Add source code.
This commit is contained in:
1 parent
dab19ace02
commit
0b8a7b3cdc
31 files changed
+2809
No files matched your search
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "CommandSpec.h"
|
||||
#include "Completer.h"
|
||||
#include "Config.h"
|
||||
#include "Database.h"
|
||||
#include "Display.h"
|
||||
#include "LineEditor.h"
|
||||
#include "Status.h"
|
||||
|
||||
// Interactive prompt: commands are typed live, one per line.
|
||||
class Repl {
|
||||
public:
|
||||
Repl(Database& db, Display& display, Config& config);
|
||||
|
||||
int run();
|
||||
|
||||
private:
|
||||
using Args = std::vector<std::string>;
|
||||
using Handler = bool (Repl::*)(const Args&); // returns true if the panels should be redrawn
|
||||
|
||||
struct Command {
|
||||
CommandSpec spec;
|
||||
Handler handler;
|
||||
};
|
||||
|
||||
void registerCommands();
|
||||
void add(const std::string& key, const std::string& usage, const std::string& help,
|
||||
std::size_t minArgs, std::size_t maxArgs, const std::vector<ArgKind>& argKinds,
|
||||
Handler handler);
|
||||
const Command* find(const Args& tokens, std::size_t& consumed) const;
|
||||
|
||||
void execute(const std::string& line);
|
||||
void refresh() const;
|
||||
void say(const std::string& message);
|
||||
void flushMessages();
|
||||
void endOfInput();
|
||||
bool confirm(const std::string& question) const;
|
||||
|
||||
// Helpers
|
||||
static void requireName(const std::string& name);
|
||||
static Status parseStatusFrom(const Args& args, std::size_t from);
|
||||
|
||||
// Account commands
|
||||
bool cmdAccAdd(const Args& args);
|
||||
bool cmdAccDel(const Args& args);
|
||||
bool cmdAccRename(const Args& args);
|
||||
bool cmdAccLs(const Args& args);
|
||||
|
||||
// Task commands
|
||||
bool cmdTskAdd(const Args& args);
|
||||
bool cmdTskDel(const Args& args);
|
||||
bool cmdTskLs(const Args& args);
|
||||
bool cmdTskRename(const Args& args);
|
||||
bool cmdTskReacc(const Args& args);
|
||||
bool cmdTskRestat(const Args& args);
|
||||
bool cmdTskNotes(const Args& args);
|
||||
|
||||
// Display commands
|
||||
bool cmdDisp(const Args& args);
|
||||
bool cmdDispTsk(const Args& args);
|
||||
bool cmdDispTskLevel(const Args& args);
|
||||
bool cmdDispAcc(const Args& args);
|
||||
bool cmdDispAccLevel(const Args& args);
|
||||
|
||||
// Database commands
|
||||
bool cmdDbSave(const Args& args);
|
||||
bool cmdDbBackup(const Args& args);
|
||||
bool cmdDbRestore(const Args& args);
|
||||
|
||||
// Misc
|
||||
bool cmdEditor(const Args& args);
|
||||
bool cmdHelp(const Args& args);
|
||||
bool cmdQuit(const Args& args);
|
||||
|
||||
Database& db_;
|
||||
Display& display_;
|
||||
Config& config_;
|
||||
std::vector<Command> commands_;
|
||||
std::vector<CommandSpec> specs_;
|
||||
Completer completer_;
|
||||
LineEditor lineEditor_;
|
||||
std::vector<std::string> messages_;
|
||||
bool quit_;
|
||||
};
|
||||
Reference in new issue
Block a user