teditor  1.8.0@@fee5e94
Terminal based editor written in C++
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
teditor::Buffer Class Reference

#include <buffer.h>

+ Inheritance diagram for teditor::Buffer:

Classes

struct  OpData
 The state before/after applying insertion/deletion operations on the Buffer object. More...
 
struct  RemovedLine
 

Public Member Functions

 Buffer (const std::string &name="", bool noUndoRedo=false)
 
virtual ~Buffer ()
 
virtual void insert (char c)
 
virtual void insert (const std::string &str)
 
void remove (bool removeCurrent=false)
 main remove method More...
 
std::string removeAndCopy ()
 
std::string removeRegion (const Point &start, const Point &end)
 removes region between start and end More...
 
std::string killLine (bool pushToStack=true)
 
void sortRegion ()
 
void keepRemoveLines (parser::NFA &regex, bool keep)
 Keep/Remove lines that match the input regex. More...
 
virtual void clear ()
 
bool undo ()
 undo the previous operation More...
 
bool redo ()
 redo the previously undid operation. More...
 
bool matchCurrentParen ()
 find matching paren at the current location More...
 
virtual void load (const std::string &file, int line=0)
 
int length () const
 
Lineat (int idx)
 
const Lineat (int idx) const
 
Point buffer2screen (const Point &loc, const Point &start, const Point &dim) const
 
Point screen2buffer (const Point &loc, const Point &start, const Point &dim) const
 
char charAt (const Point &pos) const
 
virtual void draw (Editor &ed, const Window &win)
 
void drawPoint (Editor &ed, const AttrColor &bg, const Window &win)
 
void startOfLine ()
 
void endOfLine ()
 
void left ()
 
void right ()
 
void down ()
 
void up ()
 
void begin ()
 
void end ()
 
void pageDown (int ijump)
 
void pageUp (int ijump)
 
void nextPara ()
 
void previousPara ()
 
void nextWord ()
 
void previousWord ()
 
void gotoLine (int lineNum, const Point &dim)
 
bool hasPointOn (int line) const
 
const PointgetPoint () const
 
void setPoint (const Point &p)
 
bool isRegionActive () const
 
std::string regionAsStr () const
 
std::string regionAsStr (const Point &start, const Point &end) const
 
void startRegion ()
 
void stopRegion ()
 
const PointgetRegion () const
 
int lengthOf (int i) const
 
void indent ()
 
virtual int totalLinesNeeded (const Point &dim) const
 
virtual void lineUp (const Point &dim)
 
virtual void lineDown ()
 
void lineReset ()
 
void lineEnd (const Point &start, const Point &dim)
 
virtual bool save (const std::string &fName="")
 
const std::string & bufferName () const
 
const std::string & getFileName () const
 
const std::string & pwd () const
 
bool isRO () const
 
bool isModified () const
 
virtual int getMinStartLoc () const
 
std::string dirModeGetFileAtLine (int line)
 
void reload ()
 
const AttrColorgetColor (const std::string &name) const
 
const std::string & getWord () const
 
const std::string & modeName () const
 
void makeReadOnly ()
 
void setMode (ModePtr m)
 
template<typename ModeT >
ModeT * getMode (const std::string &name)
 
Strings cmdNames () const
 

Protected Types

enum  OpType { OpInsert = 0, OpDelete, OpKillLine, OpKeepRemoveLines }
 
typedef std::vector< RemovedLineRemovedLines
 
typedef std::stack< OpDataOpStack
 

Protected Member Functions

void insertImpl (char c)
 
void addLine ()
 
void resetBufferState (int line, const std::string &file, bool dir)
 
KeyCmdMapgetKeyCmdMap ()
 
void loadFile (const std::string &file, int line)
 
void loadDir (const std::string &dir)
 
std::string removeFrom (const Point &start, const Point &end)
 
Point matchCurrentParen (bool &isOpen)
 
int dirModeFileOffset () const
 
void drawStatusBar (Editor &ed, const Window &win)
 
virtual int drawLine (int y, const std::string &line, Editor &ed, int lineNum, const Window &win)
 
std::string removeChar ()
 
std::string removeCurrentChar ()
 
void applyInsertOp (OpData &op, bool pushToStack=true)
 Insert characters into the buffer. More...
 
void applyDeleteOp (OpData &op)
 Delete characters/regions from the buffer. More...
 
void addLines (const RemovedLines &rlines)
 
void removeLines (const RemovedLines &rlines)
 
void pushNewOp (OpData &op)
 
void clearStack (OpStack &st)
 

Protected Attributes

std::vector< Linelines
 
int startLine
 
bool modified
 
bool readOnly
 
std::string buffName
 
std::string fileName
 
std::string dirName
 
std::string tmpFileName
 
Point region
 
ModePtr mode
 
Point cu
 
int longestX
 
OpStack undoStack
 
OpStack redoStack
 
bool disableStack
 

Friends

class Editor
 

Detailed Description

Class for representing text files as a vector of lines (aka Buffer)

Member Typedef Documentation

◆ OpStack

typedef std::stack<OpData> teditor::Buffer::OpStack
protected

the stack for undo/redo operations

◆ RemovedLines

typedef std::vector<RemovedLine> teditor::Buffer::RemovedLines
protected

list of removed lines

Member Enumeration Documentation

◆ OpType

enum teditor::Buffer::OpType
protected

the operation type

Enumerator
OpInsert 

insertion operation

OpDelete 

backspace operation

OpKillLine 

deleting the rest of the line

OpKeepRemoveLines 

keep/remove lines

