Commit Graph

251 Commits

Author SHA1 Message Date
Matan Ziv-Av
04d99f7cdc Save all lines to history when scrolling multiple lines up
This action should not be performance critical, so scrolling one line n times seems reasonable.
A solution with better performance requires more changes in addHistLine().

This should solve https://bugs.kde.org/show_bug.cgi?id=449233 .
2022-02-05 14:30:10 +00:00
Luis Javier Merino Morán
830f416850 Fix copying one single char
Regression introduced by 5919c1fd.  The selection range is inclusive in
both ends.

Thanks to Chiitoo for reporting and to Yerrey Dev for proposing a
solution.

BUG: 448144
2022-01-11 15:44:21 +00:00
Luis Javier Merino Morán
7a1e47686a Fix remembering selection in scrollback buffer
Commit d37d3ac1 "CompactHistoryScroll: Remove _maxLineCount + 5 lines at
a time" caused a regression: addHistLine queried the number of lines in
history before and after adding a line, and if it had not incremented it
assumed one line entered history and another was dropped at the other
end.  Now, lines are dropped from history in batches, so take care of
that.
2022-01-06 21:53:51 +00:00
Luis Javier Merino Morán
d787ac75bc Move inverted selection to TerminalPainter
TerminalPainter already takes care of calculating blended colors when
"Always invert the colors of selected text" is off.  Move there also the
swapping of fg/bg colors for the inverted colors kind of selections.

This removes one reference to TerminalDisplay from Screen.  There is
still another one to support reflow for some zsh configurations.
2021-12-28 16:27:05 +01:00
Luis Javier Merino Morán
5919c1fd0a Don't get the selection to check if it is empty
Every time the selection is changed, the selection text is retrieved to
check whether to enable or disable the copy actions. Besides that, the
selection text is also used for the web search context menu entries.

Better just check if the selection is empty and make a note that the
selection changed, so the next time the context menu is invoked it can
retrieve the current selection text, which should happen much less often
than selection changes.
2021-12-28 10:59:33 +00:00
Luis Javier Merino Morán
5df601d9ee Avoid moving memory around in copyLineToStream
If the "Trim leading spaces" option is set, we can pass a pointer to the
first non-space character to decodeLine(), no need to first move memory
around.
2021-12-28 10:59:33 +00:00
Luis Javier Merino Morán
5067aeca4e copyFromScreen/copyFromHistory improvements
- Hoist _columns access out of loop.
- Make copyFromScreen more similar to copyFromHistory.
- Use std::copy and std::fill instead of explicit loops.

Prompted by suggestions by Waqar Ahmed.
2021-12-28 10:59:33 +00:00
Luis Javier Merino Morán
0d65b7f0a8 Don't check profile for every selected character
The profile was checked for every selected character to learn whether it
should be rendered with inverted foreground and background colors, or
with blended colors.
2021-12-28 10:59:33 +00:00
Waqar Ahmed
369fce92e6 Massive performance improvement for scrolling 2021-12-14 23:13:22 +05:00
Kurt Hindenburg
57ea4d415d Fix mistake with HAVE_MALLOC_H ifdef 2021-11-26 17:45:31 -05:00
Luis Javier Merino Morán
1cb3de91d4 SD (ScrollDown) should be able to clear the screen
Before, it couldn't scroll out of existence the last line.

From esctest:
SDTests.test_SD_CanClearScreen
2021-11-22 22:39:59 +01:00
Luis Javier Merino Morán
caf5fcebe3 Insert Lines should be a noop if outside margins
From esctest:
ICHTests.test_ICH_ScrollOffRightMarginInScrollRegion
2021-11-22 22:39:59 +01:00
Luis Javier Merino Morán
8c3a1f83c9 Delete Lines should be a noop if outside margins
From esctest:
DLTests.test_DL_OutsideScrollRegion
2021-11-22 22:39:59 +01:00
Luis Javier Merino Morán
717b615ab6 Cursor PreviousLine should respect the top margin
From esctest:
CPLTests.test_CPL_StopsAtTopMarginInScrollRegion
2021-11-22 22:39:59 +01:00
Luis Javier Merino Morán
d2437fbb2b Cursor NextLine should respect the bottom margin
From esctest:
CNLTests.test_CNL_StopsAtBottomMarginInScrollRegion
2021-11-22 22:39:59 +01:00
Luis Javier Merino Morán
566912883d Saving/Restoring cursor should include Origin Mode
From esctest:
ANSIRCTests.test_SaveRestoreCursor_ResetsOriginMode
DECRCTests.test_SaveRestoreCursor_ResetsOriginMode
DECSETTiteInhibitTests.test_SaveRestoreCursor_ResetsOriginMode
2021-11-22 22:39:59 +01:00
Luis Javier Merino Morán
c3b3ef1905 RIS goes to (1,1) and clears tab stops
RIS (ESC c) - Hard Reset should move the cursor to (1,1) and clear tab
stops.

From esctest:
RISTests.test_RIS_CursorToOrigin
RISTests.test_RIS_ResetTabs
2021-11-22 22:39:59 +01:00
Luis Javier Merino Morán
22f8430275 Move the cursor home on Alignment Test
DECALN (ESC # 8) moves the cursor home.

From esctest DECALNTests.test_DECALN_MovesCursorHome
2021-11-22 22:39:59 +01:00
Kurt Hindenburg
13b2ed6697 Comment spelling corrections 2021-11-20 22:14:01 -05:00
Kurt Hindenburg
38fc4569d1 Add malloc.h check; fixes build on macos
Tested on kubuntu and freebsd
2021-11-20 20:39:52 -05:00
Waqar Ahmed
7bb6e94725 Fix Screen::moveImage overwriting content
The previous version didn't care about partial images i.e., the a few
lines of the full image. This lead to broken behaviour in apps like VI.
2021-11-16 10:36:11 +05:00
Tomaz Canabrava
3403585b87 Use malloc_trim only on linux
This is not the correct fix but a temporary one, this allow us
to compile on freebsd while a better fix is in the works.
2021-11-15 16:19:11 +01:00
Waqar Ahmed
304305f752 Dont resize screenLines all the time 2021-11-15 13:46:58 +00:00
Waqar Ahmed
fbf4875865 Use std::vector instead of QVector for _lineProperties 2021-11-15 13:46:58 +00:00
Waqar Ahmed
5daf46c1e0 Use std::vector instead of QVector for _screenLines 2021-11-15 13:46:58 +00:00
Waqar Ahmed
d8999631d9 Improve performance of outputting text to screen
This change tries to improve the performance when you are outputting a
lot of text to the screen. Result with a 40M text file for me before was
6 seconds which is now down to about 3.5 seconds with this change.

It can still be improved a lot more.

BUG: 443885
2021-11-15 13:46:58 +00:00
Martin T. H. Sandsmark
295435d8fa Make sure we release memory when clearing the (possibly huge) scroll history 2021-11-15 13:34:07 +00:00
Laurent Montel
6eb30ff3c3 Remove duplicate include from .h/.cpp 2021-11-02 13:20:43 +01:00
Luis Javier Merino Morán
733e78587f Respect DECDWL/DHL on last column cursor controls 2021-10-22 07:29:51 +00:00
Luis Javier Merino Morán
c099e0f2ea Fix regression on cursor controls at last column
Commit 8de0e6c7 mistakenly removed code to cancel the pending wrap flag
(which in konsole is implemented as having the cursor one past the width
of the screen) before the cursor controls CUU, CUD, CUB and BS.

While the behavior may seem counter-intuitive (specially BS and CUB,
where `printf "A\bB"` at the last column results in `BA`), this is the
behavior of VT100, xterm (without reverse-wraparound mode), and, most
importantly, is expected by ncurses.

CCBUG: 399615
2021-10-22 07:29:51 +00:00
Ahmad Samir
97569b764c Run clang-format on the whole repo
Also install the relevant git hook.

GIT_SILENT
2021-09-06 12:51:39 +02:00
Luis Javier Merino Morán
ed7fe4a2cb Resize lines when clearing to end of line.
clearImage() just clears until _columns.  To prevent characters from
beyond _columns from reappearing, e.g. due to DCH (Delete CHaracters)
requests, make clearImage() resize lines when clearing to the end of
line.

BUG: 432669
2021-07-16 10:55:07 +00:00
Ahmad Samir
38208f94cd Add option to always invert text selection colours
The recent change of blending the background/foreground colours for text
selection doesn't work everywhere, users with vision impairment or
colour-blindness would probably find it hard to distinguish text selection
colours; and the current code can't possibly cover all variations of colour
schemes out there. The same goes with certain displays and viewing angles,
some display types are notoriously awful when viewed at an angle.

BUG: 435309
FIXED-IN: 21.08
2021-06-22 11:56:47 +02:00
Ahmad Samir
4ef7296b94 General code cleanup
- Add a type alias for QPointer<Session>
- Use TerminalDisplay::setSessionController() as early as possible
- Use Screen::setCurrentTerminalDisplay() in TerminalDisplay::mousePressEvent(),
  this matches what's being done in keyPressEvent()
- Add convenience function TerminalDisplay::currentSession()
- More const
2021-06-22 11:52:06 +02:00
Tomaz Canabrava
7f647bac68 Simplify logic 2021-06-18 11:29:20 +00:00
Tomaz Canabrava
17c3b96235 Fix block selection on reflowed lines 2021-06-18 11:29:20 +00:00
Carlos Alves
c0355ccd42 Access changes QList and Add in Screen
Avoid deep copy using 'at()' and '++' before variable instead of after.
2021-06-15 16:10:35 +00:00
Carlos Alves
4ce6ea9132 Change lineProperties to QVector in Screen
Added access changes using 'at()' at reflow code to avoid deep copy.
2021-06-15 16:10:35 +00:00
Carlos Alves
7b2a751b30 Fix Screen::_cuY position inside screen
Keep _cuY position inside max screen lines in AppScreen mode.
2021-05-05 14:11:34 +00:00
Luis Javier Merino Morán
0ecc366c02 Fix crash on resize while doing other things
Commits 9ffe33a27a and
4352df00d9 introduce and use a
getScreenLineColumns(line) method to provide support for DECDWL
(Double-Width) lines.

It turns out that under some conditions on resize Screen::_cuY (the
current cursor Y position) and ScreenWindow::endWindowLine() can have
different ideas of how many lines the terminal has.

A test that asserts:

 - while [ true ]; do echo -e "\e[?1047h";  done
 - Resize the window, making it smaller

BUG: 436327
2021-05-05 14:00:23 +00:00
Luis Javier Merino Morán
d5b290aa48 Fix potential crash in Screen::restoreCursor
Restore Y coordinate before X coordinate, so we make sure Y is in bounds
before trying to access _lineProperties depending on Y.

To test:

 - Go to the last line
 - tput sc
 - Shrink the terminal
 - tput rc
2021-05-05 14:00:23 +00:00
Carlos Alves
2aa61bb994 Change CompactHistory data storage
It is removing the vector of lines storage. Now it is using a similar
idea used in history file.

All chars are stored in a linear way, only the line indexes are
changed when reflowing.

No speed problem found when removing lines.
2021-05-03 19:39:47 +00:00
Luis Javier Merino Morán
05d81656f2 Do not reflow double-height lines
Double height lines are actually two lines, the first with the top part
of the characters, the second with the bottom part. Reflowing could lead
to situations where we render a top part, a double height line with its
top and bottom parts, and a bottom part, which looks weird.
2021-04-17 14:01:06 +00:00
Luis Javier Merino Morán
3cd160f5a0 Prevent selecting beyond last column on double-width lines
There is a difference with xterm behavior: when the screen width is an
odd number of columns, xterm allows selecting up to columns/2+1, we just
allow selecting up to columns/2.
2021-04-17 14:01:06 +00:00
Luis Javier Merino Morán
9771b1d99d Make reflow aware of line rendition attributes
While DECDHL/DECDWL lines are not wrapped at the correct column, now at
least reflowing doesn't clear line rendition attributes, so resizing
Konsole and going back to the original size always recovers the original
content, including double-height/double-width status of each line.

Reflowing double-height lines doesn't make much sense, since a
double-height line actually consists of a top (T) and a bottom (B)
line. Shrinking them could lead to TTBB lines, which look weird. At
least now going back to the original size brings back the original
content in all its glory.
2021-04-17 14:01:06 +00:00
Luis Javier Merino Morán
57ce654da5 Support scrolling double-height/width lines
The scrollback buffer has support for a wrapped property for every line.
Extend it to support the line rendition attributes.
2021-04-17 14:01:06 +00:00
Luis Javier Merino Morán
c61e4cacb6 Allow writing only half of a double-height line
While DECHDL sequences should be used in pairs on adjacent lines, the
first line drawing the top half, and the second line drawing the bottom
half, apparently real VTxxx (or at least the VT220) terminals did draw
only the top or bottom of characters when confronted with an isolated
DECDHL line (https://retrocomputing.stackexchange.com/questions/18023/).
xterm has that same behavior. So behave likewise.
2021-04-17 14:01:06 +00:00
Luis Javier Merino Morán
e1e832f586 Don't clear line rendition on EL and partial ED
EL (Erase Line) should not reset the line rendition attribute to
single-width. ED (Erase Display) should only reset it for completely
cleared lines. ECH (Erase CHaracters) should obviously not reset it.
DECSED and DECSEL (Selective Erase, not supported by Konsole) should not
reset it.

This fixes a vttest test where a line is set to double-height-top and
then EL before writing its text and the double-height-bottom line below.

Can also be tested with:

echo -e "\e[2J\e[4;1HNormal\n\e#6DOUBLE\n\e#6DOUBLE\nNormal" &&
sleep 2; echo -e "\e[5;3H\e[1J\e[8;1H"
2021-04-17 14:01:06 +00:00
Luis Javier Merino Morán
4352df00d9 Use the correct last column for double-width lines
Some control functions special case the last column. When a line has
been set to double-width via DECDWL or DECDHL (double-height and
double-width), the correcr last column for that line should be used.
Control functions which special case the last column include TAB, CUF,
ICH and DECRC.

Can be tested with:

perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7l$r";
         $s="L"."\tx"x4 ."\t\tR"; say "\e#3$s\n\e#4$s"'

The above tests that tabs don't travel beyond the last column in
double-width lines.  The last column (below columns 79 and 80 of
the previous line) should have an "R".

perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7h$r";
         $s="L"."X"x36 ."\e[6C"."R"; say "\e#3$s\n\e#4$s"'

The above tests that CUF (Cursor Forward) doesn't travel beyond the last
column in double-width lines.  The last column (below columns 79 and 80
of the previous line) should have an "R".

perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7h$r";
         $s="L"."X"x22 ."R"."x"x8 ."r"."\e[17D\e[16@";
         say "\e#3$s\n\e#4$s"'

The above tests that ICH (Insert CHaracters; VT200+) doesn't write past
the last column, visible on repaints (switch to another window and
back).

perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7h$r";
         $s="L"."X"x38 ."r\e7\e[H\e8R"; say "\e#3$s\n\e#4$s"'

The above tests that DECRC (Restore Cursor) doesn't restore the cursor
to a position beyond the last column on double-width lines.  The last
column should have an "R", "r" should not be visible.

perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7l$r";
         $s="L"."X"x38 ."R"; print "\e#6$s"'; sleep 5; echo

The above tests that the cursor stays at the rightmost column. The
cursor should stay over the "R" for 5 seconds.
2021-04-17 14:01:06 +00:00
Luis Javier Merino Morán
9ffe33a27a Fix appending characters at end of line in double width lines
Since double-width/double-height lines have room for just half the
characters, take that into account.

Can be tested with:

perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7h$r";
         $s="L"."X"x38 ."RL"; say "\e#6$s"'

The above tests that appending characters to double-width lines in
DECAWM (Auto Wrap Mode) wraps at the correct last column. There should
appear a second line (single-width) with a single "L".

perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7l$r";
         $s="L"."X"x42 ." TEST FAILED OUTOFBOUNDS R"; say "\e#6$s"'

The above tests that appending characters to double-width lines in
non-DECAWM (Auto Wrap Mode) doesn't write past the last column (visible
on repaints - switch to another window and back). The last column (below
columns 79 and 80 of prev line) should have an "R".
2021-04-17 14:01:06 +00:00