Screen.h 25.4 KB
Newer Older
1
/*
2 3
    This file is part of Konsole, KDE's terminal.

4 5
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
    Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6

7 8 9 10 11 12 13 14 15
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
16

17 18 19 20
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
21 22
*/

23 24
#ifndef SCREEN_H
#define SCREEN_H
25

26
// Qt
27 28 29 30 31
#include <QRect>
#include <QSet>
#include <QVector>
#include <QBitArray>
#include <QVarLengthArray>
32

33
// Konsole
34
#include "Character.h"
35
#include "konsoleprivate_export.h"
36

37 38 39 40 41 42 43 44
#define MODE_Origin    0
#define MODE_Wrap      1
#define MODE_Insert    2
#define MODE_Screen    3
#define MODE_Cursor    4
#define MODE_NewLine   5
#define MODES_SCREEN   6

Kurt Hindenburg's avatar
Kurt Hindenburg committed
45
namespace Konsole {
46
class TerminalCharacterDecoder;
47
class TerminalDisplay;
48 49
class HistoryType;
class HistoryScroll;
50

51 52 53
/**
    \brief An image of characters with associated attributes.

54
    The terminal emulation ( Emulation ) receives a serial stream of
55 56
    characters from the program currently running in the terminal.
    From this stream it creates an image of characters which is ultimately
57
    rendered by the display widget ( TerminalDisplay ).  Some types of emulation
Jekyll Wu's avatar
Jekyll Wu committed
58
    may have more than one screen image.
59

Robert Knight's avatar
 
Robert Knight committed
60
    getImage() is used to retrieve the currently visible image
61
    which is then used by the display widget to draw the output from the
Jekyll Wu's avatar
Jekyll Wu committed
62
    terminal.
63 64

    The number of lines of output history which are kept in addition to the current
Jekyll Wu's avatar
Jekyll Wu committed
65
    screen image depends on the history scroll being used to store the output.
66 67 68
    The scroll is specified using setScroll()
    The output history can be retrieved using writeToStream()

Jekyll Wu's avatar
Jekyll Wu committed
69
    The screen image has a selection associated with it, specified using
70
    setSelectionStart() and setSelectionEnd().  The selected text can be retrieved
71
    using selectedText().  When getImage() is used to retrieve the visible image,
Jekyll Wu's avatar
Jekyll Wu committed
72
    characters which are part of the selection have their colors inverted.
73
*/
74
class KONSOLEPRIVATE_EXPORT Screen
75 76
{
public:
77 78 79 80 81 82 83 84 85
    /* PlainText: Return plain text (default)
     * ConvertToHtml: Specifies if returned text should have HTML tags.
     * PreserveLineBreaks: Specifies whether new line characters should be
     *      inserted into the returned text at the end of each terminal line.
     * TrimLeadingWhitespace: Specifies whether leading spaces should be
     *      trimmed in the returned text.
     * TrimTrailingWhitespace: Specifies whether trailing spaces should be
     *      trimmed in the returned text.
     */
86 87 88 89 90 91 92 93 94
    enum DecodingOption {
        PlainText = 0x0,
        ConvertToHtml = 0x1,
        PreserveLineBreaks = 0x2,
        TrimLeadingWhitespace = 0x4,
        TrimTrailingWhitespace = 0x8
    };
    Q_DECLARE_FLAGS(DecodingOptions, DecodingOption)

95
    /** Construct a new screen image of size @p lines by @p columns. */
96 97
    Screen(int lines, int columns);
    ~Screen();
98

Kurt Hindenburg's avatar
Kurt Hindenburg committed
99 100
    Screen(const Screen &) = delete;
    Screen &operator=(const Screen &) = delete;
101

Jekyll Wu's avatar
Jekyll Wu committed
102
    // VT100/2 Operations
103
    // Cursor Movement
104

Jekyll Wu's avatar
Jekyll Wu committed
105 106
    /**
     * Move the cursor up by @p n lines.  The cursor will stop at the
107 108
     * top margin.
     */
109
    void cursorUp(int n);
Jekyll Wu's avatar
Jekyll Wu committed
110
    /**
111 112 113
     * Move the cursor down by @p n lines.  The cursor will stop at the
     * bottom margin.
     */
114
    void cursorDown(int n);
Jekyll Wu's avatar
Jekyll Wu committed
115
    /**
116 117 118
     * Move the cursor to the left by @p n columns.
     * The cursor will stop at the first column.
     */
119
    void cursorLeft(int n);
120 121 122 123 124 125 126 127 128 129
    /**
     * Moves cursor to beginning of the line by @p n lines down.
     * The cursor will stop at the beginning of the line.
     */
    void cursorNextLine(int n);
    /**
     * Moves cursor to beginning of the line by @p n lines up.
     * The cursor will stop at the beginning of the line.
     */
    void cursorPreviousLine(int n);
Jekyll Wu's avatar
Jekyll Wu committed
130
    /**
131 132 133
     * Move the cursor to the right by @p n columns.
     * The cursor will stop at the right-most column.
     */
134
    void cursorRight(int n);
135
    /** Position the cursor on line @p y. */
136
    void setCursorY(int y);
137
    /** Position the cursor at column @p x. */
138
    void setCursorX(int x);
139
    /** Position the cursor at line @p y, column @p x. */
140
    void setCursorYX(int y, int x);
141 142 143
    /**
     * Sets the margins for scrolling the screen.
     *
144 145
     * @param top The top line of the new scrolling margin.
     * @param bot The bottom line of the new scrolling margin.
146
     */
147
    void setMargins(int top, int bot);
Jekyll Wu's avatar
Jekyll Wu committed
148
    /** Returns the top line of the scrolling region. */
149
    int topMargin() const;
150
    /** Returns the bottom line of the scrolling region. */
151 152
    int bottomMargin() const;

Jekyll Wu's avatar
Jekyll Wu committed
153
    /**
154 155 156
     * Resets the scrolling margins back to the top and bottom lines
     * of the screen.
     */
157
    void setDefaultMargins();
158

Jekyll Wu's avatar
Jekyll Wu committed
159 160
    /**
     * Moves the cursor down one line, if the MODE_NewLine mode
161 162 163 164
     * flag is enabled then the cursor is returned to the leftmost
     * column first.
     *
     * Equivalent to NextLine() if the MODE_NewLine flag is set
Jekyll Wu's avatar
Jekyll Wu committed
165
     * or index() otherwise.
166
     */
167
    void newLine();
168 169
    /**
     * Moves the cursor down one line and positions it at the beginning
170
     * of the line.  Equivalent to calling Return() followed by index()
171
     */
172
    void nextLine();
173

Jekyll Wu's avatar
Jekyll Wu committed
174
    /**
175 176 177 178
     * Move the cursor down one line.  If the cursor is on the bottom
     * line of the scrolling region (as returned by bottomMargin()) the
     * scrolling region is scrolled up by one line instead.
     */
179
    void index();
180 181 182 183 184
    /**
     * Move the cursor up one line.  If the cursor is on the top line
     * of the scrolling region (as returned by topMargin()) the scrolling
     * region is scrolled down by one line instead.
     */
185
    void reverseIndex();
186

Jekyll Wu's avatar
Jekyll Wu committed
187 188 189
    /**
     * Scroll the scrolling region of the screen up by @p n lines.
     * The scrolling region is initially the whole screen, but can be changed
190
     * using setMargins()
Jekyll Wu's avatar
Jekyll Wu committed
191
     */
192
    void scrollUp(int n);
193 194 195 196 197
    /**
     * Scroll the scrolling region of the screen down by @p n lines.
     * The scrolling region is initially the whole screen, but can be changed
     * using setMargins()
     */
198
    void scrollDown(int n);
Jekyll Wu's avatar
Jekyll Wu committed
199 200
    /**
     * Moves the cursor to the beginning of the current line.
201 202
     * Equivalent to setCursorX(0)
     */
203
    void toStartOfLine();
Jekyll Wu's avatar
Jekyll Wu committed
204
    /**
205 206 207
     * Moves the cursor one column to the left and erases the character
     * at the new cursor position.
     */
208 209 210 211 212
    void backspace();
    /** Moves the cursor @p n tab-stops to the right. */
    void tab(int n = 1);
    /** Moves the cursor @p n tab-stops to the left. */
    void backtab(int n);
213

214
    // Editing
215

Jekyll Wu's avatar
Jekyll Wu committed
216 217
    /**
     * Erase @p n characters beginning from the current cursor position.
218 219
     * This is equivalent to over-writing @p n characters starting with the current
     * cursor position with spaces.
Jekyll Wu's avatar
Jekyll Wu committed
220
     * If @p n is 0 then one character is erased.
221
     */
222
    void eraseChars(int n);
Jekyll Wu's avatar
Jekyll Wu committed
223 224 225
    /**
     * Delete @p n characters beginning from the current cursor position.
     * If @p n is 0 then one character is deleted.
226
     */
227
    void deleteChars(int n);
228 229
    /**
     * Insert @p n blank characters beginning from the current cursor position.
Jekyll Wu's avatar
Jekyll Wu committed
230
     * The position of the cursor is not altered.
231 232
     * If @p n is 0 then one character is inserted.
     */
233
    void insertChars(int n);
234
    /**
Kurt Hindenburg's avatar
Kurt Hindenburg committed
235 236
     * Repeat the preceding graphic character @p n times, including SPACE.
     * If @p n is 0 then the character is repeated once.
237 238
     */
    void repeatChars(int n);
Jekyll Wu's avatar
Jekyll Wu committed
239
    /**
240 241 242 243
     * Removes @p n lines beginning from the current cursor position.
     * The position of the cursor is not altered.
     * If @p n is 0 then one line is removed.
     */
244
    void deleteLines(int n);
245 246 247 248 249
    /**
     * Inserts @p lines beginning from the current cursor position.
     * The position of the cursor is not altered.
     * If @p n is 0 then one line is inserted.
     */
250
    void insertLines(int n);
251
    /** Clears all the tab stops. */
252
    void clearTabStops();
Jekyll Wu's avatar
Jekyll Wu committed
253
    /**  Sets or removes a tab stop at the cursor's current column. */
254
    void changeTabStop(bool set);
255

256 257 258 259
    /** Resets (clears) the specified screen @p m. */
    void resetMode(int m);
    /** Sets (enables) the specified screen @p m. */
    void setMode(int m);
Jekyll Wu's avatar
Jekyll Wu committed
260
    /**
261
     * Saves the state of the specified screen @p m.  It can be restored
262 263
     * using restoreMode()
     */
264 265 266 267 268
    void saveMode(int m);
    /** Restores the state of a screen @p m saved by calling saveMode() */
    void restoreMode(int m);
    /** Returns whether the specified screen @p me is enabled or not .*/
    bool getMode(int m) const;
269

Jekyll Wu's avatar
Jekyll Wu committed
270 271 272 273
    /**
     * Saves the current position and appearance (text color and style) of the cursor.
     * It can be restored by calling restoreCursor()
     */
274
    void saveCursor();
Albert Astals Cid's avatar
Albert Astals Cid committed
275
    /** Restores the position and appearance of the cursor.  See saveCursor() */
276
    void restoreCursor();
277

Jekyll Wu's avatar
Jekyll Wu committed
278
    /** Clear the whole screen, moving the current screen contents into the history first. */
279
    void clearEntireScreen();
Jekyll Wu's avatar
Jekyll Wu committed
280 281
    /**
     * Clear the area of the screen from the current cursor position to the end of
282 283
     * the screen.
     */
284
    void clearToEndOfScreen();
285 286 287 288
    /**
     * Clear the area of the screen from the current cursor position to the start
     * of the screen.
     */
289
    void clearToBeginOfScreen();
290
    /** Clears the whole of the line on which the cursor is currently positioned. */
291
    void clearEntireLine();
292
    /** Clears from the current cursor position to the end of the line. */
293
    void clearToEndOfLine();
294
    /** Clears from the current cursor position to the beginning of the line. */
295
    void clearToBeginOfLine();
296

297
    /** Fills the entire screen with the letter 'E' */
298
    void helpAlign();
299

Jekyll Wu's avatar
Jekyll Wu committed
300 301
    /**
     * Enables the given @p rendition flag.  Rendition flags control the appearance
302 303 304
     * of characters on the screen.
     *
     * @see Character::rendition
Jekyll Wu's avatar
Jekyll Wu committed
305
     */
306
    void setRendition(RenditionFlags rendition);
307
    /**
Albert Astals Cid's avatar
Albert Astals Cid committed
308
     * Disables the given @p rendition flag.  Rendition flags control the appearance
309 310 311 312
     * of characters on the screen.
     *
     * @see Character::rendition
     */
313
    void resetRendition(RenditionFlags rendition);
314

Jekyll Wu's avatar
Jekyll Wu committed
315
    /**
316 317 318 319 320 321 322
     * Sets the cursor's foreground color.
     * @param space The color space used by the @p color argument
     * @param color The new foreground color.  The meaning of this depends on
     * the color @p space used.
     *
     * @see CharacterColor
     */
323
    void setForeColor(int space, int color);
324 325
    /**
     * Sets the cursor's background color.
326
     * @param space The color space used by the @p color argument.
327 328 329 330 331
     * @param color The new background color.  The meaning of this depends on
     * the color @p space used.
     *
     * @see CharacterColor
     */
332
    void setBackColor(int space, int color);
Jekyll Wu's avatar
Jekyll Wu committed
333 334
    /**
     * Resets the cursor's color back to the default and sets the
335 336
     * character's rendition flags back to the default settings.
     */
337
    void setDefaultRendition();
338

339
    /** Returns the column which the cursor is positioned at. */
340
    int  getCursorX() const;
341
    /** Returns the line which the cursor is positioned on. */
342
    int  getCursorY() const;
343

344 345 346 347 348 349 350 351 352 353 354 355 356 357
    /**
     * Resets the state of the screen.  This resets the various screen modes
     * back to their default states.  The cursor style and colors are reset
     * (as if setDefaultRendition() had been called)
     *
     * <ul>
     * <li>Line wrapping is enabled.</li>
     * <li>Origin mode is disabled.</li>
     * <li>Insert mode is disabled.</li>
     * <li>Cursor mode is enabled.  TODO Document me</li>
     * <li>Screen mode is disabled. TODO Document me</li>
     * <li>New line mode is disabled.  TODO Document me</li>
     * </ul>
     *
Jekyll Wu's avatar
Jekyll Wu committed
358
     * If @p clearScreen is true then the screen contents are erased entirely,
359 360
     * otherwise they are unaltered.
     */
361
    void reset();
362

Jekyll Wu's avatar
Jekyll Wu committed
363 364 365
    /**
     * Displays a new character at the current cursor position.
     *
366
     * If the cursor is currently positioned at the right-edge of the screen and
Jekyll Wu's avatar
Jekyll Wu committed
367
     * line wrapping is enabled then the character is added at the start of a new
368 369
     * line below the current one.
     *
Jekyll Wu's avatar
Jekyll Wu committed
370 371 372 373
     * If the MODE_Insert screen mode is currently enabled then the character
     * is inserted at the current cursor position, otherwise it will replace the
     * character already at the current cursor position.
     */
374
    void displayCharacter(uint c);
375

Jekyll Wu's avatar
Jekyll Wu committed
376 377
    /**
     * Resizes the image to a new fixed size of @p new_lines by @p new_columns.
378 379
     * In the case that @p new_columns is smaller than the current number of columns,
     * existing lines are not truncated.  This prevents characters from being lost
380
     * if the terminal display is resized smaller and then larger again.
381
     *
Jekyll Wu's avatar
Jekyll Wu committed
382
     * The top and bottom margins are reset to the top and bottom of the new
383 384
     * screen size.  Tab stops are also reset and the current selection is
     * cleared.
385
     */
386
    void resizeImage(int new_lines, int new_columns);
387

388
    /**
Jekyll Wu's avatar
Jekyll Wu committed
389
     * Returns the current screen image.
390 391
     * The result is an array of Characters of size [getLines()][getColumns()] which
     * must be freed by the caller after use.
Robert Knight's avatar
 
Robert Knight committed
392 393 394 395 396
     *
     * @param dest Buffer to copy the characters into
     * @param size Size of @p dest in Characters
     * @param startLine Index of first line to copy
     * @param endLine Index of last line to copy
397
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
398
    void getImage(Character *dest, int size, int startLine, int endLine) const;
399

Jekyll Wu's avatar
Jekyll Wu committed
400
    /**
401
     * Returns the additional attributes associated with lines in the image.
Jekyll Wu's avatar
Jekyll Wu committed
402
     * The most important attribute is LINE_WRAPPED which specifies that the
Robert Knight's avatar
 
Robert Knight committed
403
     * line is wrapped,
404 405
     * other attributes control the size of characters in the line.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
406
    QVector<LineProperty> getLineProperties(int startLine, int endLine) const;
407

408
    /** Return the number of lines. */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
409 410
    int getLines() const
    {
Jekyll Wu's avatar
Jekyll Wu committed
411
        return _lines;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
412
    }
Kurt Hindenburg's avatar
Kurt Hindenburg committed
413

414
    /** Return the number of columns. */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
415 416
    int getColumns() const
    {
Jekyll Wu's avatar
Jekyll Wu committed
417
        return _columns;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
418
    }
Kurt Hindenburg's avatar
Kurt Hindenburg committed
419

420
    /** Return the number of lines in the history buffer. */
421
    int getHistLines() const;
Jekyll Wu's avatar
Jekyll Wu committed
422 423 424
    /**
     * Sets the type of storage used to keep lines in the history.
     * If @p copyPreviousScroll is true then the contents of the previous
425 426
     * history buffer are copied into the new scroll.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
427
    void setScroll(const HistoryType &, bool copyPreviousScroll = true);
428
    /** Returns the type of storage used to keep lines in the history. */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
429
    const HistoryType &getScroll() const;
Jekyll Wu's avatar
Jekyll Wu committed
430
    /**
431 432 433
     * Returns true if this screen keeps lines that are scrolled off the screen
     * in a history buffer.
     */
434
    bool hasScroll() const;
435

Jekyll Wu's avatar
Jekyll Wu committed
436
    /**
437 438
     * Sets the start of the selection.
     *
439
     * @param x The column index of the first character in the selection.
440
     * @param y The line index of the first character in the selection.
441
     * @param blockSelectionMode True if the selection is in column mode.
442
     */
443
    void setSelectionStart(const int x, const int y, const bool blockSelectionMode);
444

445
    /**
446
     * Sets the end of the current selection.
447
     *
448 449
     * @param x The column index of the last character in the selection.
     * @param y The line index of the last character in the selection.
Jekyll Wu's avatar
Jekyll Wu committed
450
     */
451
    void setSelectionEnd(const int x, const int y);
452

453 454 455 456
    /**
     * Retrieves the start of the selection or the cursor position if there
     * is no selection.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
457
    void getSelectionStart(int &column, int &line) const;
458

459 460 461 462
    /**
     * Retrieves the end of the selection or the cursor position if there
     * is no selection.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
463
    void getSelectionEnd(int &column, int &line) const;
464

465
    /** Clears the current selection */
466
    void clearSelection();
467

468 469 470
    /** Return the selection state */
    bool hasSelection() const;

Jekyll Wu's avatar
Jekyll Wu committed
471
    /**
472
      *  Returns true if the character at (@p x, @p y) is part of the
Jekyll Wu's avatar
Jekyll Wu committed
473 474
      *  current selection.
      */
475
    bool isSelected(const int x, const int y) const;
476

Jekyll Wu's avatar
Jekyll Wu committed
477 478
    /**
     * Convenience method.  Returns the currently selected text.
479
     * @param options See Screen::DecodingOptions
480
     */
481
    QString selectedText(const DecodingOptions options) const;
482

483
    /**
484 485 486
     * Convenience method.  Returns the text between two indices.
     * @param startIndex Specifies the starting text index
     * @param endIndex Specifies the ending text index
487
     * @param options See Screen::DecodingOptions
488
     */
489
    QString text(int startIndex, int endIndex, const DecodingOptions options) const;
490

491 492 493
    /**
     * Copies part of the output to a stream.
     *
494
     * @param decoder A decoder which converts terminal characters into text
495 496
     * @param fromLine The first line in the history to retrieve
     * @param toLine The last line in the history to retrieve
497
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
498
    void writeLinesToStream(TerminalCharacterDecoder *decoder, int fromLine, int toLine) const;
499

500 501 502 503 504 505 506 507 508 509
    /**
     * Checks if the text between from and to is inside the current
     * selection. If this is the case, the selection is cleared. The
     * from and to are coordinates in the current viewable window.
     * The loc(x,y) macro can be used to generate these values from a
     * column,line pair.
     *
     * @param from The start of the area to check.
     * @param to The end of the area to check
     */
510 511
    void checkSelection(int from, int to);

Jekyll Wu's avatar
Jekyll Wu committed
512
    /**
513
     * Sets or clears an attribute of the current line.
Jekyll Wu's avatar
Jekyll Wu committed
514
     *
515 516 517 518
     * @param property The attribute to set or clear
     * Possible properties are:
     * LINE_WRAPPED:     Specifies that the line is wrapped.
     * LINE_DOUBLEWIDTH: Specifies that the characters in the current line
519
     *                   should be double the normal width.
Jekyll Wu's avatar
Jekyll Wu committed
520
     * LINE_DOUBLEHEIGHT:Specifies that the characters in the current line
521
     *                   should be double the normal height.
522
     *                   Double-height lines are formed of two lines containing the same characters,
523 524 525
     *                   with both having the LINE_DOUBLEHEIGHT attribute.
     *                   This allows other parts of the code to work on the
     *                   assumption that all lines are the same height.
526 527 528
     *
     * @param enable true to apply the attribute to the current line or false to remove it
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
529
    void setLineProperty(LineProperty property, bool enable);
530

Jekyll Wu's avatar
Jekyll Wu committed
531
    /**
532
     * Returns the number of lines that the image has been scrolled up or down by,
Robert Knight's avatar
 
Robert Knight committed
533 534
     * since the last call to resetScrolledLines().
     *
535
     * a positive return value indicates that the image has been scrolled up,
Jekyll Wu's avatar
Jekyll Wu committed
536
     * a negative return value indicates that the image has been scrolled down.
537 538
     */
    int scrolledLines() const;
539 540 541 542

    /**
     * Returns the region of the image which was last scrolled.
     *
Jekyll Wu's avatar
Jekyll Wu committed
543
     * This is the area of the image from the top margin to the
544 545 546 547
     * bottom margin when the last scroll occurred.
     */
    QRect lastScrolledRegion() const;

Jekyll Wu's avatar
Jekyll Wu committed
548
    /**
549 550 551 552 553
     * Resets the count of the number of lines that the image has been scrolled up or down by,
     * see scrolledLines()
     */
    void resetScrolledLines();

554 555 556 557 558 559 560
    /**
     * Returns the number of lines of output which have been
     * dropped from the history since the last call
     * to resetDroppedLines()
     *
     * If the history is not unlimited then it will drop
     * the oldest lines of output if new lines are added when
Jekyll Wu's avatar
Jekyll Wu committed
561
     * it is full.
562 563 564 565 566 567 568 569 570
     */
    int droppedLines() const;

    /**
     * Resets the count of the number of lines dropped from
     * the history.
     */
    void resetDroppedLines();

Jekyll Wu's avatar
Jekyll Wu committed
571
    /**
572 573 574
      * Fills the buffer @p dest with @p count instances of the default (ie. blank)
      * Character style.
      */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
575
    static void fillWithDefaultChar(Character *dest, int count);
Robert Knight's avatar
 
Robert Knight committed
576

Kurt Hindenburg's avatar
Kurt Hindenburg committed
577 578
    void setCurrentTerminalDisplay(TerminalDisplay *display)
    {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
579
        _currentTerminalDisplay = display;
580 581
    }

Kurt Hindenburg's avatar
Kurt Hindenburg committed
582 583
    TerminalDisplay *currentTerminalDisplay()
    {
584 585
        return _currentTerminalDisplay;
    }
586

587
    QSet<uint> usedExtendedChars() const
Kurt Hindenburg's avatar
Kurt Hindenburg committed
588
    {
589
        QSet<uint> result;
Jekyll Wu's avatar
Jekyll Wu committed
590
        for (int i = 0; i < _lines; ++i) {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
591
            const ImageLine &il = _screenLines[i];
592
            for (int j = 0; j < il.length(); ++j) {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
593
                if (il[j].rendition & RE_EXTENDED_CHAR) {
594 595 596 597 598 599
                    result << il[j].character;
                }
            }
        }
        return result;
    }
600

Jekyll Wu's avatar
Jekyll Wu committed
601
    static const Character DefaultChar;
602

Jekyll Wu's avatar
Jekyll Wu committed
603 604
private:
    //copies a line of text from the screen or history into a stream using a
605 606
    //specified character decoder.  Returns the number of lines actually copied,
    //which may be less than 'count' if (start+count) is more than the number of characters on
Jekyll Wu's avatar
Jekyll Wu committed
607
    //the line
608
    //
Jekyll Wu's avatar
Jekyll Wu committed
609
    //line - the line number to copy, from 0 (the earliest line in the history) up to
610
    //         history->getLines() + lines - 1
611 612
    //start - the first column on the line to copy
    //count - the number of characters on the line to copy
613
    //decoder - a decoder which converts terminal characters (an Character array) into text
614
    //appendNewLine - if true a new line character (\n) is appended to the end of the line
Kurt Hindenburg's avatar
Kurt Hindenburg committed
615
    int  copyLineToStream(int line, int start, int count, TerminalCharacterDecoder *decoder,
616
                          bool appendNewLine, const DecodingOptions options) const;
617

618 619 620
    //fills a section of the screen image with the character 'c'
    //the parameters are specified as offsets from the start of the screen image.
    //the loc(x,y) macro can be used to generate these values from a column,line pair.
621
    void clearImage(int loca, int loce, char c);
622 623 624 625

    //move screen image between 'sourceBegin' and 'sourceEnd' to 'dest'.
    //the parameters are specified as offsets from the start of the screen image.
    //the loc(x,y) macro can be used to generate these values from a column,line pair.
626 627
    //
    //NOTE: moveImage() can only move whole lines
628
    void moveImage(int dest, int sourceBegin, int sourceEnd);
629 630 631 632
    // scroll up 'n' lines in current region, clearing the bottom 'n' lines
    void scrollUp(int from, int n);
    // scroll down 'n' lines in current region, clearing the top 'n' lines
    void scrollDown(int from, int n);
633

634
    //when we handle scroll commands, we need to know which screenwindow will scroll
Kurt Hindenburg's avatar
Kurt Hindenburg committed
635
    TerminalDisplay *_currentTerminalDisplay;
636

637 638 639 640
    void addHistLine();

    void initTabStops();

641
    void updateEffectiveRendition();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
642
    void reverseRendition(Character &p) const;
643

644
    bool isSelectionValid() const;
645 646
    // copies text from 'startIndex' to 'endIndex' to a stream
    // startIndex and endIndex are positions generated using the loc(x,y) macro
Kurt Hindenburg's avatar
Kurt Hindenburg committed
647
    void writeToStream(TerminalCharacterDecoder *decoder, int startIndex, int endIndex,
648
                       const DecodingOptions options) const;
649 650
    // copies 'count' lines from the screen buffer into 'dest',
    // starting from 'startLine', where 0 is the first line in the screen buffer
Kurt Hindenburg's avatar
Kurt Hindenburg committed
651
    void copyFromScreen(Character *dest, int startLine, int count) const;
652 653
    // copies 'count' lines from the history buffer into 'dest',
    // starting from 'startLine', where 0 is the first line in the history
Kurt Hindenburg's avatar
Kurt Hindenburg committed
654
    void copyFromHistory(Character *dest, int startLine, int count) const;
Robert Knight's avatar
 
Robert Knight committed
655

656 657 658 659 660 661 662
    // returns a buffer that can hold at most 'count' characters,
    // where the number of reallocations and object reinitializations
    // should be as minimal as possible
    static Character *getCharacterBuffer(const int size);

    int getLineLength(const int line) const;

663
    // screen image ----------------
Jekyll Wu's avatar
Jekyll Wu committed
664 665
    int _lines;
    int _columns;
666

667
    typedef QVector<Character> ImageLine;      // [0..columns]
Kurt Hindenburg's avatar
Kurt Hindenburg committed
668
    ImageLine *_screenLines;             // [lines]
669
    int _screenLinesSize;                // _screenLines.size()
670

671
    int _scrolledLines;
672
    QRect _lastScrolledRegion;
673

674 675
    int _droppedLines;

Jekyll Wu's avatar
Jekyll Wu committed
676
    QVarLengthArray<LineProperty, 64> _lineProperties;
677

678
    // history buffer ---------------
Kurt Hindenburg's avatar
Kurt Hindenburg committed
679
    HistoryScroll *_history;
680

681
    // cursor location
Jekyll Wu's avatar
Jekyll Wu committed
682 683
    int _cuX;
    int _cuY;
684 685

    // cursor color and rendition info
Jekyll Wu's avatar
Jekyll Wu committed
686 687
    CharacterColor _currentForeground;
    CharacterColor _currentBackground;
688
    RenditionFlags _currentRendition;
689 690

    // margins ----------------
691 692
    int _topMargin;
    int _bottomMargin;
693 694

    // states ----------------
Jekyll Wu's avatar
Jekyll Wu committed
695 696
    int _currentModes[MODES_SCREEN];
    int _savedModes[MODES_SCREEN];
697 698 699

    // ----------------------------

Jekyll Wu's avatar
Jekyll Wu committed
700
    QBitArray _tabStops;
701 702

    // selection -------------------
Jekyll Wu's avatar
Jekyll Wu committed
703 704 705 706
    int _selBegin; // The first location selected.
    int _selTopLeft;    // TopLeft Location.
    int _selBottomRight;    // Bottom Right Location.
    bool _blockSelectionMode;  // Column selection mode
707 708

    // effective colors and rendition ------------
Jekyll Wu's avatar
Jekyll Wu committed
709 710
    CharacterColor _effectiveForeground; // These are derived from
    CharacterColor _effectiveBackground; // the cu_* variables above
711
    RenditionFlags _effectiveRendition;  // to speed up operation
712

Kurt Hindenburg's avatar
Kurt Hindenburg committed
713
    class SavedState
714 715
    {
    public:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
716 717 718 719 720 721 722 723
        SavedState() :
            cursorColumn(0),
            cursorLine(0),
            rendition(0),
            foreground(CharacterColor()),
            background(CharacterColor())
        {
        }
724 725 726

        int cursorColumn;
        int cursorLine;
727
        RenditionFlags rendition;
728 729 730
        CharacterColor foreground;
        CharacterColor background;
    };
Jekyll Wu's avatar
Jekyll Wu committed
731
    SavedState _savedState;
732

733
    // last position where we added a character
Jekyll Wu's avatar
Jekyll Wu committed
734
    int _lastPos;
735 736

    // used in REP (repeating char)
737
    quint32 _lastDrawnChar;
738
};
739

740 741
Q_DECLARE_OPERATORS_FOR_FLAGS(Screen::DecodingOptions)

Stephan Binner's avatar
Stephan Binner committed
742
}
743

744 745


746
#endif // SCREEN_H