teditor  1.8.0@@fee5e94
Terminal based editor written in C++
Namespaces | Functions
calc/ops.cpp File Reference
#include "core/editor.h"
#include "core/command.h"
#include "core/option.h"
#include "parser.h"
#include "mode.h"

Namespaces

 teditor
 
 teditor::calc
 
 teditor::calc::ops
 

Functions

Buffer & teditor::calc::ops::getCalcBuff (Editor &ed)
 
const std::string & teditor::calc::ops::prompt ()
 
const std::string & teditor::calc::ops::lineSeparator ()
 
bool teditor::calc::ops::isPromptLine (Buffer &buf)
 
bool teditor::calc::ops::isOnPrompt (Buffer &buf, bool includeTrailingSpace=false)
 
bool teditor::calc::ops::isOnSeparator (Buffer &buf)
 
void teditor::calc::ops::printHeader (Buffer &buf)
 
void teditor::calc::ops::insertChar (Buffer &buf, char c, Editor &ed)
 
 teditor::calc::ops::DEF_CMD (Calc, "calc", "calc_ops", DEF_OP() { auto &buf=getCalcBuff(ed);printHeader(buf);ed.switchToBuff("*calc");})
 
 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);})
 
 teditor::calc::ops::DEF_CMD (InsertChar, ".calc::insert-char", "calc_ops", DEF_OP() { insertChar(ed.getBuff(),(char) ed.getKey(), ed);})
 
 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);})
 
 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();})
 
 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);})
 
 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");})