teditor
1.8.0@@fee5e94
Terminal based editor written in C++
|
Go to the documentation of this file.
14 #include <unordered_set>
27 Buffer(
const std::string& name=
"",
bool noUndoRedo=
false);
35 virtual void insert(
char c);
37 virtual void insert(
const std::string& str);
42 void remove(
bool removeCurrent=
false);
54 std::string
killLine(
bool pushToStack=
true);
89 virtual void load(
const std::string& file,
int line=0);
107 const Point& dim)
const;
109 const Point& dim)
const;
199 virtual bool save(
const std::string& fName=
"");
215 template <
typename ModeT>
217 ASSERT(
modeName() == name,
"getMode: expected '%s' but obtained '%s'!",
219 return dynamic_cast<ModeT*
>(
mode.get());
295 void loadFile(
const std::string& file,
int line);
296 void loadDir(
const std::string& dir);
307 virtual int drawLine(
int y,
const std::string& line,
Editor& ed,
int lineNum,
371 std::unordered_set<std::string> buffNames;
373 std::string uniquify(
const std::string& name)
const;
virtual void load(const std::string &file, int line=0)
Definition: buffer.cpp:333
void startRegion()
Definition: buffer.h:180
void insertImpl(char c)
Definition: buffer.cpp:266
@ OpInsert
Definition: buffer.h:239
Buffer(const std::string &name="", bool noUndoRedo=false)
Definition: buffer.cpp:14
void remove(bool removeCurrent=false)
main remove method
Definition: buffer.cpp:57
int num
Definition: buffer.h:230
bool isRO() const
Definition: buffer.h:203
void loadFile(const std::string &file, int line)
Definition: buffer.cpp:358
void loadDir(const std::string &dir)
Definition: buffer.cpp:352
virtual void draw(Editor &ed, const Window &win)
Definition: buffer.cpp:391
Point after
Definition: buffer.h:257
std::string dirModeGetFileAtLine(int line)
Definition: buffer.cpp:443
virtual int getMinStartLoc() const
Definition: buffer.h:205
virtual void lineDown()
Definition: buffer.cpp:626
void applyInsertOp(OpData &op, bool pushToStack=true)
Insert characters into the buffer.
Definition: buffer.cpp:250
Point buffer2screen(const Point &loc, const Point &start, const Point &dim) const
Definition: buffer.cpp:477
Line split(int idx)
Definition: line.cpp:15
void left()
Definition: buffer.cpp:670
std::string buffName
Definition: buffer.h:274
std::string copyFromRemote(const std::string &file)
Definition: file_utils.cpp:306
int sendStringf(int x, int y, const AttrColor &fg, const AttrColor &bg, const char *fmt,...)
Definition: editor.cpp:302
@ OpKeepRemoveLines
Definition: buffer.h:245
virtual ~Buffer()
Definition: buffer.h:28
bool isRegionActive() const
Definition: buffer.h:174
bool readOnly
Definition: buffer.h:273
static std::string inferMode(const std::string &file, bool isDir)
Helper to infer mode name from the file.
Definition: core/mode.cpp:40
int buffSize() const
Definition: editor.h:63
OpType
Definition: buffer.h:237
int length() const
Definition: buffer.h:92
char getMatchingParen(char c)
Definition: utils.cpp:205
static const key_t Key_Enter
Definition: keys.h:62
const Pos2di & start() const
Definition: window.h:58
Definition: key_cmd_map.h:19
void drawStatusBar(Editor &ed, const Window &win)
Definition: buffer.cpp:413
std::string killLine(bool pushToStack=true)
Definition: buffer.cpp:184
std::string removeChar()
Definition: buffer.cpp:86
const Point & getPoint() const
Definition: buffer.h:165
void pushNewOp(OpData &op)
Definition: buffer.cpp:291
std::shared_ptr< Mode > ModePtr
Definition: core/mode.h:19
void up()
Definition: buffer.cpp:705
T y
Definition: pos2d.h:16
void resetBufferState(int line, const std::string &file, bool dir)
Definition: buffer.cpp:380
The state before/after applying insertion/deletion operations on the Buffer object.
Definition: buffer.h:253
void nextWord()
Definition: buffer.cpp:756
bool isDir(const std::string &f)
Definition: file_utils.cpp:34
std::string tempFileName()
Definition: file_utils.cpp:148
std::string fileName
Definition: buffer.h:274
OpType type
Definition: buffer.h:263
ModeT * getMode(const std::string &name)
Definition: buffer.h:216
const std::string & get() const
Definition: line.h:51
std::string tmpFileName
Definition: buffer.h:274
bool undo()
undo the previous operation
Definition: buffer.cpp:211
void reload()
Definition: buffer.cpp:340
Line & at(int idx)
Definition: buffer.h:98
std::vector< std::string > Strings
Definition: utils.h:42
Ken-Thompson NFA as described here: https://swtch.com/~rsc/regexp/regexp1.html but adjusted to work w...
Definition: nfa.h:23
void addLines(const RemovedLines &rlines)
Definition: buffer.cpp:532
int numLinesNeeded(int wid) const
Definition: line.cpp:49
bool isModified() const
Definition: buffer.h:204
int lengthOf(int i) const
Definition: buffer.h:187
void addLine()
Definition: buffer.h:292
OpStack redoStack
Definition: buffer.h:286
int sendChar(int x, int y, const AttrColor &fg, const AttrColor &bg, char c)
Definition: editor.cpp:295
void applyDeleteOp(OpData &op)
Delete characters/regions from the buffer.
Definition: buffer.cpp:279
int dirModeFileOffset() const
Definition: buffer.h:299
void down()
Definition: buffer.cpp:698
std::string str
Definition: buffer.h:259
void end()
Definition: buffer.cpp:718
int currBuffId() const
Definition: window.h:55
std::string str
Definition: buffer.h:228
std::vector< Line > lines
Definition: buffer.h:271
void nextPara()
Definition: buffer.cpp:734
std::string erase(int idx, int len=1)
Definition: line.cpp:7
bool isCloseParen(char c)
Definition: utils.cpp:199
~Buffers()
Definition: buffer.cpp:821
bool modified
Definition: buffer.h:273
bool isReadOnly(const char *f)
Definition: file_utils.cpp:52
KeyCmdMap & getKeyCmdMap()
Definition: buffer.h:294
Buffer * push_back(const std::string &name, bool noUndoRedo=false)
Definition: buffer.cpp:834
bool matchCurrentParen()
find matching paren at the current location
Definition: buffer.cpp:551
OpStack undoStack
Definition: buffer.h:284
void keepRemoveLines(parser::NFA ®ex, bool keep)
Keep/Remove lines that match the input regex.
Definition: buffer.cpp:500
int startLine
Definition: buffer.h:272
void indent()
Definition: buffer.cpp:804
static const size_t NoMatch
Definition: nfa.h:93
void previousWord()
Definition: buffer.cpp:776
size_t findAny(const std::string &str, size_t &matchStartPos, size_t start=0, size_t end=0)
Tries for regex match starting from anywhere in the string.
Definition: nfa.cpp:76
void pageDown(int ijump)
Definition: buffer.cpp:723
int longestX
Definition: buffer.h:282
Point before
Definition: buffer.h:255
std::vector< RemovedLine > RemovedLines
Definition: buffer.h:233
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
int sendString(int x, int y, const AttrColor &fg, const AttrColor &bg, const char *str, int len)
Definition: editor.cpp:282
std::string num2str(int num)
Definition: utils.cpp:66
bool isAbs(const std::string &file)
Definition: file_utils.cpp:116
std::string basename(const std::string &file)
Definition: file_utils.cpp:133
void drawPoint(Editor &ed, const AttrColor &bg, const Window &win)
Definition: buffer.cpp:402
Point cu
Definition: buffer.h:280
void makeReadOnly()
Definition: buffer.cpp:345
const std::string & modeName() const
Definition: buffer.h:211
void startOfLine()
Definition: buffer.h:128
const std::string & bufferName() const
Definition: buffer.h:200
void right()
Definition: buffer.cpp:686
#define DEBUG(fmt,...)
Definition: logger.h:73
std::string removeAndCopy()
Definition: buffer.cpp:39
std::string dirName
Definition: buffer.h:274
Definition: core/mode.h:27
void lineEnd(const Point &start, const Point &dim)
Definition: buffer.cpp:628
@ OpKillLine
Definition: buffer.h:243
void begin()
Definition: buffer.cpp:713
void sortRegion()
Definition: buffer.cpp:596
int find(Pos2d< T > &start, Pos2d< T > &end, const Pos2d< T > &other) const
Finds the start/end points for the range defined by this and the other position.
Definition: pos2d.h:59
static const int DirModeFileOffset
Definition: file_utils.h:47
static ModePtr createMode(const std::string &mode)
Helper to create mode object of the named mode.
Definition: core/mode.cpp:48
bool redo()
redo the previously undid operation.
Definition: buffer.cpp:231
virtual int drawLine(int y, const std::string &line, Editor &ed, int lineNum, const Window &win)
Definition: buffer.cpp:450
bool hasPointOn(int line) const
Definition: buffer.h:164
std::string removeCurrentChar()
Definition: buffer.cpp:155
void copyToRemote(const std::string &rfile, const std::string &local)
Definition: file_utils.cpp:315
std::string rel2abs(const std::string &pwd, const std::string &rel)
Definition: file_utils.cpp:118
ModePtr mode
Definition: buffer.h:278
std::string regionAsStr() const
Definition: buffer.cpp:307
void setMode(ModePtr m)
Definition: buffer.h:213
void clear()
Definition: buffer.cpp:829
void endOfLine()
Definition: buffer.h:130
bool isInside(int _y, int _x, const Pos2d< T > &cu) const
Check if the given location is in the regions.
Definition: pos2d.h:91
void clearStack(OpStack &st)
Definition: buffer.cpp:298
virtual void lineUp(const Point &dim)
Definition: buffer.cpp:620
RemovedLines rlines
Definition: buffer.h:261
void lineReset()
Definition: buffer.h:197
void pageUp(int ijump)
Definition: buffer.cpp:728
void previousPara()
Definition: buffer.cpp:745
void gotoLine(int lineNum, const Point &dim)
Definition: buffer.cpp:797
std::string removeRegion(const Point &start, const Point &end)
removes region between start and end
Definition: buffer.cpp:108
#define ULTRA_DEBUG(fmt,...)
Definition: logger.h:74
Strings namesList() const
Definition: buffer.cpp:853
virtual void insert(char c)
Definition: buffer.cpp:25
char charAt(const Point &pos) const
Definition: buffer.cpp:606
Point screen2buffer(const Point &loc, const Point &start, const Point &dim) const
Definition: buffer.cpp:488
const std::string & getWord() const
Definition: buffer.h:210
Pos2di Point
Definition: pos2d.h:112
void stopRegion()
Definition: buffer.h:182
const AttrColor & getColor(const std::string &name) const
Definition: buffer.cpp:303
std::string removeFrom(const Point &start, const Point &end)
Definition: buffer.cpp:115
std::string dirname(const std::string &file)
Definition: file_utils.cpp:139
virtual bool save(const std::string &fName="")
Definition: buffer.cpp:638
std::string getpwd()
Definition: file_utils.cpp:107
virtual int totalLinesNeeded(const Point &dim) const
Definition: buffer.cpp:613
T x
Definition: pos2d.h:16
bool isOpenParen(char c)
Definition: utils.cpp:195
void removeLines(const RemovedLines &rlines)
Definition: buffer.cpp:541
@ OpDelete
Definition: buffer.h:241
const Line & at(int idx) const
Definition: buffer.h:99
Point region
Definition: buffer.h:276
bool disableStack
Definition: buffer.h:288
const Point & getRegion() const
Definition: buffer.h:183
const Pos2di & dim() const
Definition: window.h:59
bool LineCompare(const Line &a, const Line &b)
Definition: line.cpp:75
const std::string & pwd() const
Definition: buffer.h:202
virtual void clear()
Definition: buffer.cpp:173
Strings cmdNames() const
Definition: buffer.h:222
void setPoint(const Point &p)
Definition: buffer.h:166
bool isRemote(const std::string &f)
Definition: file_utils.cpp:79
void erase(int idx)
Definition: buffer.cpp:846
std::string listDir2str(const std::string &dir)
Definition: file_utils.cpp:241
std::stack< OpData > OpStack
Definition: buffer.h:268
const std::string & getFileName() const
Definition: buffer.h:201
void join(const Line &other)
Definition: line.cpp:25