teditor
1.8.0@@fee5e94
Terminal based editor written in C++
|
Go to the documentation of this file.
32 Option(
const std::string& n,
const std::string& v,
const std::string& hm,
33 Type t) : name(n), value(v), helpMsg(hm), type(t) {}
40 ASSERT(type ==
Boolean,
"Option '%s' is not Boolean!", name.c_str());
41 return value ==
"YES";
45 ASSERT(type ==
Integer,
"Option '%s' is not Integer!", name.c_str());
50 ASSERT(type ==
Real,
"Option '%s' is not Real!", name.c_str());
54 std::string
getStr()
const;
57 ASSERT(type ==
Char,
"Option '%s' is not Char!", name.c_str());
69 static void add(
const std::string& n,
const std::string& v,
70 const std::string& hm,
Type t);
73 static void set(
const std::string& n,
const std::string& val);
79 static void dumpAll(
const std::string& outfile);
94 void setVal(
const std::string& val) { value = val; }
96 static std::string type2str(
Type t);
97 static std::string expandOptions(
const std::string& str);
102 bool parseArgs(
int argc,
char** argv, std::vector<FileInfo>& files);
Buffer & getWatchBuff(Editor &ed)
Definition: watch/ops.cpp:45
@ Char
Definition: option.h:22
Accounts topAccounts(bool sort=true) const
Computes balances of only the top-level accounts. Top-level account is the account name that preceeds...
Definition: ledger/parser.cpp:134
#define MESSAGE(ed, fmt,...)
Definition: logger.h:50
void addCmd(const std::string &c)
Definition: extensions/calc/mode.cpp:22
bool isOnSeparator(Buffer &buf)
Definition: calc/ops.cpp:100
Options & options()
Definition: option.cpp:35
FileInfo readFileInfo(const std::string &arg)
Definition: file_utils.cpp:274
Definition: cmd_msg_bar.h:38
Option(const std::string &n, const std::string &v, const std::string &hm, Type t)
Define a new option.
Definition: option.h:32
void parseRcFile(const std::string &rc)
Definition: option.cpp:165
bool isOnPrompt(Buffer &buf, bool includeTrailingSpace=false)
Definition: calc/ops.cpp:92
std::string timeToDateStr(const TimePoint &pt)
Definition: time_utils.cpp:39
Buffer & getTodoShowBuff(Editor &ed)
Definition: todo/ops.cpp:34
int str2num(const std::string &str)
Definition: utils.cpp:73
static void add(const std::string &n, const std::string &v, const std::string &hm, Type t)
Define a new option.
Definition: option.cpp:51
bool isCurrentOrParentDir(const std::string &dir)
Definition: file_utils.cpp:302
static void dumpAll(const std::string &outfile)
Definition: option.cpp:58
Definition: extensions/watch/mode.h:13
bool getBool() const
Definition: option.h:39
static void printOpts()
Definition: option.cpp:73
#define CMBAR_MSG(ed, fmt,...)
Definition: logger.h:52
static std::string inferMode(const std::string &file, bool isDir)
Helper to infer mode name from the file.
Definition: core/mode.cpp:40
float getReal() const
Definition: option.h:49
CmdStatus check_output(const std::string &cmd)
Definition: utils.cpp:110
const Point & getPoint() const
Definition: buffer.h:165
bool isPromptLine(Buffer &buf)
Definition: calc/ops.cpp:85
void minmaxDates(TimePoint &min, TimePoint &max) const
Definition: ledger/parser.cpp:177
Buffer & getLedgerShowBuff(Editor &ed)
Definition: ledger/ops.cpp:31
@ Boolean
Definition: option.h:18
DEF_CMD(OpenFile, "dirmode-open-file", "dir_ops", DEF_OP() { auto &buf=ed.getBuff();const auto &cu=buf.getPoint();auto file=buf.dirModeGetFileAtLine(cu.y);auto &dir=buf.getFileName();if(file=="."||file.empty()) return;if(file=="..") { ed.load(dirname(dir), 0);return;} ed.load(dir+'/'+file, 0);})
DEF_CMD(Watch, "watch", "ledger_ops", DEF_OP() { auto cmd=ed.prompt("Command to watch: ");if(cmd.empty()) return;CMBAR_MSG(ed, "Starting watch on '%s'...\n", cmd.c_str());auto &buf=getWatchBuff(ed);ed.switchToBuff("*watch");auto *mode=buf.getMode< watch::WatchMode >("watch");mode->start(&buf, cmd);})
ModeT * getMode(const std::string &name)
Definition: buffer.h:216
const std::string & get() const
Definition: line.h:51
Buffer & getCalcBuff(Editor &ed)
Definition: calc/ops.cpp:67
static void set(const std::string &n, const std::string &val)
Definition: option.cpp:47
Line & at(int idx)
Definition: buffer.h:98
const std::string & prompt()
Definition: calc/ops.cpp:75
char getChar() const
Definition: option.h:56
void showTopAccounts(Buffer &buf, const std::string &file)
Definition: ledger/ops.cpp:50
#define DEF_OP()
Definition: command.h:55
void copyFile(const std::string &in, const std::string &out)
Definition: file_utils.cpp:257
DEF_CMD(Grep, "grep", "grep_ops", DEF_OP() { auto cmd=ed.prompt("Run grep (like this): ", nullptr, nullptr, Option::get("grepCmd").getStr());if(cmd.empty()) { CMBAR_MSG(ed, "grep: nothing to run!\n");return;} CMBAR_MSG(ed, "grep cmd = %s\n", cmd.c_str());auto pwd=ed.getBuff().pwd();if(cmd.back()=='.') { cmd.pop_back();cmd+=pwd;} auto res=check_output(cmd);if(res.status !=0) { CMBAR_MSG(ed, "grep failed. Exit status = %d\n", res.status);MESSAGE(ed, "cmd = %s\nerr = %s\n", cmd.c_str(), res.error.c_str());return;} auto &buf=getGrepBuff(ed);buf.clear();buf.insert("Grep\nCommand: "+cmd+"\npwd: "+pwd+"\n\n");buf.insert(res.output);buf.begin();ed.switchToBuff("*grep");})
void end()
Definition: buffer.cpp:718
DEF_CMD(LedgerTop, "ledger::top", "ledger_ops", DEF_OP() { const auto &file=ed.getBuff().getFileName();auto &buf=getLedgerShowBuff(ed);showTopAccounts(buf, file);ed.switchToBuff("*ledger");})
@ String
Definition: todo/parser.cpp:19
#define CASE(t)
Definition: option.cpp:90
void printHeader(Buffer &buf)
Definition: calc/ops.cpp:106
void showAllAccounts(Buffer &buf, const std::string &file)
Definition: ledger/ops.cpp:75
std::unordered_map< std::string, std::shared_ptr< Option > > Options
Definition: option.cpp:33
@ String
Definition: option.h:21
int getInt() const
Definition: option.h:44
void insertChar(Buffer &buf, char c, Editor &ed)
Definition: calc/ops.cpp:113
std::string expandEnvVars(const std::string &str)
Definition: utils.cpp:219
Buffer & getBuff()
Definition: editor.h:28
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
void start(Buffer *buf, const std::string &cmd, int sleepLenMs=0)
Definition: extensions/watch/mode.cpp:35
float str2real(const std::string &str)
Definition: utils.cpp:80
std::chrono::system_clock::time_point TimePoint
Definition: time_utils.h:7
void printHeader(Buffer &buf, const TimePoint &min, const TimePoint &max)
Definition: ledger/ops.cpp:39
void weekFor(TimePoint &start, TimePoint &end, const TimePoint &pt)
Definition: time_utils.cpp:154
DEF_CMD(TodoOpen, "todo-open", "ledger_ops", DEF_OP() { auto todoFile=Option::get("todo:file").getStr();ed.load(todoFile, 0);})
const std::string & lineSeparator()
Definition: calc/ops.cpp:80
Definition: ledger/parser.h:10
Definition: todo/parser.h:9
static ModePtr createMode(const std::string &mode)
Helper to create mode object of the named mode.
Definition: core/mode.cpp:48
bool parseArgs(int argc, char **argv, std::vector< FileInfo > &files)
Definition: option.cpp:184
std::string getStr() const
Definition: option.cpp:26
Accounts allAccounts(bool sort=true) const
Computes balances of the top-level accounts as well as all accounts.
Definition: ledger/parser.cpp:149
std::string rel2abs(const std::string &pwd, const std::string &rel)
Definition: file_utils.cpp:118
void setMode(ModePtr m)
Definition: buffer.h:213
void showTodosFor(Buffer &buf, const TimePoint &start, const TimePoint &end)
Definition: todo/ops.cpp:47
void registerAllOptions()
Definition: option.cpp:104
Class to define an option used in the editor.
Definition: option.h:14
VarMap & vars()
Definition: extensions/calc/mode.cpp:11
DEF_CMD(Calc, "calc", "calc_ops", DEF_OP() { auto &buf=getCalcBuff(ed);printHeader(buf);ed.switchToBuff("*calc");})
CalendarMatches findMatchesIn(const CalendarItems &items, const TimePoint &start, const TimePoint &end)
Definition: objects.cpp:54
virtual void insert(char c)
Definition: buffer.cpp:25
static Option & get(const std::string &n)
Definition: option.cpp:40
std::string format(const char *fmt, va_list &vl)
Definition: utils.cpp:22
std::string dirname(const std::string &file)
Definition: file_utils.cpp:139
Buffer & getGrepBuff(Editor &ed)
Definition: grep/ops.cpp:33
Type
Definition: option.h:17
@ Real
Definition: option.h:20
const CalendarItems & items() const
Definition: todo/parser.h:15
std::vector< K > sortedKeys(const std::unordered_map< K, V > &map)
Definition: utils.h:149
History & cmds()
Definition: extensions/calc/mode.cpp:16
bool isFile(const std::string &f)
Definition: file_utils.cpp:43
@ Integer
Definition: option.h:19
virtual void clear()
Definition: buffer.cpp:173