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++)
546 int srcLineStartIndex = line*
columns;
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;
1284 QTextStream
stream(&result, QIODevice::ReadWrite);
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++)
#define COLOR_SPACE_DEFAULT
#define DEFAULT_FORE_COLOR
#define DEFAULT_BACK_COLOR
unsigned char LineProperty
static const int LINE_WRAPPED
#define DEFAULT_RENDITION
static const int LINE_DEFAULT
Describes the color of a single character in the terminal.
void toggleIntensive()
Toggles the value of this color between a normal system color and the corresponding intensive system ...
bool isValid()
Returns true if this character color entry is valid.
A single character in the terminal which consists of a unicode character value, foreground and backgr...
CharacterColor backgroundColor
The color used to draw this character's background.
CharacterColor foregroundColor
The foreground color used to draw this character.
quint16 character
The unicode character value for this character.
quint8 rendition
A combination of RENDITION flags which specify options for drawing the character.
const HistoryType & getType()
virtual void addLine(bool previousWrapped=false)=0
virtual void addCellsVector(const QVector< Character > &cells)
virtual bool isWrappedLine(int lineno)=0
virtual int getLineLen(int lineno)=0
virtual void getCells(int lineno, int colno, int count, Character res[])=0
virtual HistoryScroll * scroll(HistoryScroll *) const =0
A terminal character decoder which produces plain text, ignoring colours and other appearance-related...
virtual void begin(QTextStream *output)
Begin decoding characters.
virtual void end()
End decoding.
void backTabulate(int n)
Moves the cursor n tab-stops to the left.
void setCursorYX(int y, int x)
Position the cursor at line y, column x.
void saveMode(int mode)
Saves the state of the specified screen mode.
int getCursorY() const
Returns the line which the cursor is positioned on.
QVector< Character > ImageLine
void clearToEndOfScreen()
Clear the area of the screen from the current cursor position to the end of the screen.
void resizeImage(int new_lines, int new_columns)
Resizes the image to a new fixed size of new_lines by new_columns.
void deleteChars(int n)
Delete n characters beginning from the current cursor position.
void compose(const QString &compose)
void setMargins(int topLine, int bottomLine)
Sets the margins for scrolling the screen.
void getImage(Character *dest, int size, int startLine, int endLine) const
Returns the current screen image.
void checkSelection(int from, int to)
TODO Document me.
void setScroll(const HistoryType &, bool copyPreviousScroll=true)
Sets the type of storage used to keep lines in the history.
void reverseRendition(Character &p) const
void copyFromScreen(Character *dest, int startLine, int count) const
void reset(bool clearScreen=true)
Resets the state of the screen.
void clearEntireScreen()
Clear the whole screen, moving the current screen contents into the history first.
void writeToStream(TerminalCharacterDecoder *decoder, int from, int to)
Copies part of the output to a stream.
QString selectedText(bool preserveLineBreaks)
Convenience method.
void saveCursor()
Saves the current position and appearence (text color and style) of the cursor.
void clearToBeginOfLine()
Clears from the current cursor position to the beginning of the line.
void clearEntireLine()
Clears the whole of the line on which the cursor is currently positioned.
void clear()
TODO Document me.
void setCursorY(int y)
Position the cursor on line y.
void BackSpace()
Moves the cursor one column to the left and erases the character at the new cursor position.
void insertChars(int n)
Insert n blank characters beginning from the current cursor position.
void writeSelectionToStream(TerminalCharacterDecoder *decoder, bool preserveLineBreaks=true)
Copies the selected characters, set using.
Screen(int lines, int columns)
Construct a new screen image of size lines by columns.
QString getHistoryLine(int no)
Sets the selection to line no in the history and returns the text of that line from the history buffe...
void Return()
Moves the cursor to the beginning of the current line.
static Character defaultChar
int getHistLines()
Return the number of lines in the history buffer.
void changeTabStop(bool set)
Sets or removes a tab stop at the cursor's current column.
void cursorDown(int n)
Move the cursor down by n lines.
static void fillWithDefaultChar(Character *dest, int count)
Fills the buffer dest with count instances of the default (ie.
void setDefaultMargins()
Resets the scrolling margins back to the top and bottom lines of the screen.
bool isSelectionValid() const
bool hasScroll()
Returns true if this screen keeps lines that are scrolled off the screen in a history buffer.
void home()
Sets the position of the cursor to the 'home' position at the top-left corner of the screen (0,...
void copyFromHistory(Character *dest, int startLine, int count) const
void setCursorX(int x)
Position the cursor at column x.
void setSelectionEnd(const int column, const int line)
Sets the end of the current selection.
void NewLine()
Moves the cursor down one line, if the MODE_NewLine mode flag is enabled then the cursor is returned ...
void clearTabStops()
Clears all the tab stops.
void clearToBeginOfScreen()
Clear the area of the screen from the current cursor position to the start of the screen.
void eraseChars(int n)
Erase n characters beginning from the current cursor position.
void getSelectionStart(int &column, int &line)
Retrieves the start of the selection or the cursor position if there is no selection.
void helpAlign()
Fills the entire screen with the letter 'E'.
int getCursorX() const
Returns the column which the cursor is positioned at.
void getSelectionEnd(int &column, int &line)
Retrieves the end of the selection or the cursor position if there is no selection.
void Tabulate(int n=1)
Moves the cursor n tab-stops to the right.
QRect lastScrolledRegion() const
Returns the region of the image which was last scrolled.
void cursorUp(int n)
Move the cursor up by n lines.
int topMargin() const
Returns the top line of the scrolling region.
void clearImage(int loca, int loce, char c)
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 clearSelection()
Clears the current selection.
bool getMode(int mode) const
Returns whether the specified screen mode is enabled or not .
void setLineProperty(LineProperty property, bool enable)
Sets or clears an attribute of the current line.
void setMode(int mode)
Sets (enables) the specified screen mode.
bool isSelected(const int column, const int line) const
Returns true if the character at (column, line) is part of the current selection.
void setDefaultRendition()
Resets the cursor's color back to the default and sets the character's rendition flags back to the de...
void setSelectionStart(const int column, const int line, const bool columnmode)
Sets the start of the selection.
QRect _lastScrolledRegion
void moveImage(int dest, int sourceBegin, int sourceEnd)
void resetScrolledLines()
Resets the count of the number of lines that the image has been scrolled up or down by,...
void scrollDown(int n)
Scroll the scrolling region of the screen down by n lines.
void scrollUp(int n)
Scroll the scrolling region of the screen up by n lines.
void effectiveRendition()
void NextLine()
Moves the cursor down one line and positions it at the beginning of the line.
void cursorRight(int n)
Move the cursor to the right by n columns.
void restoreMode(int mode)
Restores the state of a screen mode saved by calling saveMode()
int bottomMargin() const
Returns the bottom line of the scrolling region.
QVector< LineProperty > getLineProperties(int startLine, int endLine) const
Returns the additional attributes associated with lines in the image.
void resetRendition(int rendition)
Disables the given rendition flag.
void resetDroppedLines()
Resets the count of the number of lines dropped from the history.
const HistoryType & getScroll()
Returns the type of storage used to keep lines in the history.
void restoreCursor()
Restores the position and appearence of the cursor.
void setRendition(int rendition)
Enables the given rendition flag.
void setBackColor(int space, int color)
Sets the cursor's background color.
void ShowCharacter(unsigned short c)
Displays a new character at the current cursor position.
int droppedLines() const
Returns the number of lines of output which have been dropped from the history since the last call to...
void deleteLines(int n)
Removes n lines beginning from the current cursor position.
void resetMode(int mode)
Resets (clears) the specified screen mode.
QVarLengthArray< LineProperty, 64 > lineProperties
void index()
Move the cursor down one line.
void copyLineToStream(int line, int start, int count, TerminalCharacterDecoder *decoder, bool appendNewLine, bool preserveLineBreaks)
void reverseIndex()
Move the cursor up one line.
void clearToEndOfLine()
Clears from the current cursor position to the end of the line.
int getLines()
Return the number of lines.
void cursorLeft(int n)
Move the cursor to the left by n columns.
void setForeColor(int space, int color)
Sets the cursor's foreground color.
void insertLines(int n)
Inserts lines beginning from the current cursor position.
Base class for terminal character decoders.
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...
int konsole_wcwidth(quint16 ucs)
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
std::complex< double > w(std::complex< double > z, double relerr=0)