• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
Screen.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Konsole, an X terminal.
3 
4  Copyright 2007-2008 by Robert Knight <robert.knight@gmail.com>
5  Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301 USA.
21  */
22 
23 // Own
24 #include "Screen.h"
25 
26 // Qt
27 #include <QtCore/QTextStream>
28 
29 // Konsole
30 #include "konsole_wcwidth.h"
31 #include "TerminalCharacterDecoder.h"
32 #include "History.h"
33 #include "ExtendedCharTable.h"
34 
35 using namespace Konsole;
36 
37 //FIXME: this is emulation specific. Use false for xterm, true for ANSI.
38 //FIXME: see if we can get this from terminfo.
39 const bool BS_CLEARS = false;
40 
41 //Macro to convert x,y position on screen to position within an image.
42 //
43 //Originally the image was stored as one large contiguous block of
44 //memory, so a position within the image could be represented as an
45 //offset from the beginning of the block. For efficiency reasons this
46 //is no longer the case.
47 //Many internal parts of this class still use this representation for parameters and so on,
48 //notably moveImage() and clearImage().
49 //This macro converts from an X,Y position into an image offset.
50 #ifndef loc
51 #define loc(X,Y) ((Y)*_columns+(X))
52 #endif
53 
54 const Character Screen::DefaultChar = Character(' ',
55  CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR),
56  CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR),
57  DEFAULT_RENDITION,
58  false);
59 
60 Screen::Screen(int lines, int columns):
61  _lines(lines),
62  _columns(columns),
63  _screenLines(new ImageLine[_lines + 1]),
64  _screenLinesSize(_lines),
65  _scrolledLines(0),
66  _droppedLines(0),
67  _history(new HistoryScrollNone()),
68  _cuX(0),
69  _cuY(0),
70  _currentRendition(DEFAULT_RENDITION),
71  _topMargin(0),
72  _bottomMargin(0),
73  _selBegin(0),
74  _selTopLeft(0),
75  _selBottomRight(0),
76  _blockSelectionMode(false),
77  _effectiveForeground(CharacterColor()),
78  _effectiveBackground(CharacterColor()),
79  _effectiveRendition(DEFAULT_RENDITION),
80  _lastPos(-1)
81 {
82  _lineProperties.resize(_lines + 1);
83  for (int i = 0; i < _lines + 1; i++)
84  _lineProperties[i] = LINE_DEFAULT;
85 
86  initTabStops();
87  clearSelection();
88  reset();
89 }
90 
91 Screen::~Screen()
92 {
93  delete[] _screenLines;
94  delete _history;
95 }
96 
97 void Screen::cursorUp(int n)
98 //=CUU
99 {
100  if (n == 0) n = 1; // Default
101  const int stop = _cuY < _topMargin ? 0 : _topMargin;
102  _cuX = qMin(_columns - 1, _cuX); // nowrap!
103  _cuY = qMax(stop, _cuY - n);
104 }
105 
106 void Screen::cursorDown(int n)
107 //=CUD
108 {
109  if (n == 0) n = 1; // Default
110  const int stop = _cuY > _bottomMargin ? _lines - 1 : _bottomMargin;
111  _cuX = qMin(_columns - 1, _cuX); // nowrap!
112  _cuY = qMin(stop, _cuY + n);
113 }
114 
115 void Screen::cursorLeft(int n)
116 //=CUB
117 {
118  if (n == 0) n = 1; // Default
119  _cuX = qMin(_columns - 1, _cuX); // nowrap!
120  _cuX = qMax(0, _cuX - n);
121 }
122 
123 void Screen::cursorRight(int n)
124 //=CUF
125 {
126  if (n == 0) n = 1; // Default
127  _cuX = qMin(_columns - 1, _cuX + n);
128 }
129 
130 void Screen::setMargins(int top, int bot)
131 //=STBM
132 {
133  if (top == 0) top = 1; // Default
134  if (bot == 0) bot = _lines; // Default
135  top = top - 1; // Adjust to internal lineno
136  bot = bot - 1; // Adjust to internal lineno
137  if (!(0 <= top && top < bot && bot < _lines)) {
138  //Debug()<<" setRegion("<<top<<","<<bot<<") : bad range.";
139  return; // Default error action: ignore
140  }
141  _topMargin = top;
142  _bottomMargin = bot;
143  _cuX = 0;
144  _cuY = getMode(MODE_Origin) ? top : 0;
145 }
146 
147 int Screen::topMargin() const
148 {
149  return _topMargin;
150 }
151 int Screen::bottomMargin() const
152 {
153  return _bottomMargin;
154 }
155 
156 void Screen::index()
157 //=IND
158 {
159  if (_cuY == _bottomMargin)
160  scrollUp(1);
161  else if (_cuY < _lines - 1)
162  _cuY += 1;
163 }
164 
165 void Screen::reverseIndex()
166 //=RI
167 {
168  if (_cuY == _topMargin)
169  scrollDown(_topMargin, 1);
170  else if (_cuY > 0)
171  _cuY -= 1;
172 }
173 
174 void Screen::nextLine()
175 //=NEL
176 {
177  toStartOfLine();
178  index();
179 }
180 
181 void Screen::eraseChars(int n)
182 {
183  if (n == 0) n = 1; // Default
184  const int p = qMax(0, qMin(_cuX + n - 1, _columns - 1));
185  clearImage(loc(_cuX, _cuY), loc(p, _cuY), ' ');
186 }
187 
188 void Screen::deleteChars(int n)
189 {
190  Q_ASSERT(n >= 0);
191 
192  // always delete at least one char
193  if (n == 0)
194  n = 1;
195 
196  // if cursor is beyond the end of the line there is nothing to do
197  if (_cuX >= _screenLines[_cuY].count())
198  return;
199 
200  if (_cuX + n > _screenLines[_cuY].count())
201  n = _screenLines[_cuY].count() - _cuX;
202 
203  Q_ASSERT(n >= 0);
204  Q_ASSERT(_cuX + n <= _screenLines[_cuY].count());
205 
206  _screenLines[_cuY].remove(_cuX, n);
207 
208  // Append space(s) with current attributes
209  Character spaceWithCurrentAttrs(' ', _effectiveForeground,
210  _effectiveBackground,
211  _effectiveRendition, false);
212 
213  for (int i = 0; i < n; i++)
214  _screenLines[_cuY].append(spaceWithCurrentAttrs);
215 }
216 
217 void Screen::insertChars(int n)
218 {
219  if (n == 0) n = 1; // Default
220 
221  if (_screenLines[_cuY].size() < _cuX)
222  _screenLines[_cuY].resize(_cuX);
223 
224  _screenLines[_cuY].insert(_cuX, n, Character(' '));
225 
226  if (_screenLines[_cuY].count() > _columns)
227  _screenLines[_cuY].resize(_columns);
228 }
229 
230 void Screen::deleteLines(int n)
231 {
232  if (n == 0) n = 1; // Default
233  scrollUp(_cuY, n);
234 }
235 
236 void Screen::insertLines(int n)
237 {
238  if (n == 0) n = 1; // Default
239  scrollDown(_cuY, n);
240 }
241 
242 void Screen::setMode(int m)
243 {
244  _currentModes[m] = true;
245  switch (m) {
246  case MODE_Origin :
247  _cuX = 0;
248  _cuY = _topMargin;
249  break; //FIXME: home
250  }
251 }
252 
253 void Screen::resetMode(int m)
254 {
255  _currentModes[m] = false;
256  switch (m) {
257  case MODE_Origin :
258  _cuX = 0;
259  _cuY = 0;
260  break; //FIXME: home
261  }
262 }
263 
264 void Screen::saveMode(int m)
265 {
266  _savedModes[m] = _currentModes[m];
267 }
268 
269 void Screen::restoreMode(int m)
270 {
271  _currentModes[m] = _savedModes[m];
272 }
273 
274 bool Screen::getMode(int m) const
275 {
276  return _currentModes[m];
277 }
278 
279 void Screen::saveCursor()
280 {
281  _savedState.cursorColumn = _cuX;
282  _savedState.cursorLine = _cuY;
283  _savedState.rendition = _currentRendition;
284  _savedState.foreground = _currentForeground;
285  _savedState.background = _currentBackground;
286 }
287 
288 void Screen::restoreCursor()
289 {
290  _cuX = qMin(_savedState.cursorColumn, _columns - 1);
291  _cuY = qMin(_savedState.cursorLine, _lines - 1);
292  _currentRendition = _savedState.rendition;
293  _currentForeground = _savedState.foreground;
294  _currentBackground = _savedState.background;
295  updateEffectiveRendition();
296 }
297 
298 void Screen::resizeImage(int new_lines, int new_columns)
299 {
300  if ((new_lines == _lines) && (new_columns == _columns)) return;
301 
302  if (_cuY > new_lines - 1) {
303  // attempt to preserve focus and _lines
304  _bottomMargin = _lines - 1; //FIXME: margin lost
305  for (int i = 0; i < _cuY - (new_lines - 1); i++) {
306  addHistLine();
307  scrollUp(0, 1);
308  }
309  }
310 
311  // create new screen _lines and copy from old to new
312 
313  ImageLine* newScreenLines = new ImageLine[new_lines + 1];
314  for (int i = 0; i < qMin(_lines, new_lines + 1) ; i++)
315  newScreenLines[i] = _screenLines[i];
316  for (int i = _lines; (i > 0) && (i < new_lines + 1); i++)
317  newScreenLines[i].resize(new_columns);
318 
319  _lineProperties.resize(new_lines + 1);
320  for (int i = _lines; (i > 0) && (i < new_lines + 1); i++)
321  _lineProperties[i] = LINE_DEFAULT;
322 
323  clearSelection();
324 
325  delete[] _screenLines;
326  _screenLines = newScreenLines;
327  _screenLinesSize = new_lines;
328 
329  _lines = new_lines;
330  _columns = new_columns;
331  _cuX = qMin(_cuX, _columns - 1);
332  _cuY = qMin(_cuY, _lines - 1);
333 
334  // FIXME: try to keep values, evtl.
335  _topMargin = 0;
336  _bottomMargin = _lines - 1;
337  initTabStops();
338  clearSelection();
339 }
340 
341 void Screen::setDefaultMargins()
342 {
343  _topMargin = 0;
344  _bottomMargin = _lines - 1;
345 }
346 
347 /*
348  Clarifying rendition here and in the display.
349 
350  currently, the display's color table is
351  0 1 2 .. 9 10 .. 17
352  dft_fg, dft_bg, dim 0..7, intensive 0..7
353 
354  _currentForeground, _currentBackground contain values 0..8;
355  - 0 = default color
356  - 1..8 = ansi specified color
357 
358  re_fg, re_bg contain values 0..17
359  due to the TerminalDisplay's color table
360 
361  rendition attributes are
362 
363  attr widget screen
364  -------------- ------ ------
365  RE_UNDERLINE XX XX affects foreground only
366  RE_BLINK XX XX affects foreground only
367  RE_BOLD XX XX affects foreground only
368  RE_REVERSE -- XX
369  RE_TRANSPARENT XX -- affects background only
370  RE_INTENSIVE XX -- affects foreground only
371 
372  Note that RE_BOLD is used in both widget
373  and screen rendition. Since xterm/vt102
374  is to poor to distinguish between bold
375  (which is a font attribute) and intensive
376  (which is a color attribute), we translate
377  this and RE_BOLD in falls eventually apart
378  into RE_BOLD and RE_INTENSIVE.
379  */
380 
381 void Screen::reverseRendition(Character& p) const
382 {
383  CharacterColor f = p.foregroundColor;
384  CharacterColor b = p.backgroundColor;
385 
386  p.foregroundColor = b;
387  p.backgroundColor = f; //p->r &= ~RE_TRANSPARENT;
388 }
389 
390 void Screen::updateEffectiveRendition()
391 {
392  _effectiveRendition = _currentRendition;
393  if (_currentRendition & RE_REVERSE) {
394  _effectiveForeground = _currentBackground;
395  _effectiveBackground = _currentForeground;
396  } else {
397  _effectiveForeground = _currentForeground;
398  _effectiveBackground = _currentBackground;
399  }
400 
401  if (_currentRendition & RE_BOLD)
402  _effectiveForeground.setIntensive();
403 }
404 
405 void Screen::copyFromHistory(Character* dest, int startLine, int count) const
406 {
407  Q_ASSERT(startLine >= 0 && count > 0 && startLine + count <= _history->getLines());
408 
409  for (int line = startLine; line < startLine + count; line++) {
410  const int length = qMin(_columns, _history->getLineLen(line));
411  const int destLineOffset = (line - startLine) * _columns;
412 
413  _history->getCells(line, 0, length, dest + destLineOffset);
414 
415  for (int column = length; column < _columns; column++)
416  dest[destLineOffset + column] = Screen::DefaultChar;
417 
418  // invert selected text
419  if (_selBegin != -1) {
420  for (int column = 0; column < _columns; column++) {
421  if (isSelected(column, line)) {
422  reverseRendition(dest[destLineOffset + column]);
423  }
424  }
425  }
426  }
427 }
428 
429 void Screen::copyFromScreen(Character* dest , int startLine , int count) const
430 {
431  Q_ASSERT(startLine >= 0 && count > 0 && startLine + count <= _lines);
432 
433  for (int line = startLine; line < (startLine + count) ; line++) {
434  int srcLineStartIndex = line * _columns;
435  int destLineStartIndex = (line - startLine) * _columns;
436 
437  for (int column = 0; column < _columns; column++) {
438  int srcIndex = srcLineStartIndex + column;
439  int destIndex = destLineStartIndex + column;
440 
441  dest[destIndex] = _screenLines[srcIndex / _columns].value(srcIndex % _columns, Screen::DefaultChar);
442 
443  // invert selected text
444  if (_selBegin != -1 && isSelected(column, line + _history->getLines()))
445  reverseRendition(dest[destIndex]);
446  }
447  }
448 }
449 
450 void Screen::getImage(Character* dest, int size, int startLine, int endLine) const
451 {
452  Q_ASSERT(startLine >= 0);
453  Q_ASSERT(endLine >= startLine && endLine < _history->getLines() + _lines);
454 
455  const int mergedLines = endLine - startLine + 1;
456 
457  Q_ASSERT(size >= mergedLines * _columns);
458  Q_UNUSED(size);
459 
460  const int linesInHistoryBuffer = qBound(0, _history->getLines() - startLine, mergedLines);
461  const int linesInScreenBuffer = mergedLines - linesInHistoryBuffer;
462 
463  // copy _lines from history buffer
464  if (linesInHistoryBuffer > 0)
465  copyFromHistory(dest, startLine, linesInHistoryBuffer);
466 
467  // copy _lines from screen buffer
468  if (linesInScreenBuffer > 0)
469  copyFromScreen(dest + linesInHistoryBuffer * _columns,
470  startLine + linesInHistoryBuffer - _history->getLines(),
471  linesInScreenBuffer);
472 
473  // invert display when in screen mode
474  if (getMode(MODE_Screen)) {
475  for (int i = 0; i < mergedLines * _columns; i++)
476  reverseRendition(dest[i]); // for reverse display
477  }
478 
479  // mark the character at the current cursor position
480  int cursorIndex = loc(_cuX, _cuY + linesInHistoryBuffer);
481  if (getMode(MODE_Cursor) && cursorIndex < _columns * mergedLines)
482  dest[cursorIndex].rendition |= RE_CURSOR;
483 }
484 
485 QVector<LineProperty> Screen::getLineProperties(int startLine , int endLine) const
486 {
487  Q_ASSERT(startLine >= 0);
488  Q_ASSERT(endLine >= startLine && endLine < _history->getLines() + _lines);
489 
490  const int mergedLines = endLine - startLine + 1;
491  const int linesInHistory = qBound(0, _history->getLines() - startLine, mergedLines);
492  const int linesInScreen = mergedLines - linesInHistory;
493 
494  QVector<LineProperty> result(mergedLines);
495  int index = 0;
496 
497  // copy properties for _lines in history
498  for (int line = startLine; line < startLine + linesInHistory; line++) {
499  //TODO Support for line properties other than wrapped _lines
500  if (_history->isWrappedLine(line)) {
501  result[index] = (LineProperty)(result[index] | LINE_WRAPPED);
502  }
503  index++;
504  }
505 
506  // copy properties for _lines in screen buffer
507  const int firstScreenLine = startLine + linesInHistory - _history->getLines();
508  for (int line = firstScreenLine; line < firstScreenLine + linesInScreen; line++) {
509  result[index] = _lineProperties[line];
510  index++;
511  }
512 
513  return result;
514 }
515 
516 void Screen::reset(bool clearScreen)
517 {
518  setMode(MODE_Wrap);
519  saveMode(MODE_Wrap); // wrap at end of margin
520 
521  resetMode(MODE_Origin);
522  saveMode(MODE_Origin); // position refer to [1,1]
523 
524  resetMode(MODE_Insert);
525  saveMode(MODE_Insert); // overstroke
526 
527  setMode(MODE_Cursor); // cursor visible
528  resetMode(MODE_Screen); // screen not inverse
529  resetMode(MODE_NewLine);
530 
531  _topMargin = 0;
532  _bottomMargin = _lines - 1;
533 
534  setDefaultRendition();
535  saveCursor();
536 
537  if (clearScreen)
538  clear();
539 }
540 
541 void Screen::clear()
542 {
543  clearEntireScreen();
544  home();
545 }
546 
547 void Screen::backspace()
548 {
549  _cuX = qMin(_columns - 1, _cuX); // nowrap!
550  _cuX = qMax(0, _cuX - 1);
551 
552  if (_screenLines[_cuY].size() < _cuX + 1)
553  _screenLines[_cuY].resize(_cuX + 1);
554 
555  if (BS_CLEARS) {
556  _screenLines[_cuY][_cuX].character = ' ';
557  _screenLines[_cuY][_cuX].rendition = _screenLines[_cuY][_cuX].rendition & ~RE_EXTENDED_CHAR;
558  }
559 }
560 
561 void Screen::tab(int n)
562 {
563  // note that TAB is a format effector (does not write ' ');
564  if (n == 0) n = 1;
565  while ((n > 0) && (_cuX < _columns - 1)) {
566  cursorRight(1);
567  while ((_cuX < _columns - 1) && !_tabStops[_cuX])
568  cursorRight(1);
569  n--;
570  }
571 }
572 
573 void Screen::backtab(int n)
574 {
575  // note that TAB is a format effector (does not write ' ');
576  if (n == 0) n = 1;
577  while ((n > 0) && (_cuX > 0)) {
578  cursorLeft(1);
579  while ((_cuX > 0) && !_tabStops[_cuX]) {
580  cursorLeft(1);
581  }
582  n--;
583  }
584 }
585 
586 void Screen::clearTabStops()
587 {
588  for (int i = 0; i < _columns; i++)
589  _tabStops[i] = false;
590 }
591 
592 void Screen::changeTabStop(bool set)
593 {
594  if (_cuX >= _columns)
595  return;
596 
597  _tabStops[_cuX] = set;
598 }
599 
600 void Screen::initTabStops()
601 {
602  _tabStops.resize(_columns);
603 
604  // The 1st tabstop has to be one longer than the other.
605  // i.e. the kids start counting from 0 instead of 1.
606  // Other programs might behave correctly. Be aware.
607  for (int i = 0; i < _columns; i++)
608  _tabStops[i] = (i % 8 == 0 && i != 0);
609 }
610 
611 void Screen::newLine()
612 {
613  if (getMode(MODE_NewLine))
614  toStartOfLine();
615 
616  index();
617 }
618 
619 void Screen::checkSelection(int from, int to)
620 {
621  if (_selBegin == -1)
622  return;
623  const int scr_TL = loc(0, _history->getLines());
624  //Clear entire selection if it overlaps region [from, to]
625  if ((_selBottomRight >= (from + scr_TL)) && (_selTopLeft <= (to + scr_TL)))
626  clearSelection();
627 }
628 
629 void Screen::displayCharacter(unsigned short c)
630 {
631  // Note that VT100 does wrapping BEFORE putting the character.
632  // This has impact on the assumption of valid cursor positions.
633  // We indicate the fact that a newline has to be triggered by
634  // putting the cursor one right to the last column of the screen.
635 
636  int w = konsole_wcwidth(c);
637  if (w < 0)
638  return;
639  else if (w == 0) {
640  if (QChar(c).category() != QChar::Mark_NonSpacing)
641  return;
642  int charToCombineWithX = -1;
643  int charToCombineWithY = -1;
644  if (_cuX == 0) {
645  // We are at the beginning of a line, check
646  // if previous line has a character at the end we can combine with
647  if (_cuY > 0 && _columns == _screenLines[_cuY - 1].size()) {
648  charToCombineWithX = _columns - 1;
649  charToCombineWithY = _cuY - 1;
650  } else {
651  // There is nothing to combine with
652  // TODO Seems gnome-terminal shows the characters alone
653  // might be worth investigating how to do that
654  return;
655  }
656  } else {
657  charToCombineWithX = _cuX - 1;
658  charToCombineWithY = _cuY;
659  }
660 
661  // Prevent "cat"ing binary files from causing crashes.
662  if (charToCombineWithX >= _screenLines[charToCombineWithY].size()) {
663  return;
664  }
665 
666  Character& currentChar = _screenLines[charToCombineWithY][charToCombineWithX];
667  if ((currentChar.rendition & RE_EXTENDED_CHAR) == 0) {
668  const ushort chars[2] = { currentChar.character, c };
669  currentChar.rendition |= RE_EXTENDED_CHAR;
670  currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, 2);
671  } else {
672  ushort extendedCharLength;
673  const ushort* oldChars = ExtendedCharTable::instance.lookupExtendedChar(currentChar.character, extendedCharLength);
674  Q_ASSERT(oldChars);
675  if (oldChars) {
676  Q_ASSERT(extendedCharLength > 1);
677  Q_ASSERT(extendedCharLength < 65535);
678  ushort* chars = new ushort[extendedCharLength + 1];
679  memcpy(chars, oldChars, sizeof(ushort) * extendedCharLength);
680  chars[extendedCharLength] = c;
681  currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, extendedCharLength + 1);
682  delete[] chars;
683  }
684  }
685  return;
686  }
687 
688  if (_cuX + w > _columns) {
689  if (getMode(MODE_Wrap)) {
690  _lineProperties[_cuY] = (LineProperty)(_lineProperties[_cuY] | LINE_WRAPPED);
691  nextLine();
692  } else {
693  _cuX = _columns - w;
694  }
695  }
696 
697  // ensure current line vector has enough elements
698  if (_screenLines[_cuY].size() < _cuX + w) {
699  _screenLines[_cuY].resize(_cuX + w);
700  }
701 
702  if (getMode(MODE_Insert)) insertChars(w);
703 
704  _lastPos = loc(_cuX, _cuY);
705 
706  // check if selection is still valid.
707  checkSelection(_lastPos, _lastPos);
708 
709  Character& currentChar = _screenLines[_cuY][_cuX];
710 
711  currentChar.character = c;
712  currentChar.foregroundColor = _effectiveForeground;
713  currentChar.backgroundColor = _effectiveBackground;
714  currentChar.rendition = _effectiveRendition;
715  currentChar.isRealCharacter = true;
716 
717  int i = 0;
718  const int newCursorX = _cuX + w--;
719  while (w) {
720  i++;
721 
722  if (_screenLines[_cuY].size() < _cuX + i + 1)
723  _screenLines[_cuY].resize(_cuX + i + 1);
724 
725  Character& ch = _screenLines[_cuY][_cuX + i];
726  ch.character = 0;
727  ch.foregroundColor = _effectiveForeground;
728  ch.backgroundColor = _effectiveBackground;
729  ch.rendition = _effectiveRendition;
730  ch.isRealCharacter = false;
731 
732  w--;
733  }
734  _cuX = newCursorX;
735 }
736 
737 int Screen::scrolledLines() const
738 {
739  return _scrolledLines;
740 }
741 int Screen::droppedLines() const
742 {
743  return _droppedLines;
744 }
745 void Screen::resetDroppedLines()
746 {
747  _droppedLines = 0;
748 }
749 void Screen::resetScrolledLines()
750 {
751  _scrolledLines = 0;
752 }
753 
754 void Screen::scrollUp(int n)
755 {
756  if (n == 0) n = 1; // Default
757  if (_topMargin == 0) addHistLine(); // history.history
758  scrollUp(_topMargin, n);
759 }
760 
761 QRect Screen::lastScrolledRegion() const
762 {
763  return _lastScrolledRegion;
764 }
765 
766 void Screen::scrollUp(int from, int n)
767 {
768  if (n <= 0 || from + n > _bottomMargin) return;
769 
770  _scrolledLines -= n;
771  _lastScrolledRegion = QRect(0, _topMargin, _columns - 1, (_bottomMargin - _topMargin));
772 
773  //FIXME: make sure `topMargin', `bottomMargin', `from', `n' is in bounds.
774  moveImage(loc(0, from), loc(0, from + n), loc(_columns - 1, _bottomMargin));
775  clearImage(loc(0, _bottomMargin - n + 1), loc(_columns - 1, _bottomMargin), ' ');
776 }
777 
778 void Screen::scrollDown(int n)
779 {
780  if (n == 0) n = 1; // Default
781  scrollDown(_topMargin, n);
782 }
783 
784 void Screen::scrollDown(int from, int n)
785 {
786  _scrolledLines += n;
787 
788  //FIXME: make sure `topMargin', `bottomMargin', `from', `n' is in bounds.
789  if (n <= 0)
790  return;
791  if (from > _bottomMargin)
792  return;
793  if (from + n > _bottomMargin)
794  n = _bottomMargin - from;
795  moveImage(loc(0, from + n), loc(0, from), loc(_columns - 1, _bottomMargin - n));
796  clearImage(loc(0, from), loc(_columns - 1, from + n - 1), ' ');
797 }
798 
799 void Screen::setCursorYX(int y, int x)
800 {
801  setCursorY(y);
802  setCursorX(x);
803 }
804 
805 void Screen::setCursorX(int x)
806 {
807  if (x == 0) x = 1; // Default
808  x -= 1; // Adjust
809  _cuX = qMax(0, qMin(_columns - 1, x));
810 }
811 
812 void Screen::setCursorY(int y)
813 {
814  if (y == 0) y = 1; // Default
815  y -= 1; // Adjust
816  _cuY = qMax(0, qMin(_lines - 1, y + (getMode(MODE_Origin) ? _topMargin : 0)));
817 }
818 
819 void Screen::home()
820 {
821  _cuX = 0;
822  _cuY = 0;
823 }
824 
825 void Screen::toStartOfLine()
826 {
827  _cuX = 0;
828 }
829 
830 int Screen::getCursorX() const
831 {
832  return _cuX;
833 }
834 
835 int Screen::getCursorY() const
836 {
837  return _cuY;
838 }
839 
840 void Screen::clearImage(int loca, int loce, char c)
841 {
842  const int scr_TL = loc(0, _history->getLines());
843  //FIXME: check positions
844 
845  //Clear entire selection if it overlaps region to be moved...
846  if ((_selBottomRight > (loca + scr_TL)) && (_selTopLeft < (loce + scr_TL))) {
847  clearSelection();
848  }
849 
850  const int topLine = loca / _columns;
851  const int bottomLine = loce / _columns;
852 
853  Character clearCh(c, _currentForeground, _currentBackground, DEFAULT_RENDITION, false);
854 
855  //if the character being used to clear the area is the same as the
856  //default character, the affected _lines can simply be shrunk.
857  const bool isDefaultCh = (clearCh == Screen::DefaultChar);
858 
859  for (int y = topLine; y <= bottomLine; y++) {
860  _lineProperties[y] = 0;
861 
862  const int endCol = (y == bottomLine) ? loce % _columns : _columns - 1;
863  const int startCol = (y == topLine) ? loca % _columns : 0;
864 
865  QVector<Character>& line = _screenLines[y];
866 
867  if (isDefaultCh && endCol == _columns - 1) {
868  line.resize(startCol);
869  } else {
870  if (line.size() < endCol + 1)
871  line.resize(endCol + 1);
872 
873  Character* data = line.data();
874  for (int i = startCol; i <= endCol; i++)
875  data[i] = clearCh;
876  }
877  }
878 }
879 
880 void Screen::moveImage(int dest, int sourceBegin, int sourceEnd)
881 {
882  Q_ASSERT(sourceBegin <= sourceEnd);
883 
884  const int lines = (sourceEnd - sourceBegin) / _columns;
885 
886  //move screen image and line properties:
887  //the source and destination areas of the image may overlap,
888  //so it matters that we do the copy in the right order -
889  //forwards if dest < sourceBegin or backwards otherwise.
890  //(search the web for 'memmove implementation' for details)
891  if (dest < sourceBegin) {
892  for (int i = 0; i <= lines; i++) {
893  _screenLines[(dest / _columns) + i ] = _screenLines[(sourceBegin / _columns) + i ];
894  _lineProperties[(dest / _columns) + i] = _lineProperties[(sourceBegin / _columns) + i];
895  }
896  } else {
897  for (int i = lines; i >= 0; i--) {
898  _screenLines[(dest / _columns) + i ] = _screenLines[(sourceBegin / _columns) + i ];
899  _lineProperties[(dest / _columns) + i] = _lineProperties[(sourceBegin / _columns) + i];
900  }
901  }
902 
903  if (_lastPos != -1) {
904  const int diff = dest - sourceBegin; // Scroll by this amount
905  _lastPos += diff;
906  if ((_lastPos < 0) || (_lastPos >= (lines * _columns)))
907  _lastPos = -1;
908  }
909 
910  // Adjust selection to follow scroll.
911  if (_selBegin != -1) {
912  const bool beginIsTL = (_selBegin == _selTopLeft);
913  const int diff = dest - sourceBegin; // Scroll by this amount
914  const int scr_TL = loc(0, _history->getLines());
915  const int srca = sourceBegin + scr_TL; // Translate index from screen to global
916  const int srce = sourceEnd + scr_TL; // Translate index from screen to global
917  const int desta = srca + diff;
918  const int deste = srce + diff;
919 
920  if ((_selTopLeft >= srca) && (_selTopLeft <= srce))
921  _selTopLeft += diff;
922  else if ((_selTopLeft >= desta) && (_selTopLeft <= deste))
923  _selBottomRight = -1; // Clear selection (see below)
924 
925  if ((_selBottomRight >= srca) && (_selBottomRight <= srce))
926  _selBottomRight += diff;
927  else if ((_selBottomRight >= desta) && (_selBottomRight <= deste))
928  _selBottomRight = -1; // Clear selection (see below)
929 
930  if (_selBottomRight < 0) {
931  clearSelection();
932  } else {
933  if (_selTopLeft < 0)
934  _selTopLeft = 0;
935  }
936 
937  if (beginIsTL)
938  _selBegin = _selTopLeft;
939  else
940  _selBegin = _selBottomRight;
941  }
942 }
943 
944 void Screen::clearToEndOfScreen()
945 {
946  clearImage(loc(_cuX, _cuY), loc(_columns - 1, _lines - 1), ' ');
947 }
948 
949 void Screen::clearToBeginOfScreen()
950 {
951  clearImage(loc(0, 0), loc(_cuX, _cuY), ' ');
952 }
953 
954 void Screen::clearEntireScreen()
955 {
956  // Add entire screen to history
957  for (int i = 0; i < (_lines - 1); i++) {
958  addHistLine();
959  scrollUp(0, 1);
960  }
961 
962  clearImage(loc(0, 0), loc(_columns - 1, _lines - 1), ' ');
963 }
964 
969 void Screen::helpAlign()
970 {
971  clearImage(loc(0, 0), loc(_columns - 1, _lines - 1), 'E');
972 }
973 
974 void Screen::clearToEndOfLine()
975 {
976  clearImage(loc(_cuX, _cuY), loc(_columns - 1, _cuY), ' ');
977 }
978 
979 void Screen::clearToBeginOfLine()
980 {
981  clearImage(loc(0, _cuY), loc(_cuX, _cuY), ' ');
982 }
983 
984 void Screen::clearEntireLine()
985 {
986  clearImage(loc(0, _cuY), loc(_columns - 1, _cuY), ' ');
987 }
988 
989 void Screen::setRendition(int rendention)
990 {
991  _currentRendition |= rendention;
992  updateEffectiveRendition();
993 }
994 
995 void Screen::resetRendition(int rendention)
996 {
997  _currentRendition &= ~rendention;
998  updateEffectiveRendition();
999 }
1000 
1001 void Screen::setDefaultRendition()
1002 {
1003  setForeColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR);
1004  setBackColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR);
1005  _currentRendition = DEFAULT_RENDITION;
1006  updateEffectiveRendition();
1007 }
1008 
1009 void Screen::setForeColor(int space, int color)
1010 {
1011  _currentForeground = CharacterColor(space, color);
1012 
1013  if (_currentForeground.isValid())
1014  updateEffectiveRendition();
1015  else
1016  setForeColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR);
1017 }
1018 
1019 void Screen::setBackColor(int space, int color)
1020 {
1021  _currentBackground = CharacterColor(space, color);
1022 
1023  if (_currentBackground.isValid())
1024  updateEffectiveRendition();
1025  else
1026  setBackColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR);
1027 }
1028 
1029 void Screen::clearSelection()
1030 {
1031  _selBottomRight = -1;
1032  _selTopLeft = -1;
1033  _selBegin = -1;
1034 }
1035 
1036 void Screen::getSelectionStart(int& column , int& line) const
1037 {
1038  if (_selTopLeft != -1) {
1039  column = _selTopLeft % _columns;
1040  line = _selTopLeft / _columns;
1041  } else {
1042  column = _cuX + getHistLines();
1043  line = _cuY + getHistLines();
1044  }
1045 }
1046 void Screen::getSelectionEnd(int& column , int& line) const
1047 {
1048  if (_selBottomRight != -1) {
1049  column = _selBottomRight % _columns;
1050  line = _selBottomRight / _columns;
1051  } else {
1052  column = _cuX + getHistLines();
1053  line = _cuY + getHistLines();
1054  }
1055 }
1056 void Screen::setSelectionStart(const int x, const int y, const bool blockSelectionMode)
1057 {
1058  _selBegin = loc(x, y);
1059  /* FIXME, HACK to correct for x too far to the right... */
1060  if (x == _columns) _selBegin--;
1061 
1062  _selBottomRight = _selBegin;
1063  _selTopLeft = _selBegin;
1064  _blockSelectionMode = blockSelectionMode;
1065 }
1066 
1067 void Screen::setSelectionEnd(const int x, const int y)
1068 {
1069  if (_selBegin == -1)
1070  return;
1071 
1072  int endPos = loc(x, y);
1073 
1074  if (endPos < _selBegin) {
1075  _selTopLeft = endPos;
1076  _selBottomRight = _selBegin;
1077  } else {
1078  /* FIXME, HACK to correct for x too far to the right... */
1079  if (x == _columns)
1080  endPos--;
1081 
1082  _selTopLeft = _selBegin;
1083  _selBottomRight = endPos;
1084  }
1085 
1086  // Normalize the selection in column mode
1087  if (_blockSelectionMode) {
1088  const int topRow = _selTopLeft / _columns;
1089  const int topColumn = _selTopLeft % _columns;
1090  const int bottomRow = _selBottomRight / _columns;
1091  const int bottomColumn = _selBottomRight % _columns;
1092 
1093  _selTopLeft = loc(qMin(topColumn, bottomColumn), topRow);
1094  _selBottomRight = loc(qMax(topColumn, bottomColumn), bottomRow);
1095  }
1096 }
1097 
1098 bool Screen::isSelected(const int x, const int y) const
1099 {
1100  bool columnInSelection = true;
1101  if (_blockSelectionMode) {
1102  columnInSelection = x >= (_selTopLeft % _columns) &&
1103  x <= (_selBottomRight % _columns);
1104  }
1105 
1106  const int pos = loc(x, y);
1107  return pos >= _selTopLeft && pos <= _selBottomRight && columnInSelection;
1108 }
1109 
1110 QString Screen::selectedText(bool preserveLineBreaks, bool trimTrailingSpaces) const
1111 {
1112  if (!isSelectionValid())
1113  return QString();
1114 
1115  return text(_selTopLeft, _selBottomRight, preserveLineBreaks, trimTrailingSpaces);
1116 }
1117 
1118 QString Screen::text(int startIndex, int endIndex, bool preserveLineBreaks, bool trimTrailingSpaces) const
1119 {
1120  QString result;
1121  QTextStream stream(&result, QIODevice::ReadWrite);
1122 
1123  PlainTextDecoder decoder;
1124  decoder.begin(&stream);
1125  writeToStream(&decoder, startIndex, endIndex, preserveLineBreaks, trimTrailingSpaces);
1126  decoder.end();
1127 
1128  return result;
1129 }
1130 
1131 bool Screen::isSelectionValid() const
1132 {
1133  return _selTopLeft >= 0 && _selBottomRight >= 0;
1134 }
1135 
1136 void Screen::writeSelectionToStream(TerminalCharacterDecoder* decoder ,
1137  bool preserveLineBreaks,
1138  bool trimTrailingSpaces) const
1139 {
1140  if (!isSelectionValid())
1141  return;
1142  writeToStream(decoder, _selTopLeft, _selBottomRight, preserveLineBreaks, trimTrailingSpaces);
1143 }
1144 
1145 void Screen::writeToStream(TerminalCharacterDecoder* decoder,
1146  int startIndex, int endIndex,
1147  bool preserveLineBreaks,
1148  bool trimTrailingSpaces) const
1149 {
1150  const int top = startIndex / _columns;
1151  const int left = startIndex % _columns;
1152 
1153  const int bottom = endIndex / _columns;
1154  const int right = endIndex % _columns;
1155 
1156  Q_ASSERT(top >= 0 && left >= 0 && bottom >= 0 && right >= 0);
1157 
1158  for (int y = top; y <= bottom; y++) {
1159  int start = 0;
1160  if (y == top || _blockSelectionMode) start = left;
1161 
1162  int count = -1;
1163  if (y == bottom || _blockSelectionMode) count = right - start + 1;
1164 
1165  const bool appendNewLine = (y != bottom);
1166  int copied = copyLineToStream(y,
1167  start,
1168  count,
1169  decoder,
1170  appendNewLine,
1171  preserveLineBreaks,
1172  trimTrailingSpaces);
1173 
1174  // if the selection goes beyond the end of the last line then
1175  // append a new line character.
1176  //
1177  // this makes it possible to 'select' a trailing new line character after
1178  // the text on a line.
1179  if (y == bottom &&
1180  copied < count) {
1181  Character newLineChar('\n');
1182  decoder->decodeLine(&newLineChar, 1, 0);
1183  }
1184  }
1185 }
1186 
1187 int Screen::copyLineToStream(int line ,
1188  int start,
1189  int count,
1190  TerminalCharacterDecoder* decoder,
1191  bool appendNewLine,
1192  bool preserveLineBreaks,
1193  bool trimTrailingSpaces) const
1194 {
1195  //buffer to hold characters for decoding
1196  //the buffer is static to avoid initializing every
1197  //element on each call to copyLineToStream
1198  //(which is unnecessary since all elements will be overwritten anyway)
1199  static const int MAX_CHARS = 1024;
1200  static Character characterBuffer[MAX_CHARS];
1201 
1202  Q_ASSERT(count < MAX_CHARS);
1203 
1204  LineProperty currentLineProperties = 0;
1205 
1206  //determine if the line is in the history buffer or the screen image
1207  if (line < _history->getLines()) {
1208  const int lineLength = _history->getLineLen(line);
1209 
1210  // ensure that start position is before end of line
1211  start = qMin(start, qMax(0, lineLength - 1));
1212 
1213  // retrieve line from history buffer. It is assumed
1214  // that the history buffer does not store trailing white space
1215  // at the end of the line, so it does not need to be trimmed here
1216  if (count == -1) {
1217  count = lineLength - start;
1218  } else {
1219  count = qMin(start + count, lineLength) - start;
1220  }
1221 
1222  // safety checks
1223  Q_ASSERT(start >= 0);
1224  Q_ASSERT(count >= 0);
1225  Q_ASSERT((start + count) <= _history->getLineLen(line));
1226 
1227  _history->getCells(line, start, count, characterBuffer);
1228 
1229  if (_history->isWrappedLine(line))
1230  currentLineProperties |= LINE_WRAPPED;
1231  } else {
1232  if (count == -1)
1233  count = _columns - start;
1234 
1235  Q_ASSERT(count >= 0);
1236 
1237  int screenLine = line - _history->getLines();
1238 
1239  Q_ASSERT(screenLine <= _screenLinesSize);
1240 
1241  screenLine = qMin(screenLine, _screenLinesSize);
1242 
1243  Character* data = _screenLines[screenLine].data();
1244  int length = _screenLines[screenLine].count();
1245 
1246  // Don't remove end spaces in lines that wrap
1247  if (trimTrailingSpaces && !(_lineProperties[screenLine] & LINE_WRAPPED))
1248  {
1249  // ignore trailing white space at the end of the line
1250  for (int i = length-1; i >= 0; i--)
1251  {
1252  if (data[i].character == ' ')
1253  length--;
1254  else
1255  break;
1256  }
1257  }
1258 
1259  //retrieve line from screen image
1260  for (int i = start; i < qMin(start + count, length); i++) {
1261  characterBuffer[i - start] = data[i];
1262  }
1263 
1264  // count cannot be any greater than length
1265  count = qBound(0, count, length - start);
1266 
1267  Q_ASSERT(screenLine < _lineProperties.count());
1268  currentLineProperties |= _lineProperties[screenLine];
1269  }
1270 
1271  if (appendNewLine && (count + 1 < MAX_CHARS)) {
1272  if (currentLineProperties & LINE_WRAPPED) {
1273  // do nothing extra when this line is wrapped.
1274  } else {
1275  // When users ask not to preserve the linebreaks, they usually mean:
1276  // `treat LINEBREAK as SPACE, thus joining multiple _lines into
1277  // single line in the same way as 'J' does in VIM.`
1278  characterBuffer[count] = preserveLineBreaks ? Character('\n') : Character(' ');
1279  count++;
1280  }
1281  }
1282 
1283  //decode line and write to text stream
1284  decoder->decodeLine((Character*) characterBuffer ,
1285  count, currentLineProperties);
1286 
1287  return count;
1288 }
1289 
1290 void Screen::writeLinesToStream(TerminalCharacterDecoder* decoder, int fromLine, int toLine) const
1291 {
1292  writeToStream(decoder, loc(0, fromLine), loc(_columns - 1, toLine));
1293 }
1294 
1295 void Screen::addHistLine()
1296 {
1297  // add line to history buffer
1298  // we have to take care about scrolling, too...
1299 
1300  if (hasScroll()) {
1301  const int oldHistLines = _history->getLines();
1302 
1303  _history->addCellsVector(_screenLines[0]);
1304  _history->addLine(_lineProperties[0] & LINE_WRAPPED);
1305 
1306  const int newHistLines = _history->getLines();
1307 
1308  const bool beginIsTL = (_selBegin == _selTopLeft);
1309 
1310  // If the history is full, increment the count
1311  // of dropped _lines
1312  if (newHistLines == oldHistLines)
1313  _droppedLines++;
1314 
1315  // Adjust selection for the new point of reference
1316  if (newHistLines > oldHistLines) {
1317  if (_selBegin != -1) {
1318  _selTopLeft += _columns;
1319  _selBottomRight += _columns;
1320  }
1321  }
1322 
1323  if (_selBegin != -1) {
1324  // Scroll selection in history up
1325  const int top_BR = loc(0, 1 + newHistLines);
1326 
1327  if (_selTopLeft < top_BR)
1328  _selTopLeft -= _columns;
1329 
1330  if (_selBottomRight < top_BR)
1331  _selBottomRight -= _columns;
1332 
1333  if (_selBottomRight < 0) {
1334  clearSelection();
1335  } else {
1336  if (_selTopLeft < 0)
1337  _selTopLeft = 0;
1338  }
1339 
1340  if (beginIsTL)
1341  _selBegin = _selTopLeft;
1342  else
1343  _selBegin = _selBottomRight;
1344  }
1345  }
1346 }
1347 
1348 int Screen::getHistLines() const
1349 {
1350  return _history->getLines();
1351 }
1352 
1353 void Screen::setScroll(const HistoryType& t , bool copyPreviousScroll)
1354 {
1355  clearSelection();
1356 
1357  if (copyPreviousScroll) {
1358  _history = t.scroll(_history);
1359  } else {
1360  HistoryScroll* oldScroll = _history;
1361  _history = t.scroll(0);
1362  delete oldScroll;
1363  }
1364 }
1365 
1366 bool Screen::hasScroll() const
1367 {
1368  return _history->hasScroll();
1369 }
1370 
1371 const HistoryType& Screen::getScroll() const
1372 {
1373  return _history->getType();
1374 }
1375 
1376 void Screen::setLineProperty(LineProperty property , bool enable)
1377 {
1378  if (enable)
1379  _lineProperties[_cuY] = (LineProperty)(_lineProperties[_cuY] | property);
1380  else
1381  _lineProperties[_cuY] = (LineProperty)(_lineProperties[_cuY] & ~property);
1382 }
1383 void Screen::fillWithDefaultChar(Character* dest, int count)
1384 {
1385  for (int i = 0; i < count; i++)
1386  dest[i] = Screen::DefaultChar;
1387 }
Konsole::Screen::hasScroll
bool hasScroll() const
Returns true if this screen keeps lines that are scrolled off the screen in a history buffer...
Definition: Screen.cpp:1366
Konsole::Screen::droppedLines
int droppedLines() const
Returns the number of lines of output which have been dropped from the history since the last call to...
Definition: Screen.cpp:741
Konsole::PlainTextDecoder::end
virtual void end()
End decoding.
Definition: TerminalCharacterDecoder.cpp:55
Konsole::TerminalCharacterDecoder::decodeLine
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...
Konsole::Screen::helpAlign
void helpAlign()
Fills the entire screen with the letter 'E'.
Definition: Screen.cpp:969
Konsole::Screen::deleteChars
void deleteChars(int n)
Delete n characters beginning from the current cursor position.
Definition: Screen.cpp:188
Konsole::Screen::cursorLeft
void cursorLeft(int n)
Move the cursor to the left by n columns.
Definition: Screen.cpp:115
Konsole::Screen::lastScrolledRegion
QRect lastScrolledRegion() const
Returns the region of the image which was last scrolled.
Definition: Screen.cpp:761
Konsole::Screen::writeLinesToStream
void writeLinesToStream(TerminalCharacterDecoder *decoder, int fromLine, int toLine) const
Copies part of the output to a stream.
Definition: Screen.cpp:1290
Konsole::Screen::resetMode
void resetMode(int mode)
Resets (clears) the specified screen mode.
Definition: Screen.cpp:253
Konsole::Screen::setDefaultRendition
void setDefaultRendition()
Resets the cursor's color back to the default and sets the character's rendition flags back to the de...
Definition: Screen.cpp:1001
Konsole::Screen::scrollDown
void scrollDown(int n)
Scroll the scrolling region of the screen down by n lines.
Definition: Screen.cpp:778
Konsole::Screen::clearTabStops
void clearTabStops()
Clears all the tab stops.
Definition: Screen.cpp:586
ExtendedCharTable.h
Konsole::Screen::clearToEndOfScreen
void clearToEndOfScreen()
Clear the area of the screen from the current cursor position to the end of the screen.
Definition: Screen.cpp:944
Konsole::Character::character
quint16 character
The unicode character value for this character.
Definition: Character.h:108
Konsole::Screen::selectedText
QString selectedText(bool preserveLineBreaks, bool trimTrailingSpaces=false) const
Convenience method.
Definition: Screen.cpp:1110
Konsole::ExtendedCharTable::createExtendedChar
ushort createExtendedChar(const ushort *unicodePoints, ushort length)
Adds a sequences of unicode characters to the table and returns a hash code which can be used later t...
Definition: ExtendedCharTable.cpp:53
Konsole::Screen::getLines
int getLines() const
Return the number of lines.
Definition: Screen.h:382
Konsole::HistoryScroll::getType
const HistoryType & getType() const
Definition: History.h:115
Konsole::ExtendedCharTable::instance
static ExtendedCharTable instance
The global ExtendedCharTable instance.
Definition: ExtendedCharTable.h:68
DEFAULT_FORE_COLOR
#define DEFAULT_FORE_COLOR
Definition: CharacterColor.h:119
QBitArray::resize
void resize(int size)
QChar
Konsole::Screen::clearEntireScreen
void clearEntireScreen()
Clear the whole screen, moving the current screen contents into the history first.
Definition: Screen.cpp:954
Konsole::Screen::getImage
void getImage(Character *dest, int size, int startLine, int endLine) const
Returns the current screen image.
Definition: Screen.cpp:450
Screen.h
COLOR_SPACE_DEFAULT
#define COLOR_SPACE_DEFAULT
Definition: CharacterColor.h:139
Konsole::Screen::topMargin
int topMargin() const
Returns the top line of the scrolling region.
Definition: Screen.cpp:147
Konsole::Screen::cursorRight
void cursorRight(int n)
Move the cursor to the right by n columns.
Definition: Screen.cpp:123
Konsole::Screen::reverseIndex
void reverseIndex()
Move the cursor up one line.
Definition: Screen.cpp:165
Konsole::LINE_WRAPPED
const int LINE_WRAPPED
Definition: Character.h:34
Konsole::Screen::insertChars
void insertChars(int n)
Insert n blank characters beginning from the current cursor position.
Definition: Screen.cpp:217
QVector::insert
void insert(int i, const T &value)
konsole_wcwidth
int KONSOLEPRIVATE_EXPORT konsole_wcwidth(quint16 oucs)
Definition: konsole_wcwidth.cpp:129
Konsole::Screen::getScroll
const HistoryType & getScroll() const
Returns the type of storage used to keep lines in the history.
Definition: Screen.cpp:1371
Konsole::LineProperty
unsigned char LineProperty
Definition: Character.h:31
Konsole::HistoryScroll::getCells
virtual void getCells(int lineno, int colno, int count, Character res[])=0
Konsole::Screen::eraseChars
void eraseChars(int n)
Erase n characters beginning from the current cursor position.
Definition: Screen.cpp:181
Konsole::CharacterColor::setIntensive
void setIntensive()
Set this color as an intensive system color.
Definition: CharacterColor.h:297
Konsole::Screen::clearToEndOfLine
void clearToEndOfLine()
Clears from the current cursor position to the end of the line.
Definition: Screen.cpp:974
Konsole::Screen::changeTabStop
void changeTabStop(bool set)
Sets or removes a tab stop at the cursor's current column.
Definition: Screen.cpp:592
Konsole::Screen::clearEntireLine
void clearEntireLine()
Clears the whole of the line on which the cursor is currently positioned.
Definition: Screen.cpp:984
MODE_Origin
#define MODE_Origin
Definition: Screen.h:36
MODE_Insert
#define MODE_Insert
Definition: Screen.h:38
Konsole::Screen::fillWithDefaultChar
static void fillWithDefaultChar(Character *dest, int count)
Fills the buffer dest with count instances of the default (ie.
Definition: Screen.cpp:1383
Konsole::Screen::getMode
bool getMode(int mode) const
Returns whether the specified screen mode is enabled or not .
Definition: Screen.cpp:274
QTextStream
Konsole::Screen::setCursorYX
void setCursorYX(int y, int x)
Position the cursor at line y, column x.
Definition: Screen.cpp:799
Konsole::Screen::~Screen
~Screen()
Definition: Screen.cpp:91
Konsole::Screen::resetRendition
void resetRendition(int rendition)
Disables the given rendition flag.
Definition: Screen.cpp:995
Konsole::HistoryScroll::isWrappedLine
virtual bool isWrappedLine(int lineno)=0
QVector::value
T value(int i) const
Konsole::Screen::text
QString text(int startIndex, int endIndex, bool preserveLineBreaks, bool trimTrailingSpaces=false) const
Convenience method.
Definition: Screen.cpp:1118
Konsole::PlainTextDecoder
A terminal character decoder which produces plain text, ignoring colors and other appearance-related ...
Definition: TerminalCharacterDecoder.h:72
Konsole::Screen::cursorUp
void cursorUp(int n)
Move the cursor up by n lines.
Definition: Screen.cpp:97
Konsole::Screen::index
void index()
Move the cursor down one line.
Definition: Screen.cpp:156
Konsole::Screen::setMargins
void setMargins(int topLine, int bottomLine)
Sets the margins for scrolling the screen.
Definition: Screen.cpp:130
Konsole::Screen::DefaultChar
static const Character DefaultChar
Definition: Screen.h:586
Konsole::Character
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:77
konsole_wcwidth.h
QVector::data
T * data()
MODE_Screen
#define MODE_Screen
Definition: Screen.h:39
Konsole::Character::isRealCharacter
bool isRealCharacter
Indicate whether this character really exists, or exists simply as place holder.
Definition: Character.h:128
QRect
History.h
Konsole::HistoryScroll::addLine
virtual void addLine(bool previousWrapped=false)=0
Konsole::Screen::resetScrolledLines
void resetScrolledLines()
Resets the count of the number of lines that the image has been scrolled up or down by...
Definition: Screen.cpp:749
Konsole::HistoryScroll::getLines
virtual int getLines()=0
Konsole::TerminalCharacterDecoder
Base class for terminal character decoders.
Definition: TerminalCharacterDecoder.h:45
Konsole::Screen::setCursorY
void setCursorY(int y)
Position the cursor on line y.
Definition: Screen.cpp:812
Konsole::Screen::clear
void clear()
Clear the entire screen and move the cursor to the home position.
Definition: Screen.cpp:541
MODE_Cursor
#define MODE_Cursor
Definition: Screen.h:40
QVector::resize
void resize(int size)
Konsole::HistoryScroll::addCellsVector
virtual void addCellsVector(const QVector< Character > &cells)
Definition: History.h:104
Konsole::Screen::setForeColor
void setForeColor(int space, int color)
Sets the cursor's foreground color.
Definition: Screen.cpp:1009
Konsole::Screen::checkSelection
void checkSelection(int from, int to)
Checks if the text between from and to is inside the current selection.
Definition: Screen.cpp:619
Konsole::Screen::displayCharacter
void displayCharacter(unsigned short c)
Displays a new character at the current cursor position.
Definition: Screen.cpp:629
Konsole::Screen::setScroll
void setScroll(const HistoryType &, bool copyPreviousScroll=true)
Sets the type of storage used to keep lines in the history.
Definition: Screen.cpp:1353
Konsole::RE_REVERSE
const int RE_REVERSE
Definition: Character.h:42
Konsole::Screen::scrolledLines
int scrolledLines() const
Returns the number of lines that the image has been scrolled up or down by, since the last call to re...
Definition: Screen.cpp:737
QVector::remove
void remove(int i)
Konsole::ExtendedCharTable::lookupExtendedChar
ushort * lookupExtendedChar(ushort hash, ushort &length) const
Looks up and returns a pointer to a sequence of unicode characters which was added to the table using...
Definition: ExtendedCharTable.cpp:113
loc
#define loc(X, Y)
Definition: Screen.cpp:51
Konsole::Screen::newLine
void newLine()
Moves the cursor down one line, if the MODE_NewLine mode flag is enabled then the cursor is returned ...
Definition: Screen.cpp:611
Konsole::Screen::toStartOfLine
void toStartOfLine()
Moves the cursor to the beginning of the current line.
Definition: Screen.cpp:825
Konsole::Screen::setBackColor
void setBackColor(int space, int color)
Sets the cursor's background color.
Definition: Screen.cpp:1019
Konsole::Screen::cursorDown
void cursorDown(int n)
Move the cursor down by n lines.
Definition: Screen.cpp:106
Konsole::Character::backgroundColor
CharacterColor backgroundColor
The color used to draw this character's background.
Definition: Character.h:117
QString
Konsole::Screen::scrollUp
void scrollUp(int n)
Scroll the scrolling region of the screen up by n lines.
Definition: Screen.cpp:754
Konsole::Screen::restoreCursor
void restoreCursor()
Restores the position and appearance of the cursor.
Definition: Screen.cpp:288
Konsole::Screen::clearSelection
void clearSelection()
Clears the current selection.
Definition: Screen.cpp:1029
MODE_Wrap
#define MODE_Wrap
Definition: Screen.h:37
Konsole::DEFAULT_RENDITION
const int DEFAULT_RENDITION
Definition: Character.h:38
Konsole::Screen::insertLines
void insertLines(int n)
Inserts lines beginning from the current cursor position.
Definition: Screen.cpp:236
Konsole::HistoryScroll::getLineLen
virtual int getLineLen(int lineno)=0
Konsole::CharacterColor
Describes the color of a single character in the terminal.
Definition: CharacterColor.h:147
Konsole::Screen::getSelectionStart
void getSelectionStart(int &column, int &line) const
Retrieves the start of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1036
Konsole::Screen::setRendition
void setRendition(int rendition)
Enables the given rendition flag.
Definition: Screen.cpp:989
Konsole::HistoryType
Definition: History.h:319
Konsole::Screen::clearToBeginOfLine
void clearToBeginOfLine()
Clears from the current cursor position to the beginning of the line.
Definition: Screen.cpp:979
Konsole::Screen::deleteLines
void deleteLines(int n)
Removes n lines beginning from the current cursor position.
Definition: Screen.cpp:230
Konsole::Screen::bottomMargin
int bottomMargin() const
Returns the bottom line of the scrolling region.
Definition: Screen.cpp:151
Konsole::PlainTextDecoder::begin
virtual void begin(QTextStream *output)
Begin decoding characters.
Definition: TerminalCharacterDecoder.cpp:49
Konsole::Screen::Screen
Screen(int lines, int columns)
Construct a new screen image of size lines by columns.
Definition: Screen.cpp:60
Konsole::Screen::restoreMode
void restoreMode(int mode)
Restores the state of a screen mode saved by calling saveMode()
Definition: Screen.cpp:269
TerminalCharacterDecoder.h
Konsole::Screen::isSelected
bool isSelected(const int column, const int line) const
Returns true if the character at (column, line) is part of the current selection. ...
Definition: Screen.cpp:1098
Konsole::LINE_DEFAULT
const int LINE_DEFAULT
Definition: Character.h:33
Konsole::Screen::clearToBeginOfScreen
void clearToBeginOfScreen()
Clear the area of the screen from the current cursor position to the start of the screen...
Definition: Screen.cpp:949
Konsole::Screen::setDefaultMargins
void setDefaultMargins()
Resets the scrolling margins back to the top and bottom lines of the screen.
Definition: Screen.cpp:341
QVector
Konsole::Screen::getSelectionEnd
void getSelectionEnd(int &column, int &line) const
Retrieves the end of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1046
Konsole::Screen::getCursorX
int getCursorX() const
Returns the column which the cursor is positioned at.
Definition: Screen.cpp:830
Konsole::Screen::backspace
void backspace()
Moves the cursor one column to the left and erases the character at the new cursor position...
Definition: Screen.cpp:547
Konsole::Screen::resizeImage
void resizeImage(int new_lines, int new_columns)
Resizes the image to a new fixed size of new_lines by new_columns.
Definition: Screen.cpp:298
Konsole::Screen::getCursorY
int getCursorY() const
Returns the line which the cursor is positioned on.
Definition: Screen.cpp:835
Konsole::Screen::reset
void reset(bool clearScreen=true)
Resets the state of the screen.
Definition: Screen.cpp:516
QVector::count
int count(const T &value) const
Konsole::Screen::setSelectionEnd
void setSelectionEnd(const int column, const int line)
Sets the end of the current selection.
Definition: Screen.cpp:1067
Konsole::HistoryScroll
Definition: History.h:86
BS_CLEARS
const bool BS_CLEARS
Definition: Screen.cpp:39
Konsole::RE_BOLD
const int RE_BOLD
Definition: Character.h:39
Konsole::Screen::resetDroppedLines
void resetDroppedLines()
Resets the count of the number of lines dropped from the history.
Definition: Screen.cpp:745
QVarLengthArray::count
int count() const
Konsole::Screen::setLineProperty
void setLineProperty(LineProperty property, bool enable)
Sets or clears an attribute of the current line.
Definition: Screen.cpp:1376
Konsole::Screen::backtab
void backtab(int n)
Moves the cursor n tab-stops to the left.
Definition: Screen.cpp:573
Konsole::Screen::saveCursor
void saveCursor()
Saves the current position and appearance (text color and style) of the cursor.
Definition: Screen.cpp:279
MODE_NewLine
#define MODE_NewLine
Definition: Screen.h:41
Konsole::Screen::nextLine
void nextLine()
Moves the cursor down one line and positions it at the beginning of the line.
Definition: Screen.cpp:174
Konsole::Screen::home
void home()
Sets the position of the cursor to the 'home' position at the top-left corner of the screen (0...
Definition: Screen.cpp:819
Konsole::Screen::setCursorX
void setCursorX(int x)
Position the cursor at column x.
Definition: Screen.cpp:805
Konsole::Screen::setMode
void setMode(int mode)
Sets (enables) the specified screen mode.
Definition: Screen.cpp:242
Konsole::Screen::setSelectionStart
void setSelectionStart(const int column, const int line, const bool blockSelectionMode)
Sets the start of the selection.
Definition: Screen.cpp:1056
Konsole::Screen::getHistLines
int getHistLines() const
Return the number of lines in the history buffer.
Definition: Screen.cpp:1348
Konsole::HistoryScrollNone
Definition: History.h:152
QVector::size
int size() const
QVarLengthArray::resize
void resize(int size)
Konsole::Screen::getLineProperties
QVector< LineProperty > getLineProperties(int startLine, int endLine) const
Returns the additional attributes associated with lines in the image.
Definition: Screen.cpp:485
Konsole::Character::rendition
quint8 rendition
A combination of RENDITION flags which specify options for drawing the character. ...
Definition: Character.h:111
Konsole::Screen::tab
void tab(int n=1)
Moves the cursor n tab-stops to the right.
Definition: Screen.cpp:561
Konsole::RE_CURSOR
const int RE_CURSOR
Definition: Character.h:45
Konsole::Screen::saveMode
void saveMode(int mode)
Saves the state of the specified screen mode.
Definition: Screen.cpp:264
Konsole::Character::foregroundColor
CharacterColor foregroundColor
The foreground color used to draw this character.
Definition: Character.h:114
Konsole::CharacterColor::isValid
bool isValid() const
Returns true if this character color entry is valid.
Definition: CharacterColor.h:199
Konsole::HistoryScroll::hasScroll
virtual bool hasScroll()
Definition: History.cpp:180
Konsole::Screen::writeSelectionToStream
void writeSelectionToStream(TerminalCharacterDecoder *decoder, bool preserveLineBreaks=true, bool trimTrailingSpaces=false) const
Copies the selected characters, set using.
Definition: Screen.cpp:1136
Konsole::RE_EXTENDED_CHAR
const int RE_EXTENDED_CHAR
Definition: Character.h:46
Konsole::HistoryType::scroll
virtual HistoryScroll * scroll(HistoryScroll *) const =0
Converts from one type of HistoryScroll to another or if given the same type, returns it...
DEFAULT_BACK_COLOR
#define DEFAULT_BACK_COLOR
Definition: CharacterColor.h:120
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal