Commit graph

331 commits

Author SHA1 Message Date
Daniel Eklöf
cb2a64c585
csi: don't allow client app to enable grapheme-shaping when disabled at compile-time
Closes #2039
2025-04-19 13:35:06 +02:00
Daniel Eklöf
4f11d6086f
DECSCUSR+DECRQSS: treat hollow cursor as a block cursor
If the user has configured cursor.style=hollow, make DECSCUSR 1/2 set
the cursor to hollow rather than block, and make DECRQSS DECSCUSR
respond as if cursor.style=block.

The idea is to not expose the hollow variant in DECSCUSR in any way,
to avoid having to extend it with custom encodings.

Another way to think about it is this is just a slightly more
discoverable way of doing:

    cursor.style=block
    cursor.block-cursor-is-hollow=yes
2025-02-21 08:03:41 +01:00
Daniel Eklöf
88dcde3ed8
term: insert-mode: handle combining characters correctly
When the client application emits combining characters, for example
multi-codepoint emojis, in insert-mode, we ended up pushing partial
graphemes to the right, for each codepoint, resulting in too many
cells (and with the wrong content) being inserted.

The fix is fairly simple; don't "insert" when appending characters to
an existing grapheme cluster.

This isn't something we can detect easily in print_insert() (it would
require us to do grapheme clustering again). Fortunately, we do have
the required information in action_utf8_print(). So, pass this
information as a boolean to term_print().

Closes #1947
2025-02-06 07:37:55 +01:00
Daniel Eklöf
8e425c4e97
csi: ignore 'CSI 21 t' - report window title
It's not widely used (don't know _any_ application that uses it), and
can be used to trick users to run unwanted commands.
2025-01-07 13:01:15 +01:00
Daniel Eklöf
9151685d04
csi: revert implementation of CSI 20 t 2024-09-13 09:04:18 +02:00
Daniel Eklöf
7984f08925
osc: OSC-1 does not set the icon, it sets the icon _label_
In fact, there appears there *is* no escape sequence to set the icon.

Keep most of the logic in place, but in practice, we'll always set the
icon to the app-id. That is, at startup, we set it to the configured
app-id (either from config, or the command line).

OSC-176, which sets the app-id, also updates the icon (to the app-id).
2024-09-13 09:04:18 +02:00
Daniel Eklöf
97ec375c67
toplevel-icon: implement OSC-1, CSI 20/21/22/23 t
* The toplevel icon is now set to the app-id, unless "overridden" by
  OSC-1 or OSC-0.
* Implemented OSC-1
* OSC-0 extended to also set the icon
* Implemented CSI 20 t - report window icon
* Implemented CSI 21 t - report window title
* Implemented CSI 22 ; 1 t - push window icon
* Implemented CS 23 ; 1 t - pop window icon
* Extended CSI 22/23 ; 0 t to also push/pop the icon
* Verify app-id set by OSC-176 is valid UTF-8
* Verify icon set by OSC-0/1 is valid UTF-8
2024-09-13 09:04:17 +02:00
Craig Barnes
d4a1283797
xsnprintf: various improvements related to xvsnprintf() and xsnprintf()
Summary of changes:

* Make xvsnprintf() static
* restrict-qualify pointer arguments (as done by the libc equivalents)
* Make comments and spec references more thorough
* Remove pointless `n <= INT_MAX` assertion (see comment)
* Use FATAL_ERROR() instead of xassert() (since the assertion is inside
  a shared util function but the caller is responsible for ensuring the
  condition holds true)
* Change some callers to use size_t instead of int for the return value
  (negative returns are impossible and all subsequent uses are size_t)

The updated comments and code were taken (and adapted) from:

49260bb154/src/util/xsnprintf.c (L6-50)

This work was entirely authored by me and I hereby license this
contribution under the MIT license (stated explicitly, so that
there's no ambiguity w.r.t. the original license).
2024-09-13 09:01:15 +02:00
Daniel Eklöf
a9e462d952
Remove a number of unused includes 2024-08-02 08:28:13 +02:00
Daniel Eklöf
38461eef6f
csi: in-band window resize notifications, private mode 2048
This implements
https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83,
in-band window resize notifications.

When user enables private mode 2048 (in-band resize
notifications), *always* send current size, even if the mode is
already active.

This ensures applications can rely on getting a reply from the
terminal.
2024-07-19 06:54:32 +02:00
Daniel Eklöf
22c8637610
osc: extend damage-cells-by-color to default fg/bg as well
When changing part of the color palette, through either OSC-4, or
OSC-10 and OSC-11 (and the corresponding reset OSCs: 104, 110 and
111), only dirty affected cells.

We've always done this, but only for OSC-4.

This patch breaks out that logic, and extends it to handle default
fg/bg too.

It also fixes a bug where cells with colored underlines were not
dirtied if the underline was the only part of the cell that was
affected by a OSC-4 change.
2024-07-03 10:53:33 +02:00
Daniel Eklöf
dd58dad15a
csi: redraw margins after restoring the palette 2024-07-03 09:47:51 +02:00
Daniel Eklöf
dd6fc99ae1
csi: implement XTPUSHCOLORS+XTPOPCOLORS+XTREPORTCOLORS
The documentation of these sequences are vague and lacking, as is
often the case with XTerm invented control sequences.

I've tried to replicate what XTerm does (as of xterm-392).

The stack represents *stashed/stored* palettes. The currently active
palette is *not* stored on the stack.

The stack is dynamically allocated, and starts out with zero elements.

Now, XTerm has a somewhat weird definition of "pushing" and "popping"
in this context, and the documentation is somewhat misleading.

What a push does is this: it stores the current palette to the stack
at the specified slot. If the specified slot number (Pm) is 0, the
slot used is the current slot index incremented by 1.

The "current" slot index is then set to the specified slot (which is
current slot + 1 if Pm == 0).

Thus, "push" (i.e. when Pm == 0 is used) means store to the "next"
slot. This is true even if the current slot index points into the
middle of stack.

Pop works in a similar way. The palette is restored from the specified
slot index. If the specified slot number is 0, we use the current slot
index.

The "current" slot index is then set to the specified slot -
1 (current slot - 1 if Pm == 0).

XTREPORTCOLORS return the current slot index, and the number of
palettes stored on the stack, on the format

    CSI ? <slot index> ; <palette count> # Q

When XTPUSHCOLORS grows the stack with more than one element (i.e. via
a 'CSI N # P' sequence), make sure *all* new slots are initialized (to
the current color palette). This avoids uninitialized slots, that
could then be popped with XTPOPCOLORS.

Closes #856
2024-07-03 09:47:30 +02:00
Daniel Eklöf
e708d19ea3
csi: implement SGR 21, double underlines 2024-07-03 09:46:41 +02:00
Craig Barnes
674a535fc3 Rename various uses of "curly" in the source code with "underline"
Since "curly" could make it seem as if all underline styles are curled
(to people unfamiliar with the codebase), whereas in reality only 1 is.
2024-07-01 20:00:16 +01:00
Daniel Eklöf
5e046e6a84
csi: sgr_reset(): avoid using memset()
This _should_ be what the compiler does anyway (i.e. it _should_
replace the memset() with inline MOVs). But let's be sure.
2024-06-26 18:39:24 +02:00
Daniel Eklöf
48cf57818d
term: performance: use a bitfield to track which ascii printer to use
The things affecting which ASCII printer we use have grown...

Instead of checking everything inside term_update_ascii_printer(), use
a bitfield.

Anything affecting the printer used, must now set a bit in this
bitfield. This makes term_update_ascii_printer() much faster, since
all it needs to do is check if the bitfield is zero or not.
2024-06-26 18:39:24 +02:00
Daniel Eklöf
a45ccfaed0
csi: remove debug log 2024-06-26 18:39:23 +02:00
Daniel Eklöf
32effc6657
csi: wip: styled underlines
This is work in progress, and fairly untested.

This adds initial tracking of styled underlines. Setting attributes
seems to work (both color and underline style). Grid reflow has *not*
been tested.

When rendering, style is currently ignored (all styles are rendered as
a plain, legacy underline).

Color however, *is* applied.
2024-06-26 18:39:23 +02:00
Daniel Eklöf
8716ca5784
url-mode: disable IME mode while URL-mode is active
This prevents the IME from stealing "our" key-presses, and thus
preventing the user from opening URLs.

Closes #1718, hopefully.
2024-05-21 08:37:39 +02:00
Daniel Eklöf
c4f1380943
config: add cursor.blink-rate option
The default is 500ms, which corresponds to the old, hardcoded default.

Closes #1707
2024-05-20 09:17:42 +02:00
Craig Barnes
27330a5dd6
csi: indicate "permanently reset" for DECRQM queries of mode 67 (DECBKM)
This allows dynamic querying for the equivalent of terminfo's "kbs"
capability.
2024-03-16 15:36:00 +01:00
Daniel Eklöf
712bc95db3
csi: the CSI-t family of queries now report unscaled pixel values
Before this patch, we reported scaled pixel values. This was rather
useless, since applications have no way of getting the scaling factor,
to "scale up" e.g. images.

Furthermore, the most common use of these queries are probably to
calculate the dimensions to use when emitting sixels.

Closes #1643
2024-03-14 07:26:37 +01:00
Daniel Eklöf
e2b3eb91dd
csi: params_to_rectangular_area(): ensure left/right is within bounds 2024-03-10 17:37:11 +01:00
Daniel Eklöf
6a01642a6f
csi: DECCARA+DECRARA: dirty cells 2024-03-07 16:25:04 +01:00
Daniel Eklöf
d6c5bc3262
csi: DECRARA: fix comment: DECCARA -> DECRARA 2024-03-07 16:24:33 +01:00
Daniel Eklöf
f5c574cd94
csi: DECCRA: no need for a counter here 2024-03-07 16:24:33 +01:00
Daniel Eklöf
23908d9277
term_fill(): change ‘character’ parameter from char -> uint8_t 2024-03-07 16:24:33 +01:00
Daniel Eklöf
b3a84ba71b
term: modify term_fill() to optionally reset the SGR attributes 2024-03-07 16:24:33 +01:00
Daniel Eklöf
189cfd717f
term: replace term_put_char() with term_fill() 2024-03-07 16:24:33 +01:00
Daniel Eklöf
1b66c6a3ac
csi: rectangular: add helper function params_to_rectangular_area()
This functions reads the four top/left/bottom/right parameters,
validates them, and converts relative row numbers to absolute.

Returns true if the params are valid, otherwise false.
2024-03-07 16:24:33 +01:00
Daniel Eklöf
95293f142a
csi: add ‘28’ (rectangular edit) to primary DA response 2024-03-07 16:24:33 +01:00
Daniel Eklöf
926d88fd30
csi: implement rectangular edit escapes
* DECCARA - change attributes in rectangular area
* DECRARA - reverse attributes in rectangular area
* DECCRA - copy rectangular area
* DECFRA - fill rectangular area
* DECERA - erase rectangular area

Not implemented:

* DECSERA - selective erase rectangular area
2024-03-07 16:24:33 +01:00
Craig Barnes
fa01bf2b75 csi: support DECRQM queries for ECMA-48 (SM/RM) modes
This is in addition to the existing support for DECRQM queries
of DEC private modes.
2024-02-11 15:09:28 +00:00
Daniel Eklöf
7999975016
Don't use fancy Unicode quotes, stick to ASCII 2024-02-06 12:36:45 +01:00
Craig Barnes
44c0cf594b
csi: simplify handling of Set/Reset Mode (SM/RM) sequences 2024-01-27 08:43:32 +01:00
Daniel Eklöf
7fcbca808b
csi: decrqm: 2027: permanently disabled when grapheme-width-method != double-width 2023-09-25 16:50:50 +02:00
Daniel Eklöf
4eef001d58
csi: implement DECSET/DECRST/DECRQM 2027 - grapheme cluster processing
This implements private mode 2027 - grapheme cluster processing, as
defined in the "Terminal Unicode Core"[1] specification.

Internally, we just flip the already existing option "grapheme
shaping". Since it's now runtime changeable, we need a copy of it in
the terminal struct, rather than referencing the conf object.

[1]: 13fc5a8993/spec/terminal-unicode-core.tex (L50-L53)
2023-09-25 16:50:44 +02:00
Daniel Eklöf
613c61abb4
scaling: always round the scaling factor when converting to int
* In all calls to wl_subsurface_set_position()
* (wp_viewport_set_destination() already does this)
* Whenever we use the scale to calculate margins (search box,
  scrollback indicator etc)
* Since the scaling factor is stored as a float (and not a double),
  use roundf() instead of round()
2023-07-25 16:48:50 +02:00
Daniel Eklöf
c1f374cc8d
term: convert ‘scale’ to a float 2023-06-29 15:38:22 +02:00
Daniel Eklöf
2c0c4ce821
csi: CHA+HPA (cursor horizontal absolute): use term_cursor_col() 2023-06-20 14:55:32 +02:00
Daniel Eklöf
dc7642f2a5
csi: implement "CSI ? m" 2023-04-26 18:30:09 +02:00
Daniel Eklöf
f114068a46
csi: DECCOLM+DECSCLM: remove all support
We don’t support neither 132 column mode, nor smooth scrolling. Thus
it makes little sense to recognize these control condes.

Note that while XTerm does support 132 columns, it is disabled by
default. In this mode, XTerm also doesn’t trigger the
side-effects (i.e. clearing the screen).

Closes #1265
2023-03-31 13:16:43 +02:00
Harri Nieminen
ae26915916 fix typos 2023-03-29 00:45:18 +03:00
Daniel Eklöf
0fc8b65a2b
selection: selection_on_rows(): typo: row_start -> row_end
This fixes an issue where selections in the scroll margins were not
detected correctly. This meant they weren’t canceled as they should
have been, which in turn caused a visual glitch where text appeared to
be selected, but were in fact not.
2022-11-24 19:18:20 +01:00
Craig Barnes
46f6bad728
csi: reply with 4 instead of 2 for DECRQM queries of unsupported modes
The status value 4 means "permanently reset", as opposed to 2, which
means "reset". The former implies that there's no way to enable the
mode because it's unsupported (but recognized).

Note: this commit also fixes an unrelated typo in CHANGELOG.md.
2022-09-18 17:55:03 +02:00
Daniel Eklöf
c311229b9e
csi: damage *viewport* when exiting the alt screen
This fixes a redraw issue when the normal screen were somewhere in the
scrollback history when exiting the alt screen.
2022-09-06 17:37:19 +02:00
Daniel Eklöf
87e4004960
csi: clamp color index for ‘CSI 38/48 ; 5 ; idx m’ sequences
Indexed color values are stored in the cell attributes as color
indices (into the 256-color table). However, the index from the CSI
was not validated in any way, meaning you can do something like this:

  echo -e ‘\e[38:5:1024m CRASH \e[m’

and foot will crash on an out-of-bounds access.

Fix by clamping the color index.

Closes #1111
2022-07-22 10:44:33 +02:00
Daniel Eklöf
8485cdaaaa
csi: implement CSI > 4n (reset modifyOtherKeys) 2022-04-19 17:25:06 +02:00
Craig Barnes
856086bbbe
csi: reduce duplication in code handling SGR 38 and 48 sequences 2022-04-11 14:20:11 +02:00