Commit Graph

301 Commits

Author SHA1 Message Date
Matan Ziv-Av
f26f71db01 Add keyboard selection mode
Similar to screen copy/scrollback mode it allows browsing the scrollback
and selecting text.

Selection is done either by standard GUI shift+arrows, or `vi` style with
`v` starting/ending selection.

BUG: 100317
2022-10-03 10:46:46 +00:00
Tomaz Canabrava
6adbc55310 Don't crash on Screen.cpp 2022-09-07 11:20:13 +02:00
Tomaz Canabrava
25e2a9f6f9 Remove level of indentation
We can always return on the if, and remove the else.
2022-09-07 10:08:21 +02:00
Christoph Cullmann
bec7a69c11 fix Qt 6 compile 2022-08-27 23:36:39 +02:00
Matan Ziv-Av
a4681775ae Modify setDefaultRendition() to reset the underline color. 2022-08-26 19:24:56 +00:00
Matan Ziv-Av
76f879cd70 Draw characters in exact positions
QT can't be made to draw monospaced text (if the font does not cooperate),
so avoid combining characters, using a QPainter::drawText() call for each
character.

For bidi text support this change requires konsole to reorder and reshape
the characters. This is done using the ICU library (which QT also uses).

This change allows for some improvements related to text rendering:

- More precise bidi reordering, which is no longer changed by characters'
  attributes and selection.
- underlines drawn separately from the text, allowing for differing
  underline modes (double, curly, dashed, dotted, colored).
- Overriding font for emoji characters.

This commit fixes a few bugs and addresses a lot more:

Feature requests: More standard conforming RTL and various underlines:
BUG: 403729
BUG: 387811

Using non-monospace font:
BUG: 416508
BUG: 452087
BUG: 425973
BUG: 430822
BUG: 442742
BUG: 441037
BUG: 430822



Emoji:
BUG: 440070
CCBUG: 450017
CCBUG: 445846
CCBUG: 453086

Regression: devanagari rendering
CCBUG: 381593
CCBUG: 451716
2022-08-26 19:24:56 +00:00
Matan Ziv-Av
4e875cdfdd Prevent _replModeStart line number from becoming negative
Hopefully, this solves:
BUG: 457920
BUG: 458015
2022-08-25 19:47:45 +00:00
Matan Ziv-Av
24b0c08d9f Fix three coverity issues
Reported here:
https://mail.kde.org/pipermail/konsole-devel/2022-July/041429.html

- Use delete[] to free array allocated with new.
- Don't separate two cases which are handled identically.
- In vt100 parsing state machine no need to handle in specific states
  characters which are handles identically in all states.
2022-07-18 14:57:25 +00:00
Harald Sitter
87e27eb811 automatic clang-format run (clang 14) 2022-07-11 11:43:02 +02:00
Matan Ziv-Av
9333d6713a Add semantic integration copy actions
- Selecting Copy (or pressing ctrl-shift-c) when there is no selection
  selects current output if current mode is output, current input if
  current mode is input and input is non-empty, and last output if current
  input is empty.
- Ctrl + mouse triple click selects the pointed input/output/prompt.
- There is also a fix that was missed in previous patch for keeping
  track of current semantic mode through scrolls.
2022-07-04 23:53:48 +03:00
Matan Ziv-Av
5389ec11b0 Fix bugs in semantic shell integration
Bugs reported here:
https://invent.kde.org/utilities/konsole/-/merge_requests/691#note_480025
- Properly ignore OSC parameters for now. (later we'll support some).
- Handle Input end for when command gets shorter.
- Always draw separating line in foreground color
- Don't group characters of different REPL type.
- Don't reset double width/height attributes of erased lines.
2022-07-03 21:40:56 +03:00
Matan Ziv-Av
d67de797b6 Allow filtered copy to clipboard
This adds three copy actions:
- Copy only user input
- Copy only command output
- Copy both (filter out shell prompts).
2022-07-03 07:58:54 +00:00
Matan Ziv-Av
c4779f359b Add scroll to previous/next prompt
When using semantic shell integration (OSC 133), ctrl+shift+PgUp/Down
scrolls up down to the next prompt.
2022-07-03 07:58:54 +00:00
Matan Ziv-Av
cfaf997eba Add semantic shell integration
- Add `OSC 133 ; *` escape sequences (where * stands for one of
  A,B,C,D,L,P. For the shell to report text mode
  (one of prompt/input/output).
- Store the mode of each character written to the screen.
- Replace isRealCharacter field in Character with flags.
- Store line length in _lineProperties array.
2022-07-03 07:58:54 +00:00
Matan Ziv-Av
59290e12af Add a new rendition flag RE_TRANSPARENT
This flag is used for cells where the background is not drawn
unlike RE_CONCEAL, which draws background, but not foreground.

This flag is used for cells where an unmanaged image is placed.
2022-06-20 21:38:25 +00:00
Ahmad Samir
7522686088 Use cmakedefine01
This way we get a build time warning if the var isn't defined at all, e.g.
a missing check_include_files() CMake call.
2022-06-13 19:21:52 +00:00
Matan Ziv-Av
37b9f9e363 Manage graphics placements vertical position on text reflow.
When a line is reflowed then the vertical position of all
graphics placements above or below it (as appropriate) are
adjusted, so they remain in the same place relative to the
text lines.
2022-06-10 14:25:03 +00:00
Kurt Hindenburg
a5d69875a4 Fix comment spelling error 2022-05-27 13:10:32 -04:00
Kurt Hindenburg
eb834ca2f7 Give loop variables unique names to avoid shadowing 2022-05-26 11:15:48 -04:00
Luis Javier Merino Morán
836b1d9814 Selecting past last char -> extend to last column
When selecting past the last character, extend the selection to the last
column.  This allows the user to know when the selection has extended
past the last character on a line, even in the presence of trailing
spaces, and will get a newline added to the last line.

This is the behavior of xterm, VTE and rxvt.  mlterm doesn't allow
selections to extend past the last non-space character on a line.

BUG: 413426
CCBUG: 158726
2022-05-26 08:12:52 +00:00
Luis Javier Merino Morán
9046680f5a Ignore non-real chars for selection in history
Commit e8f77101 did this for screen lines.  Do it also for lines in the
history buffer.
2022-05-26 08:12:52 +00:00
Luis Javier Merino Morán
4e69f47b06 Respect Trim Trailing Space also in history buffer
The TrimTrailingSpacesInSelectedText profile option was not being
respected when selecting text in the history buffer.
2022-05-26 08:12:52 +00:00
Luis Javier Merino Morán
9b364450f0 Remove unused include 2022-05-26 08:12:52 +00:00
Luis Javier Merino Morán
d2ca202abd Fix scroll position jumps regression
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.

Very similar to the regression fixed at 7a1e4768, only this one is about
keeping the scroll position on the presence of scroll, and that other
one is about keeping the selection.

Thanks to the bug reporters Michael and Luke-Jr for the heads-up.

BUG: 452955
BUG: 453112
2022-05-24 12:51:32 +02:00
Martin T. H. Sandsmark
ec64ccd352 the url extractor kills performance a bit, so skip it if we can 2022-05-23 08:45:27 +00:00
Matan Ziv-Av
fac05b712d Correctly fill the cell with background color for text drawn above images with negative z-index
Still needs some work.
2022-05-23 08:32:41 +00:00
Luis Javier Merino Morán
e8f7710180 Do not count trailing empty cells on selections
When selecting, the last line gets an added newline if the characters
returned from copyLineToStream() are less than the cells selected on that
last line.

A weird behaviour was that after running:

printf '                   v\n'
printf '\e[KSELECT ME\n'
printf '\e[31m\e[Kselect me\n'
printf '\e[0m                   ^\n'

selecting "SELECT ME          " would add a newline, while
selecting "select me          " would not add a newline.

This is a side-effect of clearImage() resizing lines which end with
spaces with the default rendition, so selecting the "SELECT ME" line
would get a count of 9 characters, which would make selecting more than
the initial 9 characters add a newline, while the "select me" line would
have additional spaces with isRealCharacter == false and a non-default
rendition.

Solve it but making copyLineToStream() not count and not pass to
PlainTextDecoder trailing characters where isRealCharacter == false.
2022-05-23 01:30:00 +00:00
Luis Javier Merino Morán
4e0bcd4edb Set default rendition before clearing the screen
Otherwise, weirdness ensues.  e.g. if you do:

seq 1 $((LINES)); printf '\e[31m\ec'

and try to select the blank lines, the selection shows the previous
rendition color.
2022-05-23 01:30:00 +00:00
Luis Javier Merino Morán
9dadb7b562 Fix regression preserving tcsh command prompt
Commit c3b3ef19 introduced a regression when invoking the
clear-history-and-reset action.  While RIS (Reset to Initial State) is
specified in DEC STD-070 as homing the cursor, konsole has grown some
hacks in the name of usability to preserve the command prompt line.

For a long time, it has sent two SIGWINCH with changed sizes after clear
and reset actions to force the shell to redraw the prompt (see d346a2cc,
temporarily disabled on 5d61b69e and re-added on 82778e87), which works
for bash, zsh, ksh, ...

tcsh doesn't redraw its prompt on SIGWINCH, but commit b8e96bcd modified
Screen::refresh() so instead of clearing the entire screen and homing
the cursor, it scrolled up everything but the last (usually the prompt)
line.

So, keep that last hack when called from clear-history-and-reset, and
behave as specified on DEC STD-070 otherwise.

Note that other ways of clearing the screen don't need hacks, e.g.
Ctrl-L, if handled at all, is handled by the shell, which then redraws
its prompt.  Calling "clear" or invoking "printf '\ec'" will result in
the shell redrawing its prompt in the usual way.

BUG: 453568
2022-05-16 22:51:53 +00:00
Heiko Becker
f6310c2b79 Detect the presence of malloc_trim to fix the build with musl
malloc_trim is indeed a GNU extension, but an extension of glibc.
Relying on __GNUC__ unfortunately doesn't help with that. Check for
the actual presence of malloc_trim with cmake's check_function_exists
instead.
This fixes the build with musl libc, which doesn't come with
malloc_trim.

Co-authored-by: Ahmad Samir <a.samirh78@gmail.com>
2022-04-26 14:18:29 +02:00
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