Commit graph

270 commits

Author SHA1 Message Date
Daniel Eklöf
c3fda01554
csi: kitty: log flags after ‘update’ operation 2021-11-28 15:14:52 +01:00
Daniel Eklöf
ad2539af44
csi: kitty: s/mode/flags in debug logs 2021-11-28 15:14:52 +01:00
Daniel Eklöf
fec42e5941
kitty kbd: add flag state, implement push/pop/update/query 2021-11-28 15:14:40 +01:00
Daniel Eklöf
d46af6bd7a
term: track cell color source
Each cell now tracks it’s current color source:

* default fg/bg
* base16 fg/bg (maps to *both* the regular and bright colors)
* base256 fg/bg
* RGB

Note that we don’t have enough bits to separate the regular from the
bright colors. These _shouldn’t_ be the same, so we ought to be
fine...
2021-11-20 16:46:38 +01:00
Daniel Eklöf
4a74050999
input: add support for modifyOtherKeys=2
Similar to modifyOtherKeys=1 (foot’s default, and only, mode), except
that:

* All modifiers (and not just Ctrl) generate \E[27;m;n~ escapes
* Regular keys (with modifiers) also generate \E[27;m;n~ escapes (for
  example, C-h no longer generates ^H, but \E[27;5;104~)

For our keymap based lookups, this is handled by adding
MOD_MODIFY_OTHER_KEYS_STATE<N> variants.

For “generic” keys, we simply adjust the conditions for when to emit a
\E[27;m;n~ escape - the only requirement is that at least one modifier
is active.
2021-11-13 11:09:07 +01:00
Craig Barnes
6bd151438f csi: various, minor code/formatting improvements 2021-08-30 07:40:03 +01:00
Daniel Eklöf
5f0ceb72f1
csi: erase scrollback: cancel selection if it touches the scrollback
This breaks out the scrollback erasing logic for \E[3J from csi.c, and
moves it to the new function term_erase_scrollback(), and changes the
logic to calculate the start and end row (absolute) numbers of the
scrollback, and only iterate those, instead of iterating *all* rows,
filtering out those that are on-screen.

It also adds an intersection range check of the selection range, and
cancels the selection if it touches any of the deleted scrollback
rows.

This fixes a crash when trying to render the next frame, since the
selection now references rows that have been freed.

Closes #633
2021-07-18 16:14:21 +02:00
Daniel Eklöf
fcd9897342
csi: invert the meaning of DECSDM
There has been some confusion whether enabling DECSDM (private mode
80) enables or disables sixel scrolling.

Foot currently enables scrolling when DECSDM is set, and this patch
changes this, such that setting DECSDM now *disables* scrolling.

The confusion is apparently due to a documentation error in the VT340
manual, as described in
https://github.com/dankamongmen/notcurses/issues/1782#issuecomment-863603641.

And that makes sense, in a way: the SDM in DECSDM stands for Sixel
Display Mode. I.e. it stands to reason that enabling that disables
scrolling.

Anyway, this lead to https://github.com/hackerb9/lsix/issues/41, where
it was eventually proven (by testing on a real VT340), that foot, and
a large number of other terminals (including XTerm) has it wrong:
https://github.com/hackerb9/lsix/issues/41#issuecomment-873269599.
2021-07-14 19:17:44 +02:00
Daniel Eklöf
3adc3367e6
csi: implement XTVERSION (CSI > 0q)
This is a fairly new XTerm extension. The reply is on the format:

  DCS > | text ST

XTerm replies with ‘text’ = “XTerm(366)”.

Foot replies with ‘text’ = “foot(1.6.4)”

Closes #359
2021-06-13 17:19:41 +02:00
Daniel Eklöf
9929a5ce0a
csi: CHT: don’t alter the LCF flag
This makes us pass the vttest 11.5.4 (Test non-VT100 -> Test ISO-6429
cursor-movement -> CHT) test.
2021-06-08 19:53:26 +02:00
Daniel Eklöf
0febce9007
csi: IL+DL: move cursor to column 0
This fixes vttest 11.6.6.3

Test non-VT100 ->
Test ISO-6429 colors ->
Test of VT102-style features with BCE ->
Test Insert/Delete Char/Line
2021-06-08 19:52:35 +02:00
Daniel Eklöf
7ce767ab87
config: add ‘beam-thickness’ option
* Rename cursor.style value ‘bar’ to ‘beam’. ‘bar’ remains recognized,
  but should eventually be deprecated and then removed.
* Add ‘cursor.beam-thickness’ option, a pt-or-px value specifying the
  thickness of the beam cursor. Defaults to 1.5pt.
* Rename (and export) pt_or_px_as_pixels() to
  term_pt_or_px_as_pixels()
* Change term_pt_or_px_as_pixels() to round point values instead of
  truncating them.
2021-04-30 20:36:16 +02:00
Craig Barnes
f95d7d4684 csi: add support for DECSET 2026, as an alternative to BSU/ESU sequences
See: https://gitlab.freedesktop.org/terminal-wg/specifications/-/merge_requests/2#note_847720
2021-04-25 18:35:46 +01:00
Daniel Eklöf
d271119032
csi: update ASCII printer function pointer when switching to/from alt screen
This is necessary since switching screen may change how many sixels we
have in the scrollback.
2021-03-16 13:07:09 +01:00
Daniel Eklöf
60b3ccc641
term: runtime switch between a ‘fast’ and a ‘generic’ ASCII print function
term_print() is called whenever the client application “prints”
something to the grid. It is called for both ASCII and UTF-8
characters, and needs to handle sixels, insert mode and ASCII
vs. graphical charsets.

Since it’s on the hot path, this becomes unnecessarily slow.

This patch adds a “fast” version of term_print(), tailored for the
common case: ASCII characters in non-insert mode, without any sixels
and non-graphical charsets.

A new function, term_update_ascii_printer(), has been added, and must
be called whenever:

* The currently selected charset *index* changes
* The currently selected charset changes (from ASCII to graphical, or
  vice verse)
* Sixels are added to the grid
* Sixels are removed from the grid
* Insert mode is enabled/disabled
2021-03-16 08:45:18 +01:00
Daniel Eklöf
849427bf10
sixel: implement private mode 80 - sixel scrolling
When enabled (the default), sixels behave much like normal output; the
start where the cursor is, and the cursor moves with the
sixel. I.e. after emitting a sixel the cursor is left after the image;
either to the right, if private mode 8452 is enabled, or otherwise on
the next line. Terminal content is scrolled up if the sixel is larger
than the screen.

When disabled, sixels *always* start at (0,0), the cursor never moves,
and the terminal content never scrolls.

In other words, the ‘disabled’ mode is a much simpler mode.

All we need to do to support both modes is re-write the sixel-emitting
loop to:

* break early if we’re “out of rows”, i.e. we’ve reached the bottom of
  the screen.
* not linefeed, or move the cursor when scrolling is disabled

This patch also fixes a bug in the (new) implementation of private
mode 8452.

When emitting a sixel, we may break it up into smaller pieces, to
ensure a single sixel (as tracked internally) does not cross the
scrollback wrap-around.

The code that checked if we should do a linefeed or not, would skip
the linefeed on the last row of *each* such sixel piece. The correct
thing to do is to skip it only on the last row of the *last* piece.

I chose not to fix this bug in a separate patch since doing so would
have meant re-writing it again when implementing private mode 80.
2021-02-26 09:28:03 +01:00
Daniel Eklöf
03c675c6e2
sixel: implement private mode 8452 - cursor positioning after sixel
When disabled (the default), the cursor is positioned on a new line
after emitting a sixel image.

When enabled, the cursor is positioned to the right of the sixel
image.

Closes #363
2021-02-23 10:36:02 +01:00
Daniel Eklöf
4aa980a6a2
sixel: implement private mode 1070 - private color palette
When enabled (the default), sixels use private color registers. That
is, the color palette from the last sixel is *not* re-used.

When disabled, sixels share (i.e. re-use) the same color palette.

Closes #362
2021-02-23 09:40:22 +01:00
Daniel Eklöf
8658ab4bed
csi: ‘CSI 13 ; 2 t’ reply is now (0,0)
Foot previously responded with window local coordinates.

But, XTerm responds with screen *absolute* coordinates. This isn’t
possible under Wayland, thus we now report (0,0) instead. Same as we
do for ‘CSI 13 ; 0 t’.
2021-02-16 14:31:46 +01:00
Daniel Eklöf
fcb524fc72
csi: add 47+1047 (alt screen) to DECRQM 2021-02-09 20:02:29 +01:00
Craig Barnes
e56136ce11 debug: rename assert() to xassert(), to avoid clashing with <assert.h> 2021-01-16 20:16:00 +00:00
Craig Barnes
22f25a9e4f Print stack trace on assert() failure or when calling fatal_error()
Note: this uses the __sanitizer_print_stack_trace() function from the
AddressSanitizer runtime, so it only works when AddressSanitizer is
in use.
2021-01-16 19:56:33 +00:00
Daniel Eklöf
e41654d4ea
csi: implement DECSET 47 - use alternate screen buffer 2021-01-16 13:34:40 +01:00
Daniel Eklöf
2a012f86d8
term: keep cursor state in grid, for now, but document that it _could_ be moved 2021-01-15 18:02:17 +01:00
Daniel Eklöf
a63e7983dd
csi: add support for ?1047 and ?1048
* 1047 enters/leaves the alt screen, but without saving/restoring the
  cursor.
* 1048 saves/restores the cursor
* 1049 is 1047+1048

Note: when xtsaving and xtrestoring 1048, why simply save/restore the
cursor. Without having read XTerms sources, this appears to be what it
is doing.
2021-01-15 17:09:15 +01:00
Daniel Eklöf
bae3c871bb
term/vt/csi: break out cursor save/restore to dedicated functions 2021-01-15 17:08:30 +01:00
Craig Barnes
3f4cfa338b Add xsnprintf() and remove some unnecessary strlen(3) calls 2021-01-14 21:30:06 +00:00
Daniel Eklöf
2e137c0a7e
vt: don’t ignore extra private/intermediate characters
Take ‘\E(#0’ for example - this is *not* the same as ‘\E(0’.

Up until now, foot has however treated them as the same escape,
because the handler for ‘\E(0’ didn’t verify there weren’t any _other_
private characters present.

Fix this by turning the ‘private’ array into a single 4-byte
integer. This allows us to match *all* privates with a single
comparison.

Private characters are added to the LSB first, and MSB last. This
means we can check for single privates in pretty much the same way as
before:

  switch (term->vt.private) {
  case ‘?’:
      ...
      break;
  }

Checking for two (or more) is much uglier, but foot only supports
a *single* escape with two privates, and no escapes with three or
more:

  switch (term->vt.private) {
  case 0x243f:  /* ‘?$’ */
      ...
      break;
  }

The ‘clear’ action remains simple (and fast), with a single write
operation.

Collecting privates is potentially _slightly_ more complex than
before; we now need mask and compare, instead of simply comparing,
when checking how many privates we already have.

We _could_ add a counter, which would make collecting privates easier,
but this would add an additional write to the ‘clean’ action which is
really bad since it’s in the hot path.
2020-12-16 14:30:49 +01:00
Daniel Eklöf
db097891f2
csi: implement DECRQM (DEC modes), for real
Previously, we always returned ‘2 - reset’, instead of the actual
state of the requested mode.
2020-12-16 13:57:40 +01:00
Daniel Eklöf
04703c07f0
csi: SGR 21 is “double underline”, not “disable bold” (according to ECMA-48) 2020-12-14 19:10:30 +01:00
Daniel Eklöf
9f321e6030
csi: fix sub-parameter versions of 38/48 SGR escapes
Well this is embarrassing; the sub-parameter versions of the 38/48 SGR
escapes all required an extra ‘:2’ that wasn’t supposed to be there,
causing all the other sub-parameters to be shifted one step to the
right.

That is, foot expected e.g. 38:2:2:r:g:b, or 38:2:5:idx when the
correct sequences are 38:2:cs:r:g:b and 38:5:idx.

I.e. I mixed up the color-space ID (cs) of 38:2 with *type* of color:
RGB or indexed.

In addition to fixing this, this patch also adds support for a
“bastard” version of the sub-parameter based RGB escapes, where the
color-space identifier has been left out: e.g. 38:2:r:g:b. This
sequence is invalid, but applications tend to “forget” the color-space
ID...
2020-12-12 20:55:31 +01:00
Daniel Eklöf
975e70dae1
csi: ‘CSI s’ and ‘CSI u’ now saves/restores attributes and charsets 2020-12-11 20:01:19 +01:00
Daniel Eklöf
15d20af2a2
config: add ‘notify’ to possible values for ‘bell’ in foot.ini
When `bell=notify`, foot will trigger a desktop notification when it
receives a BEL in an unfocused window.
2020-12-10 18:22:48 +01:00
Daniel Eklöf
0536bc41f4
csi: add DECSET 737769 - enables/disables IME input
73 77 69 = I M E
2020-12-07 20:44:12 +01:00
Craig Barnes
31c73f0cf0 csi: add new private mode that makes the Escape key emit "\E[27;1;27~"
This mode can be set by client programs with the DECSET, DECRST,
XTSAVE and XTRESTORE sequences by using 27127 as the parameter.

The sequence "\E[27;1;27~" is encoded in the same way as is done by
xterm's "modifyOtherKeys" mode. Even though xterm itself never emits
such a sequence for the Escape key, many programs already have
support for parsing this style of key sequence.
2020-11-29 04:04:57 +00:00
Daniel Eklöf
cb2f496269
term: split cursor blink state into two
There are two different escape sequences that can be used to set the
cursor blink state: ‘CSI ? 12 h/l’ and ‘CSI Ps SP q’.

Up until now, they both modified the same internal state in foot. This
meant you could enable a blinking cursor with e.g. ‘CSI ? 12 h’ and
then disable it with ‘CSI 2 SP q’.

Since the ‘CSI ? 12’ escapes are used in the civis/cnorm/cvvis
terminfo entries, applications often ended up disabling the blink
state on exit (typically be emitting ‘cnorm’), requiring users to
manually re-enable blinking.

By splitting the internal state into two separate states, we can
improve the situation.

The cursor will blink if at least one of the two have been enabled.

The setting in foot.ini sets the default state of the ‘CSI Ps SP q’
escape.

This means if the user has enabled blinking in the configuration, the
cursor will blink regardless of civis/cnorm/cvvis. Which probably is
what the user wants.

If the user has NOT enabled blinking, civis/cnorm/cvvis act as
intended: cvvis blink, civis and cnorm do not.

If an application overrides the cursor blink/style with ‘CSI Ps SP q’,
that will override the user’s setting in foot.ini. But most likely
that too is intended (for example, the user may have configured the
application to use a different cursor style). And, a well written
application will emit the ‘Se’ terminfo sequence on exit, which in
foot is defined to ‘CSI SP q’, which will reset both the style and
blink state to the user configured style/state.

Closes #218
2020-11-26 18:09:32 +01:00
Daniel Eklöf
360cc8e6de
term: remove read-only properties copied from the config
Use the config directly instead.
2020-11-26 18:08:28 +01:00
Daniel Eklöf
2382d6b448
csi: implement “CSI ? 1035” - toggle Num Lock override
This adds a num_lock_modifier state to the terminal, and hooks up
“CSI?1035h/l” to toggle it.
2020-11-11 18:26:47 +01:00
Daniel Eklöf
17761dce63
csi: implement ‘CSI ? 1042 h/l’ - enable/disable bell-is-urgent 2020-10-11 17:44:29 +02:00
Daniel Eklöf
5b0af8ed59
csi: only respond to Primary DA when Ps == 0 2020-10-09 18:53:00 +02:00
Daniel Eklöf
7c6686221f
bell: optionally render margins in red when receiving BEL
Add anew config option, ‘bell=none|set-urgency’. When set to
‘set-urgency’, the margins will be painted in red (if the window did
not have keyboard focus).

This is intended as a cheap replacement for the ‘urgency’ hint, that
doesn’t (yet) exist on Wayland.

Closes #157
2020-10-08 19:55:32 +02:00
Daniel Eklöf
71c54fb87c
csi: xtrestore: add ‘reverse wrap’ 2020-10-03 11:53:03 +02:00
Daniel Eklöf
060be30803
term: add private mode flag ‘’reverse-wrap’ 2020-10-02 21:29:56 +02:00
Craig Barnes
0e7723e75f csi: avoid using memcmp() to compare timespec structs
This struct may contain padding bytes, whose values are indeterminate
after any store operation[1]. It may also contain unnamed members,
whose values are always indeterminate[2]. Using memcmp() isn't a
reliable way to compare structs where either of these may be present.

[1]: ISO/IEC 9899:1999 §6.2.6.1, paragraph 6
[2]: ISO/IEC 9899:1999 §6.7.8, paragraph 9

See also:

* https://wiki.sei.cmu.edu/confluence/display/c/EXP42-C.+Do+not+compare+padding+data
* https://sourceware.org/git/?p=glibc.git;a=blob;f=time/bits/types/struct_timespec.h;hb=756c306502498f9
2020-08-23 03:08:35 +01:00
Craig Barnes
7c58648238 csi: add 2 missing "break" statements in csi_dispatch() 2020-08-18 20:49:44 +01:00
Daniel Eklöf
a48578c857
csi: xtrestore: add 'default' case
Don't call decset_decrst() with an unhandled parameter (and with
'enabled' uninitialized!)
2020-08-18 21:14:05 +02:00
Daniel Eklöf
79d20d75d2
csi: xtrestore: add missing break 2020-08-18 21:13:50 +02:00
Daniel Eklöf
22dcbeacb7
csi: xtsave/xtrestore: implement \E[?12s and \E[?12r
I.e. save/restore cursor-blink state.
2020-08-18 07:00:26 +02:00
Daniel Eklöf
15ae82e62e
csi: decset/decrst: only clear mouse tracking/reporting if mode matches
E.g. only set mouse reporting to NONE, if mouse reporting mode is SGR
and an DECRST SGR is issued.

Do *not* reset the mouse mode if e.g. mouse reporting mode is SGR and
an DECRST URXVT is issued.
2020-08-18 06:53:47 +02:00
Daniel Eklöf
23a5ff53eb
csi: implement XTRESTORE 2020-08-16 17:02:52 +02:00