teditor  1.8.0@@fee5e94
Terminal based editor written in C++
Classes | Functions
teditor::editor::ops Namespace Reference

Classes

class  FileChoices
 

Functions

 DEF_CMD (Quit, "quit", "editor_ops", DEF_OP() { ed.requestQuitEventLoop();})
 
 DEF_CMD (HelpCommand, "help-command", "editor_ops", DEF_OP() { StringChoices sc(ed.getBuff().cmdNames());auto cmd=ed.prompt("Help for Cmd? ", nullptr, &sc);if(cmd.empty()) return;try { auto c=getCmd(cmd);auto url="https://teju85.github.io/teditor/"+c.second+".html#"+cmd;check_output(Option::get("browserCmd").getStr()+" '"+url+"'");} catch(const std::runtime_error &e) { CMBAR_MSG(ed, "Unknown command: %s!\n", cmd.c_str());} })
 
 DEF_CMD (ScratchBuffer, "scratch-buffer", "editor_ops", DEF_OP() { ed.createScratchBuff(true);})
 
 DEF_CMD (FindFileHistory, "find-file-history", "editor_ops", DEF_OP() { StringChoices sc(ed.fileHistoryToString());auto file=ed.prompt("Find File History: ", nullptr, &sc);if(file.empty()) return;auto fi=readFileInfo(file);ed.load(fi.first, fi.second);})
 
 DEF_CMD (VerticalSplit, "split-vertically", "editor_ops", DEF_OP() { auto status=ed.splitVertically();if(!status) MESSAGE(ed, "Window already split vertically");})
 
 DEF_CMD (ClearAllWindows, "clear-all-windows", "editor_ops", DEF_OP() { ed.clearAllWindows();})
 
 DEF_CMD (NextWindow, "next-window", "editor_ops", DEF_OP() { ed.incrementCurrWin();})
 
 DEF_CMD (FindFile, "find-file", "editor_ops", DEF_OP() { auto &buf=ed.getBuff();auto pwd=buf.pwd()+'/';FileChoices sc(DirCache::getDirContents(pwd));auto file=ed.prompt("Find File: ", nullptr, &sc, pwd);if(!file.empty()) ed.load(file, 0);})
 
 DEF_CMD (ShellCommand, "shell-command", "editor_ops", DEF_OP() { auto cmd=ed.prompt("Shell Command: ");if(!cmd.empty()) { auto res=check_output(cmd);MESSAGE(ed, "Shell Command: %s (exit-status=%d)\nOutput: %s\nError: %s\n", cmd.c_str(), res.status, res.output.c_str(), res.error.c_str());} })
 
 DEF_CMD (RunCommand, "run-command", "editor_ops", DEF_OP() { StringChoices sc(ed.getBuff().cmdNames());auto cmd=ed.prompt("Cmd: ", nullptr, &sc);if(cmd.empty()) return;try { ed.runCmd(cmd);} catch(const std::runtime_error &e) { CMBAR_MSG(ed, "Unknown command: %s! Reason: %s\n", cmd.c_str(), e.what());} })
 
 DEF_CMD (LaunchExplorer, "open-explorer", "editor_ops", DEF_OP() { check_output("cygstart "+ed.getBuff().pwd());})
 
 DEF_CMD (LaunchBrowser, "browser", "editor_ops", DEF_OP() { auto &buf=ed.getBuff();std::string url;if(buf.isRegionActive()) url=buf.regionAsStr()[0];check_output(Option::get("browserCmd").getStr()+" '"+url+"'");})
 
 DEF_CMD (BrowserSearch, "browser-search", "editor_ops", DEF_OP() { OptionMap opts;opts["duckduckgo"]="http://www.duckduckgo.com/?t=hb&ia=meanings&q=%s";opts["google"]="http://www.google.com/#q=%s";opts["maps"]="https://www.google.co.in/maps/search/%s";opts["nvsearch"]="https://nvsearch.nvidia.com/Pages/results.aspx?k=%s";opts["stock"]="https://duckduckgo.com/?q=%s&t=ffab&ia=stock";opts["youtube"]="https://www.youtube.com/results?search_query=%s";auto command=ed.promptEnum("Search:", opts);if(command.empty()) return;command=Option::get("browserCmd").getStr()+" '"+command+"'";auto query=ed.getBuff().regionAsStr();if(query.empty()) query=ed.prompt("Query: ");if(query.empty()) return;auto hexified=urlHexify(query);auto buf=format(command.c_str(), hexified.c_str());check_output(buf.c_str());})
 
 DEF_CMD (Download, "download-url", "editor_ops", DEF_OP() { auto url=ed.prompt("URL: ");if(url.empty()) return;auto file=ed.prompt("File: ");if(file.empty()) return;downloadUrl(url, file, Option::get("dnldProg").getStr(), Option::get("dnldProgOpts").getStr());})
 
 DEF_CMD (MakeDir, "mkdir", "editor_ops", DEF_OP() { auto res=ed.prompt("Dir name: ");if(!res.empty()) makeDir(res);})
 
 DEF_CMD (SwitchBuffer, "buffer-switch", "editor_ops", DEF_OP() { StringChoices sc(ed.buffNamesToString());auto buf=ed.prompt("Buffer: ", nullptr, &sc);if(!buf.empty()) ed.switchToBuff(buf);})
 
 DEF_CMD (GitBranch, "git-branch", "editor_ops", DEF_OP() { auto &buf=ed.getBuff();auto br=gitBranchName(buf.pwd());if(br.empty()) CMBAR(ed, "Not a git-repo!\n");else CMBAR(ed, "git-branch=%s\n", br.c_str());})
 
 DEF_CMD (IndentLine, "indent", "editor_ops", DEF_OP() { ed.getBuff().indent();})
 
 DEF_CMD (OrgNotesDir, "org-notes-dir", "editor_ops", DEF_OP() { ed.load(Option::get("orgNotesDir").getStr(), 0);})
 
 DEF_CMD (SongsDir, "songs-dir", "editor_ops", DEF_OP() { ed.load(Option::get("songsDir").getStr(), 0);})
 
 DEF_CMD (TaskManager, "task-manager", "editor_ops", DEF_OP() { std::string cmd="cygstart Taskmgr.exe";auto res=check_output(cmd);MESSAGE(ed, "Shell Command: %s (exit-status=%d)\nOutput: %s", cmd.c_str(), res.status, res.output.c_str());})
 
 DEF_CMD (DNSLookup, "dns", "editor_ops", DEF_OP() { std::string url=ed.prompt("URL: ");if(url.empty()) return;std::string res;try { res=dnsLookup(url);} catch(const std::runtime_error &e) { res=e.what();} catch(...) { res="Unknown exception occured!";} CMBAR_MSG(ed, "%s\n", res.c_str());})
 

