26#include <wx/dcmemory.h>
47 : m_parent(parent), m_viewportWidth(width), m_viewportHeight(height), m_maxWidth(maxWidth), m_maxHeight(maxHeight), m_virtualCursor(0)
84 string _sLine = sLine;
85 bool isErrorLine = _sLine.find((
char)15) != string::npos;
88 while (_sLine.find((
char)15) != string::npos)
89 _sLine.erase(_sLine.find((
char)15), 1);
118 if (logicalpos == string::npos)
293 return vector<unsigned short>();
323 return (flags & 15) | (fg << 4) | (bg << 8);
352 for (
size_t i = 0; i < sColors.length(); i++)
383 size_t lastRenderedLine = 0;
395 lastRenderedLine = 0;
400 for (
size_t i = lastRenderedLine; i <
m_managedText.size(); i++)
402 size_t lastbreakpos = 0;
403 bool firstline =
true;
428 vector<unsigned short> colors =
m_managedText[i].subcolors(lastbreakpos, breakpos - lastbreakpos);
429 rLine.
colors.insert(rLine.
colors.end(), colors.begin(), colors.end());
442 cursor.
pos = j + lastbreakpos;
443 rLine.
coords.push_back(cursor);
446 lastbreakpos = breakpos;
486 if (linesToDelete > 0)
512 linesToDelete = (int)
m_renderedBlock.back().coords.back().line + linesToDelete;
539 return currentLine.length();
542 static string sValidLinebreaks =
"+- ,;.*/<>=!";
549 if (sValidLinebreaks.find(currentLine[i]) != string::npos)
713 if (!logCursor1 || !logCursor2)
717 if (logCursor1 > logCursor2)
720 logCursor1 = logCursor2;
729 while (logCursor2 > logCursor1)
731 if (logCursor1.
line != logCursor2.
line)
868 if (sText.length() && sText.back() !=
'\n')
873 while (sText.back() ==
'\n')
982 int actualLinesToScroll = numLines;
1001 if (actualLinesToScroll > limiter)
1003 actualLinesToScroll = limiter;
1021 if ( linesBelow < actualLinesToScroll)
1023 actualLinesToScroll = linesBelow;
1082 int nNewTopLine = 0;
1250 for (
int pos = cursor.
pos; pos >= 0; pos--)
1252 if (isalnum(sWord[pos]) || sWord[pos] ==
'_')
1254 sWord.erase(0, pos + 1);
1259 for (
size_t pos = 0; pos < sWord.length(); pos++)
1261 if (isalnum(sWord[pos]) || sWord[pos] ==
'_')
1263 return sWord.substr(0, pos);
1294 for (
int pos = cursor.
pos - 1; pos >= 0; pos--)
1296 if (isalnum(sWord[pos]) || sWord[pos] ==
'_')
1298 return sWord.substr(pos + 1);
1505 return adjustedIndex;
1546 for (
int i = 0; i < linesToPitch; i++)
This class resembles an extended string class, which contains the extended character class.
An implementation of a generic terminal, which has to be specialized in the child classes.
NumeReSyntax * getSyntax()
This class contains all needed keywords to highlight their occurences correspondingly....
std::string highlightLine(const std::string &sCommandLine)
This function applies the highlighting colors to the command line (only used in the terminal).
std::string highlightError(const std::string &sCommandLine)
Highlight an error message. We simply use the color of the operators (which is red as default).
bool clearRange(const ViewCursor &cursor1, const ViewCursor &cursor2)
Clears the range between two view cursors.
std::string getSelectedText() const
This member function returns the selected text.
void synchronizeRenderedBlock(int linesToDelete)
Removes parts of the already rendered block.
bool IsUserText(int y, int x) const
Determines, whether the character at (x,y) is a user text.
int AdjustIndex(int index) const
void printOutput(const std::string &sLine)
This is the read-only print function.
std::deque< CharacterVector > m_managedText
unsigned short GetColorAdjusted(int y, int x) const
std::string getRenderedString(size_t viewLine) const
Return the rendered line for the current viewport setting.
std::string operator[](int index)
void SetColorAdjusted(int y, int x, unsigned short value)
size_t tab()
Insert a tab character at the current position.
void renderLayout()
This function renders the layout.
void insertInput(const std::string &sLine, size_t logicalpos=std::string::npos)
This is the user input function.
bool Scroll(int numLines, bool scrollUp)
void newLine()
Adds a new line to the current managed text.
int calc_color(int fg, int bg, int flags)
Helper function for converting the colors into a single int.
void backspace(const LogicalCursor &logCursor)
Performs a backspace operation.
ViewCursor toViewCursor(const LogicalCursor &logCursor) const
Convert a logical cursor to a view cursor.
std::string getPreviousLine() const
This member function returns the contents of the line before the current input line.
size_t findNextLinebreak(const std::string ¤tLine, size_t currentLinebreak) const
Find the next linebreak position.
TextManager(GenericTerminal *parent=nullptr, int width=80, int height=24, int maxWidth=160, int maxHeight=300)
void Resize(int width, int height)
std::vector< unsigned short > getRenderedColors(size_t viewLine) const
Return the rendered colors for the selected viewport line.
void updateColors(bool isErrorLine=false)
Update the colors for the current line.
~TextManager()
Destructor will reset the internal buffer.
char GetCharAdjusted(int y, int x) const
bool IsEditableLogical(const LogicalCursor &logCursor) const
Determines, whether the character at the logical position is editable text.
char GetCharLogical(const LogicalCursor &cursor) const
Returns the character at the logical position.
std::string GetInputHistory(bool vcursorup=true)
Get the next history line.
void selectText(const ViewCursor &viewCursor, bool bSelect=true)
Selects the text at the view cursor position.
void SetMaxSize(int newSize)
void eraseLine()
Erase the current line.
ViewCursor getCurrentViewPos() const
Returns the current cursor position as view cursor.
bool IsEditable(int y, int x) const
Determines, whether the character at (x,y) is editable text.
std::string GetTextRange(int y, int x0, int x1) const
Extracts the text between the positions.
void ResetVirtualCursorLine()
bool isSelected(const ViewCursor &viewCursor) const
Determines, whether the pointed character is selected.
std::string GetWordStartAt(int y, int x) const
Returns the word start at the passed position.
void ChangeEditableState()
Removes the editable flag from the managed text.
LogicalCursor toLogicalCursor(const ViewCursor &viewCursor) const
Convert a view cursor into a logical cursor.
unsigned short GetColor(int y, int x) const
LogicalCursor getCurrentLogicalPos() const
Returns the current cursor position as logical cursor.
int GetLinesReceived() const
std::string getCurrentInputLine() const
Returns the contents of the input line.
void unselectAll()
This member function unselects the whole text at once.
int GetNumLinesScrolled() const
GenericTerminal * m_parent
std::string GetWordAt(int y, int x) const
Returns the word at the passed position.
std::deque< RenderedLine > m_renderedBlock
bool isSelectedLogical(const LogicalCursor &cursor) const
Determines, whether the pointed character is selected.
int GetMaxSize() const
Returns the buffer size of the terminal.
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Cursor, which is used in the TextManager to identify the actual line and position in the m_text varia...
This structure combines the rendered line with its colors and its coordinates.
std::vector< unsigned short > colors
std::vector< LogicalCursor > coords
Cursor, which is used in the terminal. The TextManager is able to convert this cursor into a LogicalC...
std::string toString(int)
Converts an integer to a string without the Settings bloat.