95 lines
2.7 KiB
C++
95 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <ctime>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "CommandSpec.h"
|
|
#include "Completer.h"
|
|
#include "Config.h"
|
|
#include "Database.h"
|
|
#include "Display.h"
|
|
#include "LineEditor.h"
|
|
#include "Tracker.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();
|
|
bool endOfInput(); // true if the program should exit
|
|
|
|
enum class Answer { Yes, No, Cancel };
|
|
// Asks until the reply is valid (y / n, and c when allowed). nullopt if input closed.
|
|
std::optional<Answer> ask(const std::string& question, bool allowCancel) const;
|
|
|
|
// Account commands
|
|
bool cmdAccAdd(const Args& args);
|
|
bool cmdAccDel(const Args& args);
|
|
bool cmdAccRename(const Args& args);
|
|
bool cmdAccWait(const Args& args);
|
|
bool cmdAccUnwait(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_;
|
|
Tracker tracker_;
|
|
std::vector<Command> commands_;
|
|
std::vector<CommandSpec> specs_;
|
|
Completer completer_;
|
|
LineEditor lineEditor_;
|
|
std::vector<std::string> messages_;
|
|
bool quit_;
|
|
};
|