Setup ed the posix line editor.

This commit is contained in:
2026-08-09 16:31:09 +01:00
parent 717c048d6f
commit f044f69f1c
13 changed files with 820 additions and 72 deletions
+30 -1
View File
@@ -1,11 +1,40 @@
#include "commands/ed/ed.h"
#include "cli.h"
namespace crib::commands::ed {
std::string summary() {
return "A POSIX-compliant line editor.";
}
void help() {}
void run(std::vector<std::string> args) {
return;
std::string prompt = "";
std::filesystem::path filepath;
bool suppress = false;
for (size_t i = 1; i < args.size(); i++) {
if (args[i] == "-p") {
i++;
if (i >= args.size())
throw crib::cli::cli_error("Prompt not specified!", 1);
prompt = args[i];
} else if (args[i] == "-s") {
suppress = true;
} else {
if (filepath.string().size())
throw crib::cli::cli_error("Invalid arguments given.", 1);
filepath = args[i];
}
}
Ed ed(filepath, suppress, prompt);
std::string command;
while (true) {
std::string cmd;
if (ed.prompt_mode)
std::cout << ed.prompt;
bool eof = !std::getline(std::cin, cmd);
if (!ed.handle(cmd, eof))
return;
}
}
} // namespace crib::commands::ed