[Teton] Add a ls command.
This commit is contained in:
parent
e0bf7a9a1c
commit
ea8598068d
|
@ -1,5 +1,9 @@
|
|||
#include "terminal.h"
|
||||
|
||||
#include <glacier/string/str_format.h>
|
||||
#include <glacier/string/str_split.h>
|
||||
#include <mammoth/file/file.h>
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue