GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Screen.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Konsole, an X terminal.
3  Copyright (C) 1997-1998, 2013 by Lars Doelle <[email protected]>
4 
5  Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
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 "unix/Screen.h"
25 
26 // Standard
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <assert.h>
31 #include <string.h>
32 #include <ctype.h>
33 
34 // Qt
35 #include <QtCore/QTextStream>
36 #include <QtCore/QDate>
37 
38 // Konsole
39 #include "unix/konsole_wcwidth.h"
41 
42 //FIXME: this is emulation specific. Use false for xterm, true for ANSI.
43 //FIXME: see if we can get this from terminfo.
44 #define BS_CLEARS false
45 
46 //Macro to convert x,y position on screen to position within an image.
47 //
48 //Originally the image was stored as one large contiguous block of
49 //memory, so a position within the image could be represented as an
50 //offset from the beginning of the block. For efficiency reasons this
51 //is no longer the case.
52 //Many internal parts of this class still use this representation for parameters and so on,
53 //notably moveImage() and clearImage().
54 //This macro converts from an X,Y position into an image offset.
55 #ifndef loc
56 #define loc(X,Y) ((Y)*columns+(X))
57 #endif
58 
59 
64 
65 //#define REVERSE_WRAPPED_LINES // for wrapped line debug
66 
67 Screen::Screen(int l, int c)
68  : lines(l),
69  columns(c),
70  screenLines(new ImageLine[lines+1] ),
71  _scrolledLines(0),
72  _droppedLines(0),
73  hist(new HistoryScrollNone()),
74  cuX(0), cuY(0),
75  cu_re(0),
76  tmargin(0), bmargin(0),
77  tabstops(0),
78  sel_begin(0), sel_TL(0), sel_BR(0),
79  sel_busy(false),
80  columnmode(false),
81  ef_fg(CharacterColor()), ef_bg(CharacterColor()), ef_re(0),
82  sa_cuX(0), sa_cuY(0),
83  sa_cu_re(0),
84  lastPos(-1)
85 {
86  lineProperties.resize(lines+1);
87  for (int i=0;i<lines+1;i++)
89 
90  initTabStops();
92  reset();
93 }
94 
95 /*! Destructor
96 */
97 
99 {
100  delete[] screenLines;
101  delete[] tabstops;
102  delete hist;
103 }
104 
105 /* ------------------------------------------------------------------------- */
106 /* */
107 /* Normalized Screen Operations */
108 /* */
109 /* ------------------------------------------------------------------------- */
110 
111 // Cursor Setting --------------------------------------------------------------
112 
113 /*! @section Cursor
114 
115  The `cursor' is a location within the screen that is implicitely used in
116  many operations. The operations within this section allow to manipulate
117  the cursor explicitly and to obtain it's value.
118 
119  The position of the cursor is guarantied to be between (including) 0 and
120  `columns-1' and `lines-1'.
121 */
122 
123 /*!
124  Move the cursor up.
125 
126  The cursor will not be moved beyond the top margin.
127 */
128 
129 void Screen::cursorUp(int n)
130 //=CUU
131 {
132  if (n == 0) n = 1; // Default
133  int stop = cuY < tmargin ? 0 : tmargin;
134  cuX = qMin(columns-1,cuX); // nowrap!
135  cuY = qMax(stop,cuY-n);
136 }
137 
138 /*!
139  Move the cursor down.
140 
141  The cursor will not be moved beyond the bottom margin.
142 */
143 
145 //=CUD
146 {
147  if (n == 0) n = 1; // Default
148  int stop = cuY > bmargin ? lines-1 : bmargin;
149  cuX = qMin(columns-1,cuX); // nowrap!
150  cuY = qMin(stop,cuY+n);
151 }
152 
153 /*!
154  Move the cursor left.
155 
156  The cursor will not move beyond the first column.
157 */
158 
160 //=CUB
161 {
162  if (n == 0) n = 1; // Default
163  cuX = qMin(columns-1,cuX); // nowrap!
164  cuX = qMax(0,cuX-n);
165 }
166 
167 /*!
168  Move the cursor left.
169 
170  The cursor will not move beyond the rightmost column.
171 */
172 
174 //=CUF
175 {
176  if (n == 0) n = 1; // Default
177  cuX = qMin(columns-1,cuX+n);
178 }
179 
180 void Screen::setMargins(int top, int bot)
181 //=STBM
182 {
183  if (top == 0) top = 1; // Default
184  if (bot == 0) bot = lines; // Default
185  top = top - 1; // Adjust to internal lineno
186  bot = bot - 1; // Adjust to internal lineno
187  if ( !( 0 <= top && top < bot && bot < lines ) )
188  { qDebug()<<" setRegion("<<top<<","<<bot<<") : bad range.";
189  return; // Default error action: ignore
190  }
191  tmargin = top;
192  bmargin = bot;
193  cuX = 0;
194  cuY = getMode(MODE_Origin) ? top : 0;
195 
196 }
197 
198 int Screen::topMargin() const
199 {
200  return tmargin;
201 }
203 {
204  return bmargin;
205 }
206 
208 //=IND
209 {
210  if (cuY == bmargin)
211  {
212  scrollUp(1);
213  }
214  else if (cuY < lines-1)
215  cuY += 1;
216 }
217 
219 //=RI
220 {
221  if (cuY == tmargin)
222  scrollDown(tmargin,1);
223  else if (cuY > 0)
224  cuY -= 1;
225 }
226 
227 /*!
228  Move the cursor to the begin of the next line.
229 
230  If cursor is on bottom margin, the region between the
231  actual top and bottom margin is scrolled up.
232 */
233 
235 //=NEL
236 {
237  Return(); index();
238 }
239 
241 {
242  if (n == 0) n = 1; // Default
243  int p = qMax(0,qMin(cuX+n-1,columns-1));
244  clearImage(loc(cuX,cuY),loc(p,cuY),' ');
245 }
246 
248 {
249  Q_ASSERT( n >= 0 );
250 
251  // always delete at least one char
252  if (n == 0)
253  n = 1;
254 
255  // if cursor is beyond the end of the line there is nothing to do
256  if ( cuX >= screenLines[cuY].count() )
257  return;
258 
259  if ( cuX+n >= screenLines[cuY].count() )
260  n = screenLines[cuY].count() - 1 - cuX;
261 
262  Q_ASSERT( n >= 0 );
263  Q_ASSERT( cuX+n < screenLines[cuY].count() );
264 
265  screenLines[cuY].remove(cuX,n);
266 }
267 
269 {
270  if (n == 0) n = 1; // Default
271 
272  if ( screenLines[cuY].size() < cuX )
273  screenLines[cuY].resize(cuX);
274 
275  screenLines[cuY].insert(cuX,n,' ');
276 
277  if ( screenLines[cuY].count() > columns )
278  screenLines[cuY].resize(columns);
279 }
280 
282 {
283  if (n == 0) n = 1; // Default
284  scrollUp(cuY,n);
285 }
286 
287 /*! insert `n' lines at the cursor position.
288 
289  The cursor is not moved by the operation.
290 */
291 
293 {
294  if (n == 0) n = 1; // Default
295  scrollDown(cuY,n);
296 }
297 
298 // Mode Operations -----------------------------------------------------------
299 
300 /*! Set a specific mode. */
301 
302 void Screen::setMode(int m)
303 {
304  currParm.mode[m] = true;
305  switch(m)
306  {
307  case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home
308  }
309 }
310 
311 /*! Reset a specific mode. */
312 
313 void Screen::resetMode(int m)
314 {
315  currParm.mode[m] = false;
316  switch(m)
317  {
318  case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home
319  }
320 }
321 
322 /*! Save a specific mode. */
323 
324 void Screen::saveMode(int m)
325 {
326  saveParm.mode[m] = currParm.mode[m];
327 }
328 
329 /*! Restore a specific mode. */
330 
332 {
333  currParm.mode[m] = saveParm.mode[m];
334 }
335 
336 bool Screen::getMode(int m) const
337 {
338  return currParm.mode[m];
339 }
340 
342 {
343  sa_cuX = cuX;
344  sa_cuY = cuY;
345  sa_cu_re = cu_re;
346  sa_cu_fg = cu_fg;
347  sa_cu_bg = cu_bg;
348 }
349 
351 {
352  cuX = qMin(sa_cuX,columns-1);
353  cuY = qMin(sa_cuY,lines-1);
354  cu_re = sa_cu_re;
355  cu_fg = sa_cu_fg;
356  cu_bg = sa_cu_bg;
358 }
359 
360 /* ------------------------------------------------------------------------- */
361 /* */
362 /* Screen Operations */
363 /* */
364 /* ------------------------------------------------------------------------- */
365 
366 /*! Resize the screen image
367 
368  The topmost left position is maintained, while lower lines
369  or right hand side columns might be removed or filled with
370  spaces to fit the new size.
371 
372  The region setting is reset to the whole screen and the
373  tab positions reinitialized.
374 
375  If the new image is narrower than the old image then text on lines
376  which extends past the end of the new image is preserved so that it becomes
377  visible again if the screen is later resized to make it larger.
378 */
379 
380 void Screen::resizeImage(int new_lines, int new_columns)
381 {
382  if ((new_lines==lines) && (new_columns==columns)) return;
383 
384  if (cuY > new_lines-1)
385  { // attempt to preserve focus and lines
386  bmargin = lines-1; //FIXME: margin lost
387  for (int i = 0; i < cuY-(new_lines-1); i++)
388  {
389  addHistLine(); scrollUp(0,1);
390  }
391  }
392 
393  // create new screen lines and copy from old to new
394 
395  ImageLine* newScreenLines = new ImageLine[new_lines+1];
396  for (int i=0; i < qMin(lines-1,new_lines+1) ;i++)
397  newScreenLines[i]=screenLines[i];
398  for (int i=lines;(i > 0) && (i<new_lines+1);i++)
399  newScreenLines[i].resize( new_columns );
400 
401  lineProperties.resize(new_lines+1);
402  for (int i=lines;(i > 0) && (i<new_lines+1);i++)
404 
405  clearSelection();
406 
407  delete[] screenLines;
408  screenLines = newScreenLines;
409 
410  lines = new_lines;
411  columns = new_columns;
412  cuX = qMin(cuX,columns-1);
413  cuY = qMin(cuY,lines-1);
414 
415  // FIXME: try to keep values, evtl.
416  tmargin=0;
417  bmargin=lines-1;
418  initTabStops();
419  clearSelection();
420 }
421 
423 {
424  tmargin = 0;
425  bmargin = lines-1;
426 }
427 
428 
429 /*
430  Clarifying rendition here and in the display.
431 
432  currently, the display's color table is
433  0 1 2 .. 9 10 .. 17
434  dft_fg, dft_bg, dim 0..7, intensive 0..7
435 
436  cu_fg, cu_bg contain values 0..8;
437  - 0 = default color
438  - 1..8 = ansi specified color
439 
440  re_fg, re_bg contain values 0..17
441  due to the TerminalDisplay's color table
442 
443  rendition attributes are
444 
445  attr widget screen
446  -------------- ------ ------
447  RE_UNDERLINE XX XX affects foreground only
448  RE_BLINK XX XX affects foreground only
449  RE_BOLD XX XX affects foreground only
450  RE_REVERSE -- XX
451  RE_TRANSPARENT XX -- affects background only
452  RE_INTENSIVE XX -- affects foreground only
453 
454  Note that RE_BOLD is used in both widget
455  and screen rendition. Since xterm/vt102
456  is to poor to distinguish between bold
457  (which is a font attribute) and intensive
458  (which is a color attribute), we translate
459  this and RE_BOLD in falls eventually appart
460  into RE_BOLD and RE_INTENSIVE.
461 */
462 
464 {
467 
468  p.foregroundColor = b;
469  p.backgroundColor = f; //p->r &= ~RE_TRANSPARENT;
470 }
471 
473 // calculate rendition
474 {
475  //copy "current rendition" straight into "effective rendition", which is then later copied directly
476  //into the image[] array which holds the characters and their appearance properties.
477  //- The old version below filtered out all attributes other than underline and blink at this stage,
478  //so that they would not be copied into the image[] array and hence would not be visible by TerminalDisplay
479  //which actually paints the screen using the information from the image[] array.
480  //I don't know why it did this, but I'm fairly sure it was the wrong thing to do. The net result
481  //was that bold text wasn't printed in bold by Konsole.
482  ef_re = cu_re;
483 
484  //OLD VERSION:
485  //ef_re = cu_re & (RE_UNDERLINE | RE_BLINK);
486 
487  if (cu_re & RE_REVERSE)
488  {
489  ef_fg = cu_bg;
490  ef_bg = cu_fg;
491  }
492  else
493  {
494  ef_fg = cu_fg;
495  ef_bg = cu_bg;
496  }
497 
498  if (cu_re & RE_BOLD)
500 }
501 
502 /*!
503  returns the image.
504 
505  Get the size of the image by @sa getLines and @sa getColumns.
506 
507  NOTE that the image returned by this function must later be
508  freed.
509 
510 */
511 
512 void Screen::copyFromHistory(Character* dest, int startLine, int count) const
513 {
514  Q_ASSERT( startLine >= 0 && count > 0 && startLine + count <= hist->getLines() );
515 
516  for (int line = startLine; line < startLine + count; line++)
517  {
518  const int length = qMin(columns,hist->getLineLen(line));
519  const int destLineOffset = (line-startLine)*columns;
520 
521  hist->getCells(line,0,length,dest + destLineOffset);
522 
523  for (int column = length; column < columns; column++)
524  dest[destLineOffset+column] = defaultChar;
525 
526  // invert selected text
527  if (sel_begin !=-1)
528  {
529  for (int column = 0; column < columns; column++)
530  {
531  if (isSelected(column,line))
532  {
533  reverseRendition(dest[destLineOffset + column]);
534  }
535  }
536  }
537  }
538 }
539 
540 void Screen::copyFromScreen(Character* dest , int startLine , int count) const
541 {
542  Q_ASSERT( startLine >= 0 && count > 0 && startLine + count <= lines );
543 
544  for (int line = startLine; line < (startLine+count) ; line++)
545  {
546  int srcLineStartIndex = line*columns;
547  int destLineStartIndex = (line-startLine)*columns;
548 
549  for (int column = 0; column < columns; column++)
550  {
551  int srcIndex = srcLineStartIndex + column;
552  int destIndex = destLineStartIndex + column;
553 
554  dest[destIndex] = screenLines[srcIndex/columns].value(srcIndex%columns,defaultChar);
555 
556  // invert selected text
557  if (sel_begin != -1 && isSelected(column,line + hist->getLines()))
558  reverseRendition(dest[destIndex]);
559  }
560 
561  }
562 }
563 
564 void Screen::getImage( Character* dest, int size, int startLine, int endLine ) const
565 {
566  Q_ASSERT( startLine >= 0 );
567  Q_ASSERT( endLine >= startLine && endLine < hist->getLines() + lines );
568 
569  const int mergedLines = endLine - startLine + 1;
570 
571  Q_ASSERT( size >= mergedLines * columns );
572  Q_UNUSED( size );
573 
574  const int linesInHistoryBuffer = qBound(0,hist->getLines()-startLine,mergedLines);
575  const int linesInScreenBuffer = mergedLines - linesInHistoryBuffer;
576 
577  // copy lines from history buffer
578  if (linesInHistoryBuffer > 0) {
579  copyFromHistory(dest,startLine,linesInHistoryBuffer);
580  }
581 
582  // copy lines from screen buffer
583  if (linesInScreenBuffer > 0) {
584  copyFromScreen(dest + linesInHistoryBuffer*columns,
585  startLine + linesInHistoryBuffer - hist->getLines(),
586  linesInScreenBuffer);
587  }
588 
589  // invert display when in screen mode
590  if (getMode(MODE_Screen))
591  {
592  for (int i = 0; i < mergedLines*columns; i++)
593  reverseRendition(dest[i]); // for reverse display
594  }
595 
596  // mark the character at the current cursor position
597  int cursorIndex = loc(cuX, cuY + linesInHistoryBuffer);
598  if(getMode(MODE_Cursor) && cursorIndex < columns*mergedLines)
599  dest[cursorIndex].rendition |= RE_CURSOR;
600 }
601 
602 QVector<LineProperty> Screen::getLineProperties( int startLine , int endLine ) const
603 {
604  Q_ASSERT( startLine >= 0 );
605  Q_ASSERT( endLine >= startLine && endLine < hist->getLines() + lines );
606 
607  const int mergedLines = endLine-startLine+1;
608  const int linesInHistory = qBound(0,hist->getLines()-startLine,mergedLines);
609  const int linesInScreen = mergedLines - linesInHistory;
610 
611  QVector<LineProperty> result(mergedLines);
612  int index = 0;
613 
614  // copy properties for lines in history
615  for (int line = startLine; line < startLine + linesInHistory; line++)
616  {
617  //TODO Support for line properties other than wrapped lines
618  if (hist->isWrappedLine(line))
619  {
620  result[index] = (LineProperty)(result[index] | LINE_WRAPPED);
621  }
622  index++;
623  }
624 
625  // copy properties for lines in screen buffer
626  const int firstScreenLine = startLine + linesInHistory - hist->getLines();
627  for (int line = firstScreenLine; line < firstScreenLine+linesInScreen; line++)
628  {
629  result[index]=lineProperties[line];
630  index++;
631  }
632 
633  return result;
634 }
635 
636 /*!
637 */
638 
639 void Screen::reset(bool clearScreen)
640 {
641  setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin
642  resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1]
643  resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke
644  setMode(MODE_Cursor); // cursor visible
645  resetMode(MODE_Screen); // screen not inverse
647 
648  tmargin=0;
649  bmargin=lines-1;
650 
652  saveCursor();
653 
654  if ( clearScreen )
655  clear();
656 }
657 
658 /*! Clear the entire screen and home the cursor.
659 */
660 
662 {
664  home();
665 }
666 
668 {
669  cuX = qMin(columns-1,cuX); // nowrap!
670  cuX = qMax(0,cuX-1);
671  // if (BS_CLEARS) image[loc(cuX,cuY)].character = ' ';
672 
673  if (screenLines[cuY].size() < cuX+1)
674  screenLines[cuY].resize(cuX+1);
675 
676  if (BS_CLEARS) screenLines[cuY][cuX].character = ' ';
677 }
678 
679 void Screen::Tabulate(int n)
680 {
681  // note that TAB is a format effector (does not write ' ');
682  if (n == 0) n = 1;
683  while((n > 0) && (cuX < columns-1))
684  {
685  cursorRight(1); while((cuX < columns-1) && !tabstops[cuX]) cursorRight(1);
686  n--;
687  }
688 }
689 
691 {
692  // note that TAB is a format effector (does not write ' ');
693  if (n == 0) n = 1;
694  while((n > 0) && (cuX > 0))
695  {
696  cursorLeft(1); while((cuX > 0) && !tabstops[cuX]) cursorLeft(1);
697  n--;
698  }
699 }
700 
702 {
703  for (int i = 0; i < columns; i++) tabstops[i] = false;
704 }
705 
706 void Screen::changeTabStop(bool set)
707 {
708  if (cuX >= columns) return;
709  tabstops[cuX] = set;
710 }
711 
713 {
714  delete[] tabstops;
715  tabstops = new bool[columns];
716 
717  // Arrg! The 1st tabstop has to be one longer than the other.
718  // i.e. the kids start counting from 0 instead of 1.
719  // Other programs might behave correctly. Be aware.
720  for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0);
721 }
722 
723 /*!
724  This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine)
725  depending on the NewLine Mode (LNM). This mode also
726  affects the key sequence returned for newline ([CR]LF).
727 */
728 
730 {
731  if (getMode(MODE_NewLine)) Return();
732  index();
733 }
734 
735 /*! put `c' literally onto the screen at the current cursor position.
736 
737  VT100 uses the convention to produce an automatic newline (am)
738  with the *first* character that would fall onto the next line (xenl).
739 */
740 
741 void Screen::checkSelection(int from, int to)
742 {
743  if (sel_begin == -1) return;
744  int scr_TL = loc(0, hist->getLines());
745  //Clear entire selection if it overlaps region [from, to]
746  if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) )
747  {
748  clearSelection();
749  }
750 }
751 
752 void Screen::ShowCharacter(unsigned short c)
753 {
754  // Note that VT100 does wrapping BEFORE putting the character.
755  // This has impact on the assumption of valid cursor positions.
756  // We indicate the fact that a newline has to be triggered by
757  // putting the cursor one right to the last column of the screen.
758 
759  int w = konsole_wcwidth(c);
760 
761  if (w <= 0)
762  return;
763 
764  if (cuX+w > columns) {
765  if (getMode(MODE_Wrap)) {
767  NextLine();
768  }
769  else
770  cuX = columns-w;
771  }
772 
773  // ensure current line vector has enough elements
774  int size = screenLines[cuY].size();
775  if (size == 0 && cuY > 0)
776  {
777  screenLines[cuY].resize( qMax(screenLines[cuY-1].size() , cuX+w) );
778  }
779  else
780  {
781  if (size < cuX+w)
782  {
783  screenLines[cuY].resize(cuX+w);
784  }
785  }
786 
788 
789  lastPos = loc(cuX,cuY);
790 
791  // clear selection on text input
792  clearSelection ();
793 
794  Character& currentChar = screenLines[cuY][cuX];
795 
796  currentChar.character = c;
797  currentChar.foregroundColor = ef_fg;
798  currentChar.backgroundColor = ef_bg;
799  currentChar.rendition = ef_re;
800 
801  int i = 0;
802  int newCursorX = cuX + w--;
803  while(w)
804  {
805  i++;
806 
807  if ( screenLines[cuY].size() < cuX + i + 1 )
808  screenLines[cuY].resize(cuX+i+1);
809 
810  Character& ch = screenLines[cuY][cuX + i];
811  ch.character = 0;
812  ch.foregroundColor = ef_fg;
813  ch.backgroundColor = ef_bg;
814  ch.rendition = ef_re;
815 
816  w--;
817  }
818  cuX = newCursorX;
819 }
820 
821 void Screen::compose(const QString& /*compose*/)
822 {
823  Q_ASSERT( 0 /*Not implemented yet*/ );
824 
825 /* if (lastPos == -1)
826  return;
827 
828  QChar c(image[lastPos].character);
829  compose.prepend(c);
830  //compose.compose(); ### FIXME!
831  image[lastPos].character = compose[0].unicode();*/
832 }
833 
835 {
836  return _scrolledLines;
837 }
839 {
840  return _droppedLines;
841 }
843 {
844  _droppedLines = 0;
845 }
847 {
848  //kDebug() << "scrolled lines reset";
849 
850  _scrolledLines = 0;
851 }
852 
853 // Region commands -------------------------------------------------------------
854 
855 void Screen::scrollUp(int n)
856 {
857  if (n == 0) n = 1; // Default
858  if (tmargin == 0) addHistLine(); // hist.history
859  scrollUp(tmargin, n);
860 }
861 
862 /*! scroll up `n' lines within current region.
863  The `n' new lines are cleared.
864  @sa setRegion @sa scrollDown
865 */
866 
868 {
869  return _lastScrolledRegion;
870 }
871 
872 void Screen::scrollUp(int from, int n)
873 {
874  if (n <= 0 || from + n > bmargin) return;
875 
876  _scrolledLines -= n;
877  _lastScrolledRegion = QRect(0,tmargin,columns-1,(bmargin-tmargin));
878 
879  //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds.
880  moveImage(loc(0,from),loc(0,from+n),loc(columns-1,bmargin));
881  clearImage(loc(0,bmargin-n+1),loc(columns-1,bmargin),' ');
882 }
883 
885 {
886  if (n == 0) n = 1; // Default
887  scrollDown(tmargin, n);
888 }
889 
890 /*! scroll down `n' lines within current region.
891  The `n' new lines are cleared.
892  @sa setRegion @sa scrollUp
893 */
894 
895 void Screen::scrollDown(int from, int n)
896 {
897 
898  //kDebug() << "Screen::scrollDown( from: " << from << " , n: " << n << ")";
899 
900  _scrolledLines += n;
901 
902 //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds.
903  if (n <= 0) return;
904  if (from > bmargin) return;
905  if (from + n > bmargin) n = bmargin - from;
906  moveImage(loc(0,from+n),loc(0,from),loc(columns-1,bmargin-n));
907  clearImage(loc(0,from),loc(columns-1,from+n-1),' ');
908 }
909 
910 void Screen::setCursorYX(int y, int x)
911 {
912  setCursorY(y); setCursorX(x);
913 }
914 
916 {
917  if (x == 0) x = 1; // Default
918  x -= 1; // Adjust
919  cuX = qMax(0,qMin(columns-1, x));
920 }
921 
923 {
924  if (y == 0) y = 1; // Default
925  y -= 1; // Adjust
926  cuY = qMax(0,qMin(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) ));
927 }
928 
930 {
931  cuX = 0;
932  cuY = 0;
933 }
934 
936 {
937  cuX = 0;
938 }
939 
941 {
942  return cuX;
943 }
944 
946 {
947  return cuY;
948 }
949 
950 // Erasing ---------------------------------------------------------------------
951 
952 /*! @section Erasing
953 
954  This group of operations erase parts of the screen contents by filling
955  it with spaces colored due to the current rendition settings.
956 
957  Althought the cursor position is involved in most of these operations,
958  it is never modified by them.
959 */
960 
961 /*! fill screen between (including) `loca' (start) and `loce' (end) with spaces.
962 
963  This is an internal helper functions. The parameter types are internal
964  addresses of within the screen image and make use of the way how the
965  screen matrix is mapped to the image vector.
966 */
967 
968 void Screen::clearImage(int loca, int loce, char c)
969 {
970  int scr_TL=loc(0,hist->getLines());
971  //FIXME: check positions
972 
973  //Clear entire selection if it overlaps region to be moved...
974  if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) )
975  {
976  clearSelection();
977  }
978 
979  int topLine = loca/columns;
980  int bottomLine = loce/columns;
981 
983 
984  //if the character being used to clear the area is the same as the
985  //default character, the affected lines can simply be shrunk.
986  bool isDefaultCh = (clearCh == Character());
987 
988  for (int y=topLine;y<=bottomLine;y++)
989  {
990  lineProperties[y] = 0;
991 
992  int endCol = ( y == bottomLine) ? loce%columns : columns-1;
993  int startCol = ( y == topLine ) ? loca%columns : 0;
994 
995  QVector<Character>& line = screenLines[y];
996 
997  if ( isDefaultCh && endCol == columns-1 )
998  {
999  line.resize(startCol);
1000  }
1001  else
1002  {
1003  if (line.size() < endCol + 1)
1004  line.resize(endCol+1);
1005 
1006  Character* data = line.data();
1007  for (int i=startCol;i<=endCol;i++)
1008  data[i]=clearCh;
1009  }
1010  }
1011 }
1012 
1013 /*! move image between (including) `sourceBegin' and `sourceEnd' to 'dest'.
1014 
1015  The 'dest', 'sourceBegin' and 'sourceEnd' parameters can be generated using
1016  the loc(column,line) macro.
1017 
1018 NOTE: moveImage() can only move whole lines.
1019 
1020  This is an internal helper functions. The parameter types are internal
1021  addresses of within the screen image and make use of the way how the
1022  screen matrix is mapped to the image vector.
1023 */
1024 
1025 void Screen::moveImage(int dest, int sourceBegin, int sourceEnd)
1026 {
1027  //kDebug() << "moving image from (" << (sourceBegin/columns)
1028  // << "," << (sourceEnd/columns) << ") to " <<
1029  // (dest/columns);
1030 
1031  Q_ASSERT( sourceBegin <= sourceEnd );
1032 
1033  int lines=(sourceEnd-sourceBegin)/columns;
1034 
1035  //move screen image and line properties:
1036  //the source and destination areas of the image may overlap,
1037  //so it matters that we do the copy in the right order -
1038  //forwards if dest < sourceBegin or backwards otherwise.
1039  //(search the web for 'memmove implementation' for details)
1040  if (dest < sourceBegin)
1041  {
1042  for (int i=0;i<=lines;i++)
1043  {
1044  screenLines[ (dest/columns)+i ] = screenLines[ (sourceBegin/columns)+i ];
1045  lineProperties[(dest/columns)+i]=lineProperties[(sourceBegin/columns)+i];
1046  }
1047  }
1048  else
1049  {
1050  for (int i=lines;i>=0;i--)
1051  {
1052  screenLines[ (dest/columns)+i ] = screenLines[ (sourceBegin/columns)+i ];
1053  lineProperties[(dest/columns)+i]=lineProperties[(sourceBegin/columns)+i];
1054  }
1055  }
1056 
1057  if (lastPos != -1)
1058  {
1059  int diff = dest - sourceBegin; // Scroll by this amount
1060  lastPos += diff;
1061  if ((lastPos < 0) || (lastPos >= (lines*columns)))
1062  lastPos = -1;
1063  }
1064 
1065  // Adjust selection to follow scroll.
1066  if (sel_begin != -1)
1067  {
1068  bool beginIsTL = (sel_begin == sel_TL);
1069  int diff = dest - sourceBegin; // Scroll by this amount
1070  int scr_TL=loc(0,hist->getLines());
1071  int srca = sourceBegin+scr_TL; // Translate index from screen to global
1072  int srce = sourceEnd+scr_TL; // Translate index from screen to global
1073  int desta = srca+diff;
1074  int deste = srce+diff;
1075 
1076  if ((sel_TL >= srca) && (sel_TL <= srce))
1077  sel_TL += diff;
1078  else if ((sel_TL >= desta) && (sel_TL <= deste))
1079  sel_BR = -1; // Clear selection (see below)
1080 
1081  if ((sel_BR >= srca) && (sel_BR <= srce))
1082  sel_BR += diff;
1083  else if ((sel_BR >= desta) && (sel_BR <= deste))
1084  sel_BR = -1; // Clear selection (see below)
1085 
1086  if (sel_BR < 0)
1087  {
1088  clearSelection();
1089  }
1090  else
1091  {
1092  if (sel_TL < 0)
1093  sel_TL = 0;
1094  }
1095 
1096  if (beginIsTL)
1097  sel_begin = sel_TL;
1098  else
1099  sel_begin = sel_BR;
1100  }
1101 }
1102 
1104 {
1105  clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' ');
1106 }
1107 
1109 {
1110  clearImage(loc(0,0),loc(cuX,cuY),' ');
1111 }
1112 
1114 {
1115  // Add entire screen to history
1116  for (int i = 0; i < (lines-1); i++)
1117  {
1118  addHistLine(); scrollUp(0,1);
1119  }
1120 
1121  clearImage(loc(0,0),loc(columns-1,lines-1),' ');
1122 }
1123 
1124 /*! fill screen with 'E'
1125  This is to aid screen alignment
1126 */
1127 
1129 {
1130  clearImage(loc(0,0),loc(columns-1,lines-1),'E');
1131 }
1132 
1134 {
1135  clearImage(loc(cuX,cuY),loc(columns-1,cuY),' ');
1136 }
1137 
1139 {
1140  clearImage(loc(0,cuY),loc(cuX,cuY),' ');
1141 }
1142 
1144 {
1145  clearImage(loc(0,cuY),loc(columns-1,cuY),' ');
1146 }
1147 
1149 {
1150  cu_re |= re;
1152 }
1153 
1155 {
1156  cu_re &= ~re;
1158 }
1159 
1161 {
1166 }
1167 
1168 void Screen::setForeColor(int space, int color)
1169 {
1170  cu_fg = CharacterColor(space, color);
1171 
1172  if ( cu_fg.isValid() )
1174  else
1176 }
1177 
1178 void Screen::setBackColor(int space, int color)
1179 {
1180  cu_bg = CharacterColor(space, color);
1181 
1182  if ( cu_bg.isValid() )
1184  else
1186 }
1187 
1188 /* ------------------------------------------------------------------------- */
1189 /* */
1190 /* Marking & Selection */
1191 /* */
1192 /* ------------------------------------------------------------------------- */
1193 
1195 {
1196  sel_BR = -1;
1197  sel_TL = -1;
1198  sel_begin = -1;
1199 }
1200 
1201 void Screen::getSelectionStart(int& column , int& line)
1202 {
1203  if ( sel_TL != -1 )
1204  {
1205  column = sel_TL % columns;
1206  line = sel_TL / columns;
1207  }
1208  else
1209  {
1210  column = cuX + getHistLines();
1211  line = cuY + getHistLines();
1212  }
1213 }
1214 void Screen::getSelectionEnd(int& column , int& line)
1215 {
1216  if ( sel_BR != -1 )
1217  {
1218  column = sel_BR % columns;
1219  line = sel_BR / columns;
1220  }
1221  else
1222  {
1223  column = cuX + getHistLines();
1224  line = cuY + getHistLines();
1225  }
1226 }
1227 void Screen::setSelectionStart(/*const ScreenCursor& viewCursor ,*/ const int x, const int y, const bool mode)
1228 {
1229 // kDebug(1211) << "setSelBeginXY(" << x << "," << y << ")";
1230  sel_begin = loc(x,y); //+histCursor) ;
1231 
1232  /* FIXME, HACK to correct for x too far to the right... */
1233  if (x == columns) sel_begin--;
1234 
1235  sel_BR = sel_begin;
1236  sel_TL = sel_begin;
1237  columnmode = mode;
1238 }
1239 
1240 void Screen::setSelectionEnd( const int x, const int y)
1241 {
1242 // kDebug(1211) << "setSelExtentXY(" << x << "," << y << ")";
1243  if (sel_begin == -1) return;
1244  int l = loc(x,y); // + histCursor);
1245 
1246  if (l < sel_begin)
1247  {
1248  sel_TL = l;
1249  sel_BR = sel_begin;
1250  }
1251  else
1252  {
1253  /* FIXME, HACK to correct for x too far to the right... */
1254  if (x == columns) l--;
1255 
1256  sel_TL = sel_begin;
1257  sel_BR = l;
1258  }
1259 }
1260 
1261 bool Screen::isSelected( const int x,const int y) const
1262 {
1263  if (columnmode) {
1264  int sel_Left,sel_Right;
1265  if ( sel_TL % columns < sel_BR % columns ) {
1266  sel_Left = sel_TL; sel_Right = sel_BR;
1267  } else {
1268  sel_Left = sel_BR; sel_Right = sel_TL;
1269  }
1270  return ( x >= sel_Left % columns ) && ( x <= sel_Right % columns ) &&
1271  ( y >= sel_TL / columns ) && ( y <= sel_BR / columns );
1272  //( y+histCursor >= sel_TL / columns ) && ( y+histCursor <= sel_BR / columns );
1273  }
1274  else {
1275  //int pos = loc(x,y+histCursor);
1276  int pos = loc(x,y);
1277  return ( pos >= sel_TL && pos <= sel_BR );
1278  }
1279 }
1280 
1281 QString Screen::selectedText(bool preserveLineBreaks)
1282 {
1283  QString result;
1284  QTextStream stream(&result, QIODevice::ReadWrite);
1285 
1286  PlainTextDecoder decoder;
1287  decoder.begin(&stream);
1288  writeSelectionToStream(&decoder , preserveLineBreaks);
1289  decoder.end();
1290 
1291  return result;
1292 }
1293 
1295 {
1296  return ( sel_TL >= 0 && sel_BR >= 0 );
1297 }
1298 
1300  bool preserveLineBreaks)
1301 {
1302  // do nothing if selection is invalid
1303  if ( !isSelectionValid() )
1304  return;
1305 
1306  int top = sel_TL / columns;
1307  int left = sel_TL % columns;
1308 
1309  int bottom = sel_BR / columns;
1310  int right = sel_BR % columns;
1311 
1312  Q_ASSERT( top >= 0 && left >= 0 && bottom >= 0 && right >= 0 );
1313 
1314  //kDebug() << "sel_TL = " << sel_TL;
1315  //kDebug() << "columns = " << columns;
1316 
1317  for (int y=top;y<=bottom;y++)
1318  {
1319  int start = 0;
1320  if ( y == top || columnmode ) start = left;
1321 
1322  int count = -1;
1323  if ( y == bottom || columnmode ) count = right - start + 1;
1324 
1325  const bool appendNewLine = ( y != bottom );
1326  copyLineToStream( y,
1327  start,
1328  count,
1329  decoder,
1330  appendNewLine,
1331  preserveLineBreaks );
1332  }
1333 }
1334 
1335 
1337  int start,
1338  int count,
1339  TerminalCharacterDecoder* decoder,
1340  bool appendNewLine,
1341  bool preserveLineBreaks)
1342 {
1343  //buffer to hold characters for decoding
1344  //the buffer is static to avoid initialising every
1345  //element on each call to copyLineToStream
1346  //(which is unnecessary since all elements will be overwritten anyway)
1347  static const int MAX_CHARS = 1024;
1348  static Character characterBuffer[MAX_CHARS];
1349 
1350  assert( count < MAX_CHARS );
1351 
1352  LineProperty currentLineProperties = 0;
1353 
1354  //determine if the line is in the history buffer or the screen image
1355  if (line < hist->getLines())
1356  {
1357  const int lineLength = hist->getLineLen(line);
1358 
1359  // ensure that start position is before end of line
1360  start = qMin(start,qMax(0,lineLength-1));
1361 
1362  //retrieve line from history buffer
1363  if (count == -1)
1364  {
1365  count = lineLength-start;
1366  }
1367  else
1368  {
1369  count = qMin(start+count,lineLength)-start;
1370  }
1371 
1372  // safety checks
1373  assert( start >= 0 );
1374  assert( count >= 0 );
1375  assert( (start+count) <= hist->getLineLen(line) );
1376 
1377  hist->getCells(line,start,count,characterBuffer);
1378 
1379  if ( hist->isWrappedLine(line) )
1380  currentLineProperties |= LINE_WRAPPED;
1381  }
1382  else
1383  {
1384  if ( count == -1 )
1385  count = columns - start;
1386 
1387  assert( count >= 0 );
1388 
1389  const int screenLine = line-hist->getLines();
1390 
1391  Character* data = screenLines[screenLine].data();
1392  int length = screenLines[screenLine].count();
1393 
1394  //retrieve line from screen image
1395  for (int i=start;i < qMin(start+count,length);i++)
1396  {
1397  characterBuffer[i-start] = data[i];
1398  }
1399 
1400  // count cannot be any greater than length
1401  count = qBound(0,count,length-start);
1402 
1403  Q_ASSERT( screenLine < lineProperties.count() );
1404  currentLineProperties |= lineProperties[screenLine];
1405  }
1406 
1407  //do not decode trailing whitespace characters
1408  for (int i=count-1 ; i >= 0; i--)
1409  if (QChar(characterBuffer[i].character).isSpace())
1410  count--;
1411  else
1412  break;
1413 
1414  // add new line character at end
1415  const bool omitLineBreak = (currentLineProperties & LINE_WRAPPED) ||
1416  !preserveLineBreaks;
1417 
1418  if ( !omitLineBreak && appendNewLine && (count+1 < MAX_CHARS) )
1419  {
1420  characterBuffer[count] = '\n';
1421  count++;
1422  }
1423 
1424  //decode line and write to text stream
1425  decoder->decodeLine( (Character*) characterBuffer ,
1426  count, currentLineProperties );
1427 }
1428 
1429 // Method below has been removed because of its reliance on 'histCursor'
1430 // and I want to restrict the methods which have knowledge of the scroll position
1431 // to just those which deal with selection and supplying final screen images.
1432 //
1433 /*void Screen::writeToStream(QTextStream* stream , TerminalCharacterDecoder* decoder) {
1434  sel_begin = 0;
1435  sel_BR = sel_begin;
1436  sel_TL = sel_begin;
1437  setSelectionEnd(columns-1,lines-1+hist->getLines()-histCursor);
1438 
1439  writeSelectionToStream(stream,decoder);
1440 
1441  clearSelection();
1442 }*/
1443 
1444 void Screen::writeToStream(TerminalCharacterDecoder* decoder, int from, int to)
1445 {
1446  sel_begin = loc(0,from);
1447  sel_TL = sel_begin;
1448  sel_BR = loc(columns-1,to);
1449  writeSelectionToStream(decoder);
1450  clearSelection();
1451 }
1452 
1453 QString Screen::getHistoryLine(int no)
1454 {
1455  sel_begin = loc(0,no);
1456  sel_TL = sel_begin;
1457  sel_BR = loc(columns-1,no);
1458  return selectedText(false);
1459 }
1460 
1462 {
1463  // add line to history buffer
1464  // we have to take care about scrolling, too...
1465 
1466  if (hasScroll())
1467  {
1468  int oldHistLines = hist->getLines();
1469 
1472 
1473  int newHistLines = hist->getLines();
1474 
1475  bool beginIsTL = (sel_begin == sel_TL);
1476 
1477  // If the history is full, increment the count
1478  // of dropped lines
1479  if ( newHistLines == oldHistLines )
1480  _droppedLines++;
1481 
1482  // Adjust selection for the new point of reference
1483  if (newHistLines > oldHistLines)
1484  {
1485  if (sel_begin != -1)
1486  {
1487  sel_TL += columns;
1488  sel_BR += columns;
1489  }
1490  }
1491 
1492  if (sel_begin != -1)
1493  {
1494  // Scroll selection in history up
1495  int top_BR = loc(0, 1+newHistLines);
1496 
1497  if (sel_TL < top_BR)
1498  sel_TL -= columns;
1499 
1500  if (sel_BR < top_BR)
1501  sel_BR -= columns;
1502 
1503  if (sel_BR < 0)
1504  {
1505  clearSelection();
1506  }
1507  else
1508  {
1509  if (sel_TL < 0)
1510  sel_TL = 0;
1511  }
1512 
1513  if (beginIsTL)
1514  sel_begin = sel_TL;
1515  else
1516  sel_begin = sel_BR;
1517  }
1518  }
1519 
1520 }
1521 
1523 {
1524  return hist->getLines();
1525 }
1526 
1527 void Screen::setScroll(const HistoryType& t , bool copyPreviousScroll)
1528 {
1529  clearSelection();
1530 
1531  if ( copyPreviousScroll )
1532  hist = t.scroll(hist);
1533  else
1534  {
1535  HistoryScroll* oldScroll = hist;
1536  hist = t.scroll(0);
1537  delete oldScroll;
1538  }
1539 }
1540 
1542 {
1543  return hist->hasScroll();
1544 }
1545 
1547 {
1548  return hist->getType();
1549 }
1550 
1552 {
1553  if ( enable )
1554  {
1555  lineProperties[cuY] = (LineProperty)(lineProperties[cuY] | property);
1556  }
1557  else
1558  {
1559  lineProperties[cuY] = (LineProperty)(lineProperties[cuY] & ~property);
1560  }
1561 }
1563 {
1564  for (int i=0;i<count;i++)
1565  dest[i] = defaultChar;
1566 }
void changeTabStop(bool set)
Sets or removes a tab stop at the cursor's current column.
Definition: Screen.cpp:706
void clearToEndOfLine()
Clears from the current cursor position to the end of the line.
Definition: Screen.cpp:1133
void setForeColor(int space, int color)
Sets the cursor's foreground color.
Definition: Screen.cpp:1168
void setCursorY(int y)
Position the cursor on line y.
Definition: Screen.cpp:922
void clearSelection()
Clears the current selection.
Definition: Screen.cpp:1194
bool isValid()
Returns true if this character color entry is valid.
void setBackColor(int space, int color)
Sets the cursor's background color.
Definition: Screen.cpp:1178
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...
Definition: Screen.cpp:846
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.
Definition: Screen.cpp:1527
void reset(bool clearScreen=true)
Resets the state of the screen.
Definition: Screen.cpp:639
QRect _lastScrolledRegion
Definition: Screen.h:592
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:834
ScreenParm currParm
Definition: Screen.h:615
int lines
Definition: Screen.h:585
void setDefaultMargins()
Resets the scrolling margins back to the top and bottom lines of the screen.
Definition: Screen.cpp:422
void copyFromScreen(Character *dest, int startLine, int count) const
Definition: Screen.cpp:540
static Character defaultChar
Definition: Screen.h:652
void compose(const QString &compose)
Definition: Screen.cpp:821
HistoryScroll * hist
Definition: Screen.h:599
ImageLine * screenLines
Definition: Screen.h:589
virtual int getLines()=0
#define DEFAULT_FORE_COLOR
CharacterColor cu_bg
Definition: Screen.h:607
#define DEFAULT_RENDITION
Definition: Character.h:41
void Tabulate(int n=1)
Moves the cursor n tab-stops to the right.
Definition: Screen.cpp:679
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:55
int getCursorY() const
Returns the line which the cursor is positioned on.
Definition: Screen.cpp:945
void setCursorYX(int y, int x)
Position the cursor at line y, column x.
Definition: Screen.cpp:910
void eraseChars(int n)
Erase n characters beginning from the current cursor position.
Definition: Screen.cpp:240
virtual bool hasScroll()
Definition: History.cpp:192
int sel_begin
Definition: Screen.h:622
#define RE_REVERSE
Definition: Character.h:45
int getLines()
Return the number of lines.
Definition: Screen.h:377
void checkSelection(int from, int to)
TODO Document me.
Definition: Screen.cpp:741
void cursorRight(int n)
Move the cursor to the right by n columns.
Definition: Screen.cpp:173
int sa_cuX
Definition: Screen.h:638
QVarLengthArray< LineProperty, 64 > lineProperties
Definition: Screen.h:596
void helpAlign()
Fills the entire screen with the letter 'E'.
Definition: Screen.cpp:1128
#define COLOR_SPACE_DEFAULT
int cuX
Definition: Screen.h:602
CharacterColor sa_cu_fg
Definition: Screen.h:643
void clear()
TODO Document me.
Definition: Screen.cpp:661
Describes the color of a single character in the terminal.
void saveMode(int mode)
Saves the state of the specified screen mode.
Definition: Screen.cpp:324
int bmargin
Definition: Screen.h:612
void clearToEndOfScreen()
Clear the area of the screen from the current cursor position to the end of the screen.
Definition: Screen.cpp:1103
void resetMode(int mode)
Resets (clears) the specified screen mode.
Definition: Screen.cpp:313
void backTabulate(int n)
Moves the cursor n tab-stops to the left.
Definition: Screen.cpp:690
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...
Definition: Screen.cpp:667
quint8 rendition
A combination of RENDITION flags which specify options for drawing the character. ...
Definition: Character.h:87
#define MODE_Origin
Definition: Screen.h:37
int konsole_wcwidth(quint16 ucs)
bool * tabstops
Definition: Screen.h:619
#define MODE_Insert
Definition: Screen.h:39
void Return()
Moves the cursor to the beginning of the current line.
Definition: Screen.cpp:935
QVector< LineProperty > getLineProperties(int startLine, int endLine) const
Returns the additional attributes associated with lines in the image.
Definition: Screen.cpp:602
static int left
Definition: randmtzig.c:189
void clearImage(int loca, int loce, char c)
Definition: Screen.cpp:968
void setRendition(int rendition)
Enables the given rendition flag.
Definition: Screen.cpp:1148
void setMargins(int topLine, int bottomLine)
Sets the margins for scrolling the screen.
Definition: Screen.cpp:180
int bottomMargin() const
Returns the bottom line of the scrolling region.
Definition: Screen.cpp:202
void NewLine()
Moves the cursor down one line, if the MODE_NewLine mode flag is enabled then the cursor is returned ...
Definition: Screen.cpp:729
CharacterColor ef_bg
Definition: Screen.h:630
bool getMode(int mode) const
Returns whether the specified screen mode is enabled or not .
Definition: Screen.cpp:336
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:380
void clearEntireScreen()
Clear the whole screen, moving the current screen contents into the history first.
Definition: Screen.cpp:1113
int sel_TL
Definition: Screen.h:623
unsigned char LineProperty
Definition: Character.h:34
#define MODE_Screen
Definition: Screen.h:40
void getSelectionStart(int &column, int &line)
Retrieves the start of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1201
void clearToBeginOfScreen()
Clear the area of the screen from the current cursor position to the start of the screen...
Definition: Screen.cpp:1108
void initTabStops()
Definition: Screen.cpp:712
virtual HistoryScroll * scroll(HistoryScroll *) const =0
int mode[6]
Definition: Screen.h:47
void moveImage(int dest, int sourceBegin, int sourceEnd)
Definition: Screen.cpp:1025
CharacterColor sa_cu_bg
Definition: Screen.h:644
Screen(int lines, int columns)
Construct a new screen image of size lines by columns.
Definition: Screen.cpp:67
#define MODE_Cursor
Definition: Screen.h:41
static const int LINE_WRAPPED
Definition: Character.h:37
A terminal character decoder which produces plain text, ignoring colours and other appearance-related...
void effectiveRendition()
Definition: Screen.cpp:472
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:1160
void clearToBeginOfLine()
Clears from the current cursor position to the beginning of the line.
Definition: Screen.cpp:1138
void copyLineToStream(int line, int start, int count, TerminalCharacterDecoder *decoder, bool appendNewLine, bool preserveLineBreaks)
Definition: Screen.cpp:1336
F77_RET_T const double const double * f
~Screen()
Definition: Screen.cpp:98
void setSelectionStart(const int column, const int line, const bool columnmode)
Sets the start of the selection.
Definition: Screen.cpp:1227
void deleteLines(int n)
Removes n lines beginning from the current cursor position.
Definition: Screen.cpp:281
void writeSelectionToStream(TerminalCharacterDecoder *decoder, bool preserveLineBreaks=true)
Copies the selected characters, set using.
Definition: Screen.cpp:1299
quint8 sa_cu_re
Definition: Screen.h:642
bool hasScroll()
Returns true if this screen keeps lines that are scrolled off the screen in a history buffer...
Definition: Screen.cpp:1541
quint8 cu_re
Definition: Screen.h:608
#define loc(X, Y)
Definition: Screen.cpp:56
const HistoryType & getType()
Definition: History.h:112
void reverseIndex()
Move the cursor up one line.
Definition: Screen.cpp:218
int topMargin() const
Returns the top line of the scrolling region.
Definition: Screen.cpp:198
void home()
Sets the position of the cursor to the 'home' position at the top-left corner of the screen (0...
Definition: Screen.cpp:929
void writeToStream(TerminalCharacterDecoder *decoder, int from, int to)
Copies part of the output to a stream.
Definition: Screen.cpp:1444
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.
Definition: Screen.cpp:268
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:1261
CharacterColor backgroundColor
The color used to draw this character's background.
Definition: Character.h:92
#define BS_CLEARS
Definition: Screen.cpp:44
#define MODE_Wrap
Definition: Screen.h:38
int getCursorX() const
Returns the column which the cursor is positioned at.
Definition: Screen.cpp:940
quint8 ef_re
Definition: Screen.h:631
QString getHistoryLine(int no)
Sets the selection to line no in the history and returns the text of that line from the history buffe...
Definition: Screen.cpp:1453
size_t size(T const (&)[z])
Definition: help.cc:103
void resetDroppedLines()
Resets the count of the number of lines dropped from the history.
Definition: Screen.cpp:842
int columns
Definition: Screen.h:586
void index()
Move the cursor down one line.
Definition: Screen.cpp:207
CharacterColor foregroundColor
The foreground color used to draw this character.
Definition: Character.h:90
void getImage(Character *dest, int size, int startLine, int endLine) const
Returns the current screen image.
Definition: Screen.cpp:564
bool columnmode
Definition: Screen.h:626
Base class for terminal character decoders.
void addHistLine()
Definition: Screen.cpp:1461
void getSelectionEnd(int &column, int &line)
Retrieves the end of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1214
bool isSelectionValid() const
Definition: Screen.cpp:1294
void setLineProperty(LineProperty property, bool enable)
Sets or clears an attribute of the current line.
Definition: Screen.cpp:1551
void resetRendition(int rendition)
Disables the given rendition flag.
Definition: Screen.cpp:1154
int _droppedLines
Definition: Screen.h:594
int sel_BR
Definition: Screen.h:624
void clearEntireLine()
Clears the whole of the line on which the cursor is currently positioned.
Definition: Screen.cpp:1143
void NextLine()
Moves the cursor down one line and positions it at the beginning of the line.
Definition: Screen.cpp:234
virtual void addCellsVector(const QVector< Character > &cells)
Definition: History.h:100
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.
Definition: Screen.cpp:1546
CharacterColor ef_fg
Definition: Screen.h:629
int lastPos
Definition: Screen.h:647
void insertLines(int n)
Inserts lines beginning from the current cursor position.
Definition: Screen.cpp:292
void deleteChars(int n)
Delete n characters beginning from the current cursor position.
Definition: Screen.cpp:247
#define RE_CURSOR
Definition: Character.h:47
static void fillWithDefaultChar(Character *dest, int count)
Fills the buffer dest with count instances of the default (ie.
Definition: Screen.cpp:1562
void setMode(int mode)
Sets (enables) the specified screen mode.
Definition: Screen.cpp:302
ScreenParm saveParm
Definition: Screen.h:650
void clearTabStops()
Clears all the tab stops.
Definition: Screen.cpp:701
void restoreCursor()
Restores the position and appearence of the cursor.
Definition: Screen.cpp:350
virtual int getLineLen(int lineno)=0
void restoreMode(int mode)
Restores the state of a screen mode saved by calling saveMode()
Definition: Screen.cpp:331
void copyFromHistory(Character *dest, int startLine, int count) const
Definition: Screen.cpp:512
void scrollUp(int n)
Scroll the scrolling region of the screen up by n lines.
Definition: Screen.cpp:855
quint16 character
The unicode character value for this character.
Definition: Character.h:75
QRect lastScrolledRegion() const
Returns the region of the image which was last scrolled.
Definition: Screen.cpp:867
int _scrolledLines
Definition: Screen.h:591
int tmargin
Definition: Screen.h:611
virtual void addLine(bool previousWrapped=false)=0
static const int LINE_DEFAULT
Definition: Character.h:36
void saveCursor()
Saves the current position and appearence (text color and style) of the cursor.
Definition: Screen.cpp:341
int sa_cuY
Definition: Screen.h:639
void cursorUp(int n)
Move the cursor up by n lines.
Definition: Screen.cpp:129
int cuY
Definition: Screen.h:603
#define MODE_NewLine
Definition: Screen.h:42
void setSelectionEnd(const int column, const int line)
Sets the end of the current selection.
Definition: Screen.cpp:1240
void cursorDown(int n)
Move the cursor down by n lines.
Definition: Screen.cpp:144
void ShowCharacter(unsigned short c)
Displays a new character at the current cursor position.
Definition: Screen.cpp:752
virtual void end()
End decoding.
void cursorLeft(int n)
Move the cursor to the left by n columns.
Definition: Screen.cpp:159
void scrollDown(int n)
Scroll the scrolling region of the screen down by n lines.
Definition: Screen.cpp:884
QVector< Character > ImageLine
Definition: Screen.h:588
CharacterColor cu_fg
Definition: Screen.h:606
int getHistLines()
Return the number of lines in the history buffer.
Definition: Screen.cpp:1522
#define RE_BOLD
Definition: Character.h:42
void setCursorX(int x)
Position the cursor at column x.
Definition: Screen.cpp:915
QString selectedText(bool preserveLineBreaks)
Convenience method.
Definition: Screen.cpp:1281
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:838
virtual void begin(QTextStream *output)
Begin decoding characters.
void reverseRendition(Character &p) const
Definition: Screen.cpp:463
F77_RET_T const double * x
#define DEFAULT_BACK_COLOR