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

Functions

BuffergetCalcBuff (Editor &ed)
 
const std::string & prompt ()
 
const std::string & lineSeparator ()
 
bool isPromptLine (Buffer &buf)
 
bool isOnPrompt (Buffer &buf, bool includeTrailingSpace=false)
 
bool isOnSeparator (Buffer &buf)
 
void printHeader (Buffer &buf)
 
void insertChar (Buffer &buf, char c, Editor &ed)
 
 DEF_CMD (Calc, "calc", "calc_ops", DEF_OP() { auto &buf=getCalcBuff(ed);printHeader(buf);ed.switchToBuff("*calc");})
 
 DEF_CMD (CommandHistory, "calc::history", "calc_ops", DEF_OP() { StringChoices sc(cmds().get());auto cmd=ed.prompt("Calc Command History: ", nullptr, &sc);if(cmd.empty()) return;auto &buf=ed.getBuff();buf.startOfLine();buf.killLine();buf.insert(prompt());buf.insert(cmd);})
 
 DEF_CMD (InsertChar, ".calc::insert-char", "calc_ops", DEF_OP() { insertChar(ed.getBuff(),(char) ed.getKey(), ed);})
 
 DEF_CMD (Evaluate, "calc::enter", "calc_ops", DEF_OP() { auto &buf=ed.getBuff();Parser parser;const auto &pt=buf.getPoint();const auto &line=buf.at(pt.y).get();const auto &p=prompt();if(line.compare(0, p.size(), p) !=0) { CMBAR_MSG(ed, "Cannot evaluate a non-expr line!\n");return;} auto expr=line.substr(p.size());if(expr.empty()) return;addCmd(expr);parser.evaluate(expr, vars());buf.insert(format("\nResult: %s\n", expr.c_str()));printHeader(buf);})
 
 DEF_CMD (BackspaceChar, "calc::backspace-char", "calc_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();if(isOnPrompt(buf, true)||isOnSeparator(buf)) { CMBAR_MSG(ed, "Cannot delete the prompt or separator!");return;} buf.remove();})
 
 DEF_CMD (DeleteChar, "calc::delete-char", "calc_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();if(isOnPrompt(buf, false)||isOnSeparator(buf)) { CMBAR_MSG(ed, "Cannot delete the prompt or separator!");return;} buf.remove(true);})
 
 DEF_CMD (KillLine, "calc::kill-line", "calc_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();if(isOnPrompt(buf, false)||isOnSeparator(buf)) { CMBAR_MSG(ed, "Cannot kill-line at the prompt or separator!");return;} auto del=buf.killLine();ed.setClipboard(del);CMBAR_MSG(ed, "Line killed\n");})
 

Function Documentation

◆ DEF_CMD() [1/7]

teditor::calc::ops::DEF_CMD ( BackspaceChar  ,
"calc::backspace-char"  ,
"calc_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();if(isOnPrompt(buf, true)||isOnSeparator(buf)) { CMBAR_MSG(ed, "Cannot delete the prompt or separator!");return;} buf.remove();}   
)

◆ DEF_CMD() [2/7]

teditor::calc::ops::DEF_CMD ( Calc  ,
"calc"  ,
"calc_ops"  ,
DEF_OP() { auto &buf=getCalcBuff(ed);printHeader(buf);ed.switchToBuff("*calc");}   
)

◆ DEF_CMD() [3/7]

teditor::calc::ops::DEF_CMD ( CommandHistory  ,
"calc::history"  ,
"calc_ops"  ,
DEF_OP() { StringChoices sc(cmds().get());auto cmd=ed.prompt("Calc Command History: ", nullptr, &sc);if(cmd.empty()) return;auto &buf=ed.getBuff();buf.startOfLine();buf.killLine();buf.insert(prompt());buf.insert(cmd);}   
)

◆ DEF_CMD() [4/7]

teditor::calc::ops::DEF_CMD ( DeleteChar  ,
"calc::delete-char"  ,
"calc_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();if(isOnPrompt(buf, false)||isOnSeparator(buf)) { CMBAR_MSG(ed, "Cannot delete the prompt or separator!");return;} buf.remove(true);}   
)

◆ DEF_CMD() [5/7]

teditor::calc::ops::DEF_CMD ( Evaluate  ,
"calc::enter"  ,
"calc_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();Parser parser;const auto &pt=buf.getPoint();const auto &line=buf.at(pt.y).get();const auto &p=prompt();if(line.compare(0, p.size(), p) !=0) { CMBAR_MSG(ed, "Cannot evaluate a non-expr line!\n");return;} auto expr=line.substr(p.size());if(expr.empty()) return;addCmd(expr);parser.evaluate(expr, vars());buf.insert(format("\nResult: %s\n", expr.c_str()));printHeader(buf);}   
)

◆ DEF_CMD() [6/7]

teditor::calc::ops::DEF_CMD ( InsertChar  ,
".calc::insert-char"  ,
"calc_ops"  ,
DEF_OP() { insertChar(ed.getBuff(),(char) ed.getKey(), ed);}   
)

◆ DEF_CMD() [7/7]

teditor::calc::ops::DEF_CMD ( KillLine  ,
"calc::kill-line"  ,
"calc_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();if(isOnPrompt(buf, false)||isOnSeparator(buf)) { CMBAR_MSG(ed, "Cannot kill-line at the prompt or separator!");return;} auto del=buf.killLine();ed.setClipboard(del);CMBAR_MSG(ed, "Line killed\n");}   
)

◆ getCalcBuff()

Buffer& teditor::calc::ops::getCalcBuff ( Editor ed)

◆ insertChar()

void teditor::calc::ops::insertChar ( Buffer buf,
char  c,
Editor ed 
)

◆ isOnPrompt()

bool teditor::calc::ops::isOnPrompt ( Buffer buf,
bool  includeTrailingSpace = false 
)

◆ isOnSeparator()

bool teditor::calc::ops::isOnSeparator ( Buffer buf)

◆ isPromptLine()

bool teditor::calc::ops::isPromptLine ( Buffer buf)

◆ lineSeparator()

const std::string& teditor::calc::ops::lineSeparator ( )

◆ printHeader()

void teditor::calc::ops::printHeader ( Buffer buf)

◆ prompt()

const std::string& teditor::calc::ops::prompt ( )