diff --git a/sys/teton/terminal.cpp b/sys/teton/terminal.cpp index 72e0bfb..15561a4 100644 --- a/sys/teton/terminal.cpp +++ b/sys/teton/terminal.cpp @@ -1,5 +1,9 @@ #include "terminal.h" +#include +#include +#include + void Terminal::HandleCharacter(char c) { console_.WriteChar(c); if (c == '\n') { @@ -14,11 +18,34 @@ void Terminal::HandleCharacter(char c) { } void Terminal::ExecuteCommand(const glcr::String& command) { - if (command == "help") { + auto tokens = glcr::StrSplit(command, ' '); + if (tokens.size() == 0) { + console_.WriteChar('>'); + return; + } + glcr::StringView cmd = tokens[0]; + if (cmd == "help") { console_.WriteString("Available Commands: cwd\n"); - } else if (command == "cwd") { + } else if (cmd == "cwd") { console_.WriteString(cwd_); console_.WriteChar('\n'); + } else if (cmd == "ls") { + glcr::StringView directory; + if (tokens.size() > 1) { + directory = tokens[1]; + } else { + directory = cwd_; + } + auto files_or = mmth::ListDirectory(directory); + if (!files_or.ok()) { + console_.WriteString(glcr::StrFormat("Error: {}\n", files_or.error())); + } else { + auto& files = files_or.value(); + for (uint64_t i = 0; i < files.size(); i++) { + console_.WriteString(files[i]); + console_.WriteChar('\n'); + } + } } else { console_.WriteString("Unknown command: "); console_.WriteString(command);