Function Documentation

◆ DEF_CMD() [1/22]

teditor::editor::ops::DEF_CMD ( BrowserSearch  ,
"browser-search"  ,
"editor_ops"  ,
DEF_OP() { OptionMap opts;opts["duckduckgo"]="http://www.duckduckgo.com/?t=hb&ia=meanings&q=%s";opts["google"]="http://www.google.com/#q=%s";opts["maps"]="https://www.google.co.in/maps/search/%s";opts["nvsearch"]="https://nvsearch.nvidia.com/Pages/results.aspx?k=%s";opts["stock"]="https://duckduckgo.com/?q=%s&t=ffab&ia=stock";opts["youtube"]="https://www.youtube.com/results?search_query=%s";auto command=ed.promptEnum("Search:", opts);if(command.empty()) return;command=Option::get("browserCmd").getStr()+" '"+command+"'";auto query=ed.getBuff().regionAsStr();if(query.empty()) query=ed.prompt("Query: ");if(query.empty()) return;auto hexified=urlHexify(query);auto buf=format(command.c_str(), hexified.c_str());check_output(buf.c_str());}   
)

◆ DEF_CMD() [2/22]

teditor::editor::ops::DEF_CMD ( ClearAllWindows  ,
"clear-all-windows"  ,
"editor_ops"  ,
DEF_OP() { ed.clearAllWindows();}   
)

◆ DEF_CMD() [3/22]

teditor::editor::ops::DEF_CMD ( DNSLookup  ,
"dns"  ,
"editor_ops"  ,
DEF_OP() { std::string url=ed.prompt("URL: ");if(url.empty()) return;std::string res;try { res=dnsLookup(url);} catch(const std::runtime_error &e) { res=e.what();} catch(...) { res="Unknown exception occured!";} CMBAR_MSG(ed, "%s\n", res.c_str());}   
)

◆ DEF_CMD() [4/22]

teditor::editor::ops::DEF_CMD ( Download  ,
"download-url"  ,
"editor_ops"  ,
DEF_OP() { auto url=ed.prompt("URL: ");if(url.empty()) return;auto file=ed.prompt("File: ");if(file.empty()) return;downloadUrl(url, file, Option::get("dnldProg").getStr(), Option::get("dnldProgOpts").getStr());}   
)

◆ DEF_CMD() [5/22]

teditor::editor::ops::DEF_CMD ( FindFile  ,
"find-file"  ,
"editor_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();auto pwd=buf.pwd()+'/';FileChoices sc(DirCache::getDirContents(pwd));auto file=ed.prompt("Find File: ", nullptr, &sc, pwd);if(!file.empty()) ed.load(file, 0);}   
)

◆ DEF_CMD() [6/22]

teditor::editor::ops::DEF_CMD ( FindFileHistory  ,
"find-file-history"  ,
"editor_ops"  ,
DEF_OP() { StringChoices sc(ed.fileHistoryToString());auto file=ed.prompt("Find File History: ", nullptr, &sc);if(file.empty()) return;auto fi=readFileInfo(file);ed.load(fi.first, fi.second);}   
)

◆ DEF_CMD() [7/22]

teditor::editor::ops::DEF_CMD ( GitBranch  ,
"git-branch"  ,
"editor_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();auto br=gitBranchName(buf.pwd());if(br.empty()) CMBAR(ed, "Not a git-repo!\n");else CMBAR(ed, "git-branch=%s\n", br.c_str());}   
)

◆ DEF_CMD() [8/22]

teditor::editor::ops::DEF_CMD ( HelpCommand  ,
"help-command"  ,
"editor_ops"  ,
DEF_OP() { StringChoices sc(ed.getBuff().cmdNames());auto cmd=ed.prompt("Help for Cmd? ", nullptr, &sc);if(cmd.empty()) return;try { auto c=getCmd(cmd);auto url="https://teju85.github.io/teditor/"+c.second+".html#"+cmd;check_output(Option::get("browserCmd").getStr()+" '"+url+"'");} catch(const std::runtime_error &e) { CMBAR_MSG(ed, "Unknown command: %s!\n", cmd.c_str());} }   
)

◆ DEF_CMD() [9/22]

teditor::editor::ops::DEF_CMD ( IndentLine  ,
"indent"  ,
"editor_ops"  ,
DEF_OP() { ed.getBuff().indent();}   
)

◆ DEF_CMD() [10/22]

teditor::editor::ops::DEF_CMD ( LaunchBrowser  ,
"browser"  ,
"editor_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();std::string url;if(buf.isRegionActive()) url=buf.regionAsStr()[0];check_output(Option::get("browserCmd").getStr()+" '"+url+"'");}   
)

◆ DEF_CMD() [11/22]

teditor::editor::ops::DEF_CMD ( LaunchExplorer  ,
"open-explorer"  ,
"editor_ops"  ,
DEF_OP() { check_output("cygstart "+ed.getBuff().pwd());}   
)

◆ DEF_CMD() [12/22]

teditor::editor::ops::DEF_CMD ( MakeDir  ,
"mkdir"  ,
"editor_ops"  ,
DEF_OP() { auto res=ed.prompt("Dir name: ");if(!res.empty()) makeDir(res);}   
)

◆ DEF_CMD() [13/22]

teditor::editor::ops::DEF_CMD ( NextWindow  ,
"next-window"  ,
"editor_ops"  ,
DEF_OP() { ed.incrementCurrWin();}   
)

◆ DEF_CMD() [14/22]

teditor::editor::ops::DEF_CMD ( OrgNotesDir  ,
"org-notes-dir"  ,
"editor_ops"  ,
DEF_OP() { ed.load(Option::get("orgNotesDir").getStr(), 0);}   
)

◆ DEF_CMD() [15/22]

teditor::editor::ops::DEF_CMD ( Quit  ,
"quit"  ,
"editor_ops"  ,
DEF_OP() { ed.requestQuitEventLoop();}   
)

◆ DEF_CMD() [16/22]

teditor::editor::ops::DEF_CMD ( RunCommand  ,
"run-command"  ,
"editor_ops"  ,
DEF_OP() { StringChoices sc(ed.getBuff().cmdNames());auto cmd=ed.prompt("Cmd: ", nullptr, &sc);if(cmd.empty()) return;try { ed.runCmd(cmd);} catch(const std::runtime_error &e) { CMBAR_MSG(ed, "Unknown command: %s! Reason: %s\n", cmd.c_str(), e.what());} }   
)

◆ DEF_CMD() [17/22]

teditor::editor::ops::DEF_CMD ( ScratchBuffer  ,
"scratch-buffer"  ,
"editor_ops"  ,
DEF_OP() { ed.createScratchBuff(true);}   
)

◆ DEF_CMD() [18/22]

teditor::editor::ops::DEF_CMD ( ShellCommand  ,
"shell-command"  ,
"editor_ops"  ,
DEF_OP() { auto cmd=ed.prompt("Shell Command: ");if(!cmd.empty()) { auto res=check_output(cmd);MESSAGE(ed, "Shell Command: %s (exit-status=%d)\nOutput: %s\nError: %s\n", cmd.c_str(), res.status, res.output.c_str(), res.error.c_str());} }   
)

◆ DEF_CMD() [19/22]

teditor::editor::ops::DEF_CMD ( SongsDir  ,
"songs-dir"  ,
"editor_ops"  ,
DEF_OP() { ed.load(Option::get("songsDir").getStr(), 0);}   
)

◆ DEF_CMD() [20/22]

teditor::editor::ops::DEF_CMD ( SwitchBuffer  ,
"buffer-switch"  ,
"editor_ops"  ,
DEF_OP() { StringChoices sc(ed.buffNamesToString());auto buf=ed.prompt("Buffer: ", nullptr, &sc);if(!buf.empty()) ed.switchToBuff(buf);}   
)

◆ DEF_CMD() [21/22]

teditor::editor::ops::DEF_CMD ( TaskManager  ,
"task-manager"  ,
"editor_ops"  ,
DEF_OP() { std::string cmd="cygstart Taskmgr.exe";auto res=check_output(cmd);MESSAGE(ed, "Shell Command: %s (exit-status=%d)\nOutput: %s", cmd.c_str(), res.status, res.output.c_str());}   
)

◆ DEF_CMD() [22/22]

teditor::editor::ops::DEF_CMD ( VerticalSplit  ,
"split-vertically"  ,
"editor_ops"  ,
DEF_OP() { auto status=ed.splitVertically();if(!status) MESSAGE(ed, "Window already split vertically");}   
)