Constructor & Destructor Documentation

◆ Buffer()

teditor::Buffer::Buffer ( const std::string &  name = "",
bool  noUndoRedo = false 
)

◆ ~Buffer()

virtual teditor::Buffer::~Buffer ( )
inlinevirtual

Member Function Documentation

◆ addLine()

void teditor::Buffer::addLine ( )
inlineprotected

◆ bufferName()

const std::string& teditor::Buffer::bufferName ( ) const
inline

◆ charAt()

char teditor::Buffer::charAt ( const Point pos) const

returns character at a given buffer location

◆ cmdNames()

Strings teditor::Buffer::cmdNames ( ) const
inline

◆ dirModeFileOffset()

int teditor::Buffer::dirModeFileOffset ( ) const
inlineprotected

◆ dirModeGetFileAtLine()

std::string teditor::Buffer::dirModeGetFileAtLine ( int  line)

◆ getColor()

const AttrColor & teditor::Buffer::getColor ( const std::string &  name) const

◆ getFileName()

const std::string& teditor::Buffer::getFileName ( ) const
inline

◆ getKeyCmdMap()

KeyCmdMap& teditor::Buffer::getKeyCmdMap ( )
inlineprotected

◆ getMinStartLoc()

virtual int teditor::Buffer::getMinStartLoc ( ) const
inlinevirtual

Reimplemented in teditor::CmdMsgBar.

◆ getMode()

template<typename ModeT >
ModeT* teditor::Buffer::getMode ( const std::string &  name)
inline

◆ getWord()

const std::string& teditor::Buffer::getWord ( ) const
inline

◆ indent()

void teditor::Buffer::indent ( )

indent the current line

◆ insertImpl()

void teditor::Buffer::insertImpl ( char  c)
protected

◆ isModified()

bool teditor::Buffer::isModified ( ) const
inline

◆ isRO()

bool teditor::Buffer::isRO ( ) const
inline

◆ length()

int teditor::Buffer::length ( ) const
inline

number of lines in this buffer

◆ lengthOf()

int teditor::Buffer::lengthOf ( int  i) const
inline

length of a given line in this buffer

◆ lineDown()

void teditor::Buffer::lineDown ( )
virtual

Reimplemented in teditor::CmdMsgBar.

◆ lineEnd()

void teditor::Buffer::lineEnd ( const Point start,
const Point dim 
)

◆ lineReset()

void teditor::Buffer::lineReset ( )
inline

◆ lineUp()

void teditor::Buffer::lineUp ( const Point dim)
virtual

Reimplemented in teditor::CmdMsgBar.

◆ load()

void teditor::Buffer::load ( const std::string &  file,
int  line = 0 
)
virtual

Load a file/dir into the buffer and optionally jump to a line

Reimplemented in teditor::CmdMsgBar.

◆ loadDir()

void teditor::Buffer::loadDir ( const std::string &  dir)
protected

◆ loadFile()

void teditor::Buffer::loadFile ( const std::string &  file,
int  line 
)
protected

◆ makeReadOnly()

void teditor::Buffer::makeReadOnly ( )

◆ matchCurrentParen() [1/2]

bool teditor::Buffer::matchCurrentParen ( )

find matching paren at the current location

Returns
true if open-paren was matched, else false

◆ matchCurrentParen() [2/2]

Point teditor::Buffer::matchCurrentParen ( bool &  isOpen)
protected

◆ modeName()

const std::string& teditor::Buffer::modeName ( ) const
inline

◆ pwd()

const std::string& teditor::Buffer::pwd ( ) const
inline

◆ reload()

void teditor::Buffer::reload ( )

◆ removeFrom()

std::string teditor::Buffer::removeFrom ( const Point start,
const Point end 
)
protected

◆ resetBufferState()

void teditor::Buffer::resetBufferState ( int  line,
const std::string &  file,
bool  dir 
)
protected

◆ save()

bool teditor::Buffer::save ( const std::string &  fName = "")
virtual

Reimplemented in teditor::CmdMsgBar.

◆ setMode()

void teditor::Buffer::setMode ( ModePtr  m)
inline

◆ totalLinesNeeded()

int teditor::Buffer::totalLinesNeeded ( const Point dim) const
virtual

number of lines needed to draw the currrent buffer in this window

Reimplemented in teditor::CmdMsgBar.

Friends And Related Function Documentation

◆ Editor

friend class Editor
friend

Member Data Documentation

◆ buffName

std::string teditor::Buffer::buffName
protected

◆ cu

Point teditor::Buffer::cu
protected

cursor

◆ dirName

std::string teditor::Buffer::dirName
protected

◆ disableStack

bool teditor::Buffer::disableStack
protected

whether to disable undo/redo stack for this buffer

◆ fileName

std::string teditor::Buffer::fileName
protected

◆ lines

std::vector<Line> teditor::Buffer::lines
protected

◆ longestX

int teditor::Buffer::longestX
protected

cursor's longest 'x' location

◆ mode

ModePtr teditor::Buffer::mode
protected

◆ modified

bool teditor::Buffer::modified
protected

◆ readOnly

bool teditor::Buffer::readOnly
protected

◆ redoStack

OpStack teditor::Buffer::redoStack
protected

stack of operations for redo

◆ region

Point teditor::Buffer::region
protected

start of a region

◆ startLine

int teditor::Buffer::startLine
protected

◆ tmpFileName

std::string teditor::Buffer::tmpFileName
protected

◆ undoStack

OpStack teditor::Buffer::undoStack
protected

stack of operations for undo


The documentation for this class was generated from the following files: