Commit Graph

321 Commits

Author SHA1 Message Date
Martin T. H. Sandsmark
15392b307f Clean up images when clearing screen/history 2022-04-25 16:16:04 -04:00
Matan Ziv-Av
ad1421f8b8 Fix cursor position after drawing Sixel graphics
Moving all cursor and scroll handling to addPlacement.

This requires the moveCursor parameter to have three possible values,
since Sixel cursor movement is not the same as Kitty/iterm2. This also
unnecessitates addPlacement return value.

BUG: 452476
(cherry picked from commit 9ae57f4e1d)
2022-04-19 14:40:20 -04:00
Matan Ziv-Av
d28359124b Fix problems discovered by coverity (and more):
- Better handling of data pointer and errors for compressed data in kitty protocol
- Correct handling of iterator when erasing a placement.
- Use midRef() instead of mid().
2022-03-18 16:53:12 +00:00
Luis Javier Merino Morán
0952e29f9b Fix misplaced parenthesis
This was causing "notcurses-demo v" (view) to run really slow.
2022-03-04 13:45:51 +00:00
Luis Javier Merino Morán
62f956b723 Add support for DECSTR (Soft Terminal Reset)
DECSTR is a level 2 control (VT2xx and up), and is to be used instead of
RIS (Reset to Initial State), which can initiate a self-test and drop
the connection on some hardware terminals.

BUG: 134892
2022-03-03 10:46:38 +00:00
Luis Javier Merino Morán
346e50ca8b Improve support for isolated Hangul Jamo
Korean Hangul can be represented in Unicode either as precomposed Hangul
syllables, or as sequences of alphabetic components called Jamo.

Jamo at U+1100..U+11FF, U+A960..U+A97F, U+D7B0..U+D7FF have conjoining
behavior, a sequence of Jamo for Leading Consonants, Vowels, and
(optionally) Trailing Consonants, in that order, conjoins into a
syllable block, (i.e. a sequence L+V+T*, where + and * have their
typical regex meaning).

To represent a Jamo in isolation, there are several options:

 - Use non-conjoining Jamo from U+3130..U+318F (or the halfwidth forms
   at U+FFA0..U+FFDF.  These blocks covers all Jamo used in modern
   Korean, but not all Jamo used in Old Korean.
 - Use the fillers at U+115F and U+1160 to substitute for non-existing
   Leading Consonants, and Vowels.  Fonts may stretch Jamo into a
   corner.
 - Use Jamo from U+1100..U+11FF, U+A960..U+A97F, U+D7B0..U+D7FF, and
   separate them with non-Korean characters.  Unicode recommends U+200B
   ZERO WIDTH SPACE and U+2060 WORD JOINER for this purpose.

Previously, Konsole treated conjoining Jamo as combining marks which
could apply to any previous character.  This commit makes conjoining
Jamo only join when previous Jamo when they form (the beginning) of a
proper L+V+T* syllable.  It also fixes the width reported when they
cannot join previous characters, which should now be 2, instead of 0.
2022-03-03 09:51:43 +00:00
Luis Javier Merino Morán
c26693af4e Don't strip 0-width Other_Format characters
These include ZWJ (Zero Width Joiner), ZWNJ (Zero Width Non-Joiner) and
Zero Width Space, which can be used to change the rendering of text,
e.g. forcing or preventing the formation of conjunct forms in Indic
scripts.

Treat them as combining characters, so they end up in an extended
character in the previous character cell.

To test, the output of:

printf "[\u915\u94d\u927]  "[\u915\u94d\u200c\u937]  [\u915\u94d\u200d\u937]\n"

can be compared against the examples in Figures 12.4 and 12.5 of the
Unicode standard, from the "Explicit Virama (Halant)" and "Explicit
Half-Consonants" sub-sections of the Devanagari section on "South and
Central Asia I" chapter (page 465 in Unicode 14).
~
2022-03-03 09:51:43 +00:00
Luis Javier Merino Morán
e7e901003d Don't cross hard newlines looking for a base char
Combining characters could end up combining with an unrelated character
from the previous line.  Now they just disappear, without messing with
the display of unrelated characters.
2022-03-03 09:51:43 +00:00
Luis Javier Merino Morán
cb1e04a05e Use a more explicit condition when combining chars
The logic for looking for a base character is meant to skip the right
part of double-wide characters.  Be explicit about it.
2022-03-03 09:51:43 +00:00
Luis Javier Merino Morán
d6cc3d4df3 Abstract away semantics of char 0 as right half of double-wide char 2022-03-03 09:51:43 +00:00
Matan Ziv-Av
e0b4b96a85 Use negative z postion for sixel and iterm2 protocol images
remove all characters covered by the image before placing the image.
2022-02-24 13:11:19 +00:00
Matan Ziv-Av
77de29bedd A hack to avoid scrolling when not moving the cursor. 2022-02-24 13:11:19 +00:00
Matan Ziv-Av
8030c1987c Kitty protocol fixes
- Allow deleting by placement id
- Delete image cache when Emulation object is destroyed.
- Small simplification of selecting image from cache.
2022-02-24 13:11:19 +00:00
Matan Ziv-Av
5647cc35e9 Use std::unique_ptr for placement list
Avoiding the need to manually delete placements.
2022-02-24 13:11:19 +00:00
Matan Ziv-Av
ff716ffbf3 Move graphics related lists from TerminalDisplay to more appropriate classes
- Graphics placements list to Screen
- Kitty image cache to Vt102Emulation
2022-02-24 13:11:19 +00:00
Matan Ziv-Av
78971aa5c7 Improve memory handling
- Remove placements when they scroll out of the scroll buffer
- Delete removed placements.
- Free QImage memory when image is deleted.
2022-02-23 11:13:10 +00:00
Luis Javier Merino Morán
8345f24ee9 More robust reflow on zsh with semantic prompts
Improve the logic for avoiding doing reflow of zsh prompts (zsh will
repaint the prompt and command line) when there are semantic prompt
markers (OSC 133).

BUG: 447830
2022-02-07 11:18:59 +00:00
Matan Ziv-Av
8119581063 Remove images on when clearing entire screen 2022-02-07 10:49:07 +00:00
Matan Ziv-Av
085814e264 Use braces for single statement if/for 2022-02-07 10:49:07 +00:00
Matan Ziv-Av
d691a3d76c Add infrastructure for displaying graphics in terminal
This allows for showing graphics in the terminal.
konsole keeps two lists of graphics to display (called placements).
Each placement includes:
- A pixmap to display.
- Column and row where the image is displayed.
- A z index. The text has z=0, so placements with z<0 are displayed below the text.
- An opacity value with which the pixmap is drawn.
- Whether the graphics scrolls with the text

Graphics placements with pid >= 0 are managed by the application, which can remove them. They need to have a unique <id,pid> pair.
Placements with pid<0 are not managed by the application. They are deleted automatically when they are completely obscured by others.
2022-02-07 10:49:07 +00:00
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