Setup ed the posix line editor.
This commit is contained in:
+30
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user