35 #include <QtCore/QTextStream>
36 #include <QtCore/QDate>
44 #define BS_CLEARS false
56 #define loc(X,Y) ((Y)*columns+(X))
76 tmargin(0), bmargin(0),
78 sel_begin(0), sel_TL(0), sel_BR(0),
87 for (
int i=0;i<
lines+1;i++)
183 if (top == 0) top = 1;
184 if (bot == 0) bot =
lines;
187 if ( !( 0 <= top && top < bot && bot <
lines ) )
188 { qDebug()<<
" setRegion("<<top<<
","<<bot<<
") : bad range.";
382 if ((new_lines==
lines) && (new_columns==
columns))
return;
384 if (
cuY > new_lines-1)
387 for (
int i = 0; i <
cuY-(new_lines-1); i++)
396 for (
int i=0; i < qMin(
lines-1,new_lines+1) ;i++)
398 for (
int i=
lines;(i > 0) && (i<new_lines+1);i++)
399 newScreenLines[i].resize( new_columns );
402 for (
int i=
lines;(i > 0) && (i<new_lines+1);i++)
514 Q_ASSERT( startLine >= 0 && count > 0 && startLine + count <= hist->
getLines() );
516 for (
int line = startLine;
line < startLine + count;
line++)
519 const int destLineOffset = (
line-startLine)*
columns;
523 for (
int column = length; column <
columns; column++)
529 for (
int column = 0; column <
columns; column++)
542 Q_ASSERT( startLine >= 0 && count > 0 && startLine + count <=
lines );
544 for (
int line = startLine;
line < (startLine+count) ;
line++)
547 int destLineStartIndex = (
line-startLine)*columns;
549 for (
int column = 0; column <
columns; column++)
551 int srcIndex = srcLineStartIndex + column;
552 int destIndex = destLineStartIndex + column;
566 Q_ASSERT( startLine >= 0 );
567 Q_ASSERT( endLine >= startLine && endLine < hist->
getLines() +
lines );
569 const int mergedLines = endLine - startLine + 1;
571 Q_ASSERT( size >= mergedLines *
columns );
574 const int linesInHistoryBuffer = qBound(0,
hist->
getLines()-startLine,mergedLines);
575 const int linesInScreenBuffer = mergedLines - linesInHistoryBuffer;
578 if (linesInHistoryBuffer > 0) {
583 if (linesInScreenBuffer > 0) {
586 linesInScreenBuffer);
592 for (
int i = 0; i < mergedLines*
columns; i++)
597 int cursorIndex =
loc(
cuX,
cuY + linesInHistoryBuffer);
604 Q_ASSERT( startLine >= 0 );
605 Q_ASSERT( endLine >= startLine && endLine < hist->
getLines() +
lines );
607 const int mergedLines = endLine-startLine+1;
608 const int linesInHistory = qBound(0,
hist->
getLines()-startLine,mergedLines);
609 const int linesInScreen = mergedLines - linesInHistory;
611 QVector<LineProperty> result(mergedLines);
615 for (
int line = startLine;
line < startLine + linesInHistory;
line++)
626 const int firstScreenLine = startLine + linesInHistory -
hist->
getLines();
627 for (
int line = firstScreenLine;
line < firstScreenLine+linesInScreen;
line++)
694 while((n > 0) && (
cuX > 0))
746 if ( (
sel_BR > (from+scr_TL) )&&(
sel_TL < (to+scr_TL)) )
775 if (size == 0 &&
cuY > 0)
802 int newCursorX =
cuX + w--;
874 if (n <= 0 || from + n >
bmargin)
return;
974 if ( (
sel_BR > (loca+scr_TL) )&&(
sel_TL < (loce+scr_TL)) )
986 bool isDefaultCh = (clearCh ==
Character());
988 for (
int y=topLine;y<=bottomLine;y++)
993 int startCol = ( y == topLine ) ? loca%
columns : 0;
997 if ( isDefaultCh && endCol ==
columns-1 )
999 line.resize(startCol);
1003 if (line.size() < endCol + 1)
1004 line.resize(endCol+1);
1007 for (
int i=startCol;i<=endCol;i++)
1031 Q_ASSERT( sourceBegin <= sourceEnd );
1040 if (dest < sourceBegin)
1042 for (
int i=0;i<=
lines;i++)
1050 for (
int i=lines;i>=0;i--)
1059 int diff = dest - sourceBegin;
1069 int diff = dest - sourceBegin;
1071 int srca = sourceBegin+scr_TL;
1072 int srce = sourceEnd+scr_TL;
1073 int desta = srca+diff;
1074 int deste = srce+diff;
1116 for (
int i = 0; i < (
lines-1); i++)
1264 int sel_Left,sel_Right;
1270 return ( x >= sel_Left % columns ) && ( x <= sel_Right %
columns ) &&
1284 QTextStream stream(&result, QIODevice::ReadWrite);
1287 decoder.
begin(&stream);
1300 bool preserveLineBreaks)
1312 Q_ASSERT( top >= 0 && left >= 0 && bottom >= 0 && right >= 0 );
1317 for (
int y=top;y<=bottom;y++)
1323 if ( y == bottom ||
columnmode ) count = right - start + 1;
1325 const bool appendNewLine = ( y != bottom );
1331 preserveLineBreaks );
1341 bool preserveLineBreaks)
1347 static const int MAX_CHARS = 1024;
1348 static Character characterBuffer[MAX_CHARS];
1350 assert( count < MAX_CHARS );
1360 start = qMin(start,qMax(0,lineLength-1));
1365 count = lineLength-start;
1369 count = qMin(start+count,lineLength)-start;
1373 assert( start >= 0 );
1374 assert( count >= 0 );
1387 assert( count >= 0 );
1395 for (
int i=start;i < qMin(start+count,length);i++)
1397 characterBuffer[i-start] = data[i];
1401 count = qBound(0,count,length-start);
1408 for (
int i=count-1 ; i >= 0; i--)
1409 if (QChar(characterBuffer[i].character).isSpace())
1415 const bool omitLineBreak = (currentLineProperties &
LINE_WRAPPED) ||
1416 !preserveLineBreaks;
1418 if ( !omitLineBreak && appendNewLine && (count+1 < MAX_CHARS) )
1420 characterBuffer[count] =
'\n';
1426 count, currentLineProperties );
1479 if ( newHistLines == oldHistLines )
1483 if (newHistLines > oldHistLines)
1495 int top_BR =
loc(0, 1+newHistLines);
1531 if ( copyPreviousScroll )
1564 for (
int i=0;i<count;i++)
void changeTabStop(bool set)
Sets or removes a tab stop at the cursor's current column.
void clearToEndOfLine()
Clears from the current cursor position to the end of the line.
void setForeColor(int space, int color)
Sets the cursor's foreground color.
void setCursorY(int y)
Position the cursor on line y.
void clearSelection()
Clears the current selection.
bool isValid()
Returns true if this character color entry is valid.
void setBackColor(int space, int color)
Sets the cursor's background color.
virtual void decodeLine(const Character *const characters, int count, LineProperty properties)=0
Converts a line of terminal characters with associated properties into a text string and writes the s...
void resetScrolledLines()
Resets the count of the number of lines that the image has been scrolled up or down by...
virtual void getCells(int lineno, int colno, int count, Character res[])=0
void setScroll(const HistoryType &, bool copyPreviousScroll=true)
Sets the type of storage used to keep lines in the history.
void reset(bool clearScreen=true)
Resets the state of the screen.
QRect _lastScrolledRegion
int scrolledLines() const
Returns the number of lines that the image has been scrolled up or down by, since the last call to re...
void setDefaultMargins()
Resets the scrolling margins back to the top and bottom lines of the screen.
void copyFromScreen(Character *dest, int startLine, int count) const
static Character defaultChar
void compose(const QString &compose)
#define DEFAULT_FORE_COLOR
#define DEFAULT_RENDITION
void Tabulate(int n=1)
Moves the cursor n tab-stops to the right.
A single character in the terminal which consists of a unicode character value, foreground and backgr...
int getCursorY() const
Returns the line which the cursor is positioned on.
void setCursorYX(int y, int x)
Position the cursor at line y, column x.
void eraseChars(int n)
Erase n characters beginning from the current cursor position.
int getLines()
Return the number of lines.
void checkSelection(int from, int to)
TODO Document me.
void cursorRight(int n)
Move the cursor to the right by n columns.
QVarLengthArray< LineProperty, 64 > lineProperties
void helpAlign()
Fills the entire screen with the letter 'E'.
#define COLOR_SPACE_DEFAULT
void clear()
TODO Document me.
Describes the color of a single character in the terminal.
void saveMode(int mode)
Saves the state of the specified screen mode.
void clearToEndOfScreen()
Clear the area of the screen from the current cursor position to the end of the screen.
void resetMode(int mode)
Resets (clears) the specified screen mode.
void backTabulate(int n)
Moves the cursor n tab-stops to the left.
virtual bool isWrappedLine(int lineno)=0
void BackSpace()
Moves the cursor one column to the left and erases the character at the new cursor position...
quint8 rendition
A combination of RENDITION flags which specify options for drawing the character. ...
int konsole_wcwidth(quint16 ucs)
void Return()
Moves the cursor to the beginning of the current line.
QVector< LineProperty > getLineProperties(int startLine, int endLine) const
Returns the additional attributes associated with lines in the image.
void clearImage(int loca, int loce, char c)
void setRendition(int rendition)
Enables the given rendition flag.
void setMargins(int topLine, int bottomLine)
Sets the margins for scrolling the screen.
int bottomMargin() const
Returns the bottom line of the scrolling region.
void NewLine()
Moves the cursor down one line, if the MODE_NewLine mode flag is enabled then the cursor is returned ...
bool getMode(int mode) const
Returns whether the specified screen mode is enabled or not .
void resizeImage(int new_lines, int new_columns)
Resizes the image to a new fixed size of new_lines by new_columns.
void clearEntireScreen()
Clear the whole screen, moving the current screen contents into the history first.
unsigned char LineProperty
void getSelectionStart(int &column, int &line)
Retrieves the start of the selection or the cursor position if there is no selection.
void clearToBeginOfScreen()
Clear the area of the screen from the current cursor position to the start of the screen...
virtual HistoryScroll * scroll(HistoryScroll *) const =0
void moveImage(int dest, int sourceBegin, int sourceEnd)
Screen(int lines, int columns)
Construct a new screen image of size lines by columns.
static const int LINE_WRAPPED
A terminal character decoder which produces plain text, ignoring colours and other appearance-related...
void effectiveRendition()
void setDefaultRendition()
Resets the cursor's color back to the default and sets the character's rendition flags back to the de...
void clearToBeginOfLine()
Clears from the current cursor position to the beginning of the line.
void copyLineToStream(int line, int start, int count, TerminalCharacterDecoder *decoder, bool appendNewLine, bool preserveLineBreaks)
F77_RET_T const double const double * f
void setSelectionStart(const int column, const int line, const bool columnmode)
Sets the start of the selection.
void deleteLines(int n)
Removes n lines beginning from the current cursor position.
void writeSelectionToStream(TerminalCharacterDecoder *decoder, bool preserveLineBreaks=true)
Copies the selected characters, set using.
bool hasScroll()
Returns true if this screen keeps lines that are scrolled off the screen in a history buffer...
const HistoryType & getType()
void reverseIndex()
Move the cursor up one line.
int topMargin() const
Returns the top line of the scrolling region.
void home()
Sets the position of the cursor to the 'home' position at the top-left corner of the screen (0...
void writeToStream(TerminalCharacterDecoder *decoder, int from, int to)
Copies part of the output to a stream.
std::complex< double > w(std::complex< double > z, double relerr=0)
void insertChars(int n)
Insert n blank characters beginning from the current cursor position.
bool isSelected(const int column, const int line) const
Returns true if the character at (column, line) is part of the current selection. ...
CharacterColor backgroundColor
The color used to draw this character's background.
int getCursorX() const
Returns the column which the cursor is positioned at.
QString getHistoryLine(int no)
Sets the selection to line no in the history and returns the text of that line from the history buffe...
size_t size(T const (&)[z])
void resetDroppedLines()
Resets the count of the number of lines dropped from the history.
void index()
Move the cursor down one line.
CharacterColor foregroundColor
The foreground color used to draw this character.
void getImage(Character *dest, int size, int startLine, int endLine) const
Returns the current screen image.
Base class for terminal character decoders.
void getSelectionEnd(int &column, int &line)
Retrieves the end of the selection or the cursor position if there is no selection.
bool isSelectionValid() const
void setLineProperty(LineProperty property, bool enable)
Sets or clears an attribute of the current line.
void resetRendition(int rendition)
Disables the given rendition flag.
void clearEntireLine()
Clears the whole of the line on which the cursor is currently positioned.
void NextLine()
Moves the cursor down one line and positions it at the beginning of the line.
virtual void addCellsVector(const QVector< Character > &cells)
void toggleIntensive()
Toggles the value of this color between a normal system color and the corresponding intensive system ...
const HistoryType & getScroll()
Returns the type of storage used to keep lines in the history.
void insertLines(int n)
Inserts lines beginning from the current cursor position.
void deleteChars(int n)
Delete n characters beginning from the current cursor position.
static void fillWithDefaultChar(Character *dest, int count)
Fills the buffer dest with count instances of the default (ie.
void setMode(int mode)
Sets (enables) the specified screen mode.
void clearTabStops()
Clears all the tab stops.
void restoreCursor()
Restores the position and appearence of the cursor.
virtual int getLineLen(int lineno)=0
void restoreMode(int mode)
Restores the state of a screen mode saved by calling saveMode()
void copyFromHistory(Character *dest, int startLine, int count) const
void scrollUp(int n)
Scroll the scrolling region of the screen up by n lines.
quint16 character
The unicode character value for this character.
QRect lastScrolledRegion() const
Returns the region of the image which was last scrolled.
virtual void addLine(bool previousWrapped=false)=0
static const int LINE_DEFAULT
void saveCursor()
Saves the current position and appearence (text color and style) of the cursor.
void cursorUp(int n)
Move the cursor up by n lines.
void setSelectionEnd(const int column, const int line)
Sets the end of the current selection.
void cursorDown(int n)
Move the cursor down by n lines.
void ShowCharacter(unsigned short c)
Displays a new character at the current cursor position.
virtual void end()
End decoding.
void cursorLeft(int n)
Move the cursor to the left by n columns.
void scrollDown(int n)
Scroll the scrolling region of the screen down by n lines.
QVector< Character > ImageLine
int getHistLines()
Return the number of lines in the history buffer.
void setCursorX(int x)
Position the cursor at column x.
QString selectedText(bool preserveLineBreaks)
Convenience method.
int droppedLines() const
Returns the number of lines of output which have been dropped from the history since the last call to...
virtual void begin(QTextStream *output)
Begin decoding characters.
void reverseRendition(Character &p) const
F77_RET_T const double * x
#define DEFAULT_BACK_COLOR