126 Commits

Author SHA1 Message Date
Gregory Anders
1c0b79c40f core: separate default colors from modifiable colors
Default colors are those set by the user in the config file, or an
actual default value if unset. The actual colors are modifiable and can
be changed using the OSC 4, 10, and 11 sequences.
2023-11-09 14:08:14 -06:00
Gregory Anders
006e93bd08 core: implement setting colors with OSC 4, 10, and 11 2023-11-09 11:59:20 -06:00
Mitchell Hashimoto
4c45bfec9e terminal: improve some debug logging 2023-10-27 09:14:29 -07:00
Mitchell Hashimoto
9c165ecbd2 terminal: clamp cursor left above scroll region with XTREVWRAP2
Fixes a crash found through fuzzing. This crash is also exhibited in
xterm (as of v384). The issue arises when you set the cursor above the top
scroll margin, then issue a large cursor left (CSI D) with extended reverse
wrap (?1045) set. Extended reverse wrap loops back until it reaches the top
scroll then wraps around. But since the cursor is before the top scroll,
xterm just arbitrarily moves back into negative row numbers, which reads into
bad memory.

We decided to fix this by clamping to (0,0) and exiting because this
will mimic the xterm behavior for valid values of cursor left count
(prior to crashing).
2023-10-26 22:38:33 -07:00
Mitchell Hashimoto
28aace4393 Merge pull request #728 from mitchellh/cimgui
Terminal Inspector v1
2023-10-26 10:12:39 -07:00
Mitchell Hashimoto
0baf3522b4 terminal: bring back unimplemented logs 2023-10-26 09:53:57 -07:00
Nameless
49f1866f28 add tests for fuzzed results, clean up unimplemented osc warning 2023-10-25 11:44:16 -05:00
Mitchell Hashimoto
7b2af3a039 inspector: start termio log 2023-10-24 15:27:17 -07:00
Mitchell Hashimoto
62475fd709 terminal: ICH should only run with no intermediates 2023-10-24 09:43:06 -07:00
Mitchell Hashimoto
de1ed071ad termio: configure OSC parser with an allocator 2023-10-15 08:41:38 -07:00
Mitchell Hashimoto
392da475e1 terminal: XTSHIFTESCAPE 2023-10-11 21:49:04 -07:00
Mitchell Hashimoto
7a8f2bfed6 terminal: decscusr 2023-10-10 12:24:11 -07:00
Mitchell Hashimoto
f216609662 terminal: RIS should reset tabstops, ESC ? W should reset every 8
Fixes #648

Two issues here:

  - RIS should've been resetting the tabstops to every 8, but was
    clearing all tabstops.

  - `ESC ? W` should've reset tabstops to every 8, but was clearing
    all tabstops.
2023-10-10 09:02:22 -07:00
Mitchell Hashimoto
2354454907 terminal: set left and right margins, left and right margin mode 69 2023-10-09 21:20:15 -07:00
Mitchell Hashimoto
9c45c6a3d1 terminal: handle ansi vs dec mode
Previously, we just ignored ansi vs dec modes (`?`-prefix) and just
responded to both requests most of the time using the number as the
unique value. This _kind of works_ because almost all DEC modes do not
overlap with ANSI modes, but some overlap (i.e. `insert`, ANSI mode 4).

This commit properly separates ANSI vs DEC modes and updates all of our
terminal sequences to handle both (where applicable -- some sequences
are explicitly DEC-only).
2023-10-09 16:01:08 -07:00
Mitchell Hashimoto
ed23f2f1d0 terminal: implement DECID (ESC Z) 2023-10-09 09:43:28 -07:00
Mitchell Hashimoto
b927760149 terminal: HPR, VPR 2023-10-07 09:32:58 -07:00
Mitchell Hashimoto
c2af7b60d0 terminal: FF (0x0D) also invokes LF 2023-10-06 12:00:18 -07:00
Mitchell Hashimoto
823f47f695 termio: hook up dcs callbacks 2023-09-27 13:32:00 -07:00
Mitchell Hashimoto
032fcee9ff terminal: DCS handler, XTGETTCAP parsing 2023-09-27 12:07:31 -07:00
Mitchell Hashimoto
5528580a29 terminal: DECSED, DECSEL parsing, tests 2023-09-25 10:56:59 -07:00
Mitchell Hashimoto
8137a66ef6 terminal: CSI Ps " q for setting DEC protected mode 2023-09-25 10:56:59 -07:00
Mitchell Hashimoto
92e98d34b5 terminal: CSI E and F 2023-09-21 08:21:32 -07:00
Tim Culverhouse
fbe030d85a terminal: respond to XTVERSION query
XTVERSION (CSI > 0 q) is used by some libraries to identify the terminal
+ version. Respond to this query with `ghostty {version_string}`. There
is no formal format for this response. A roundup of a few tested
terminals show two primary formats. This patch opts to save one byte and
use the `name SP version` semantics.

foot: foot(version)
xterm: XTerm(version)
contour: contour version
wezterm: wezterm version

Reference: https://github.com/dankamongmen/notcurses/blob/master/TERMINALS.md#notes-for-terminal-authors
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2023-09-20 19:06:28 -05:00
Mitchell Hashimoto
8694d29bd0 terminal: ignore CSI S with intermediates 2023-09-17 09:39:03 -07:00
Mitchell Hashimoto
19ef4a22a9 terminal: stylistic changes for OSC terminators, 10/11 params 2023-09-14 13:12:41 -07:00
cryptocode
dc14ca86ca Review updates:
* Change state names to more human readable query_default_fg/bg
* Single-line state prongs
* String terminator is not an enum
* Removed `endWithStringTerminator` and added nullabe arg to `end`
* Fixed a color reporting bug, fg/bg wasn't correctly picked
2023-09-14 21:46:23 +02:00
cryptocode
a3696a9185 Implement OSC 10 and OSC 11 default color queries
These OSC commands report the default foreground and background colors.

Most terminals return the RGB components scaled up to 16-bit components, because some
legacy software are unable to read 8-bit components. The PR follows this conventions.

iTerm2 allow 8-bit reporting through a config option, and a similar option is
added here. In addition to picking between scaled and unscaled reporting, the user
can also turn off OSC 10/11 replies altogether.

Scaling is essentially c / 1 * 65535, where c is the 8-bit component, and reporting
is left-padded with zeros if necessary. This format appears to stem from the XParseColor
format.
2023-09-14 21:41:40 +02:00
Mitchell Hashimoto
cb2931cb27 rename cursor shape to mouse shape for OSC 22 2023-09-14 11:12:17 -07:00
Mitchell Hashimoto
7734bab8c4 terminal: cursor shape parsing, hook up to apprt callback 2023-09-14 10:12:38 -07:00
Mitchell Hashimoto
24af24a086 terminal: CSI q requires a space intermediate 2023-09-10 22:01:17 -07:00
Mitchell Hashimoto
f8335c10d8 terminal: disable noisy logs 2023-09-03 14:02:55 -07:00
Mitchell Hashimoto
cdf81b610d terminal: mark prompt continuation lines, end prompt clear at first
prompt
2023-09-03 14:00:56 -07:00
Mitchell Hashimoto
3b9d5d27ad terminal: implement DECRQM (request mode) 2023-08-28 08:50:11 -07:00
Mitchell Hashimoto
6e061fb344 termio/exec: process APC callbacks 2023-08-20 22:03:19 -07:00
Mitchell Hashimoto
29e3e79b94 terminal: parse APC strings 2023-08-20 22:03:19 -07:00
Mitchell Hashimoto
e7ab16f0e1 terminal: CSI < u defaults param to "1" if not set (pop kitty keyboard) 2023-08-20 22:02:12 -07:00
Mitchell Hashimoto
c8a07abdf3 terminal: ignore SOH/STX, bash sends this for some reason 2023-08-17 13:40:11 -07:00
Mitchell Hashimoto
af4ede40f1 terminal: implement CSI = u for setting kitty keyboard flags 2023-08-16 17:31:05 -07:00
Mitchell Hashimoto
a9d7e0eb7f terminal: parse kitty query, push, pop keyboard flags 2023-08-16 17:31:05 -07:00
Mitchell Hashimoto
06f82ad713 terminal: parse and handle save/restore mode (CSI ? s, CSI ? r) 2023-08-15 11:43:07 -07:00
Mitchell Hashimoto
951aa00c63 terminal: move to new modes struct 2023-08-15 11:30:33 -07:00
Mitchell Hashimoto
d27bc1f0fe termio: send VT220 device attributes on request, add secondary 2023-08-15 08:21:48 -07:00
Mitchell Hashimoto
a2310afa4e terminal: ignore ESC \ which enables ST mode since we're always in it 2023-08-13 15:52:38 -07:00
Mitchell Hashimoto
77df7a0e7f terminal: support disable modify key format sequence ESC[>n 2023-08-13 14:55:32 -07:00
Mitchell Hashimoto
66aa1d9be3 terminal: parse and handle set modify key format (ESC[>{a};{b}m) 2023-08-13 14:55:32 -07:00
Mitchell Hashimoto
d94474463b terminal: handle set application keypad mode (both ESC and modes) 2023-08-13 14:55:32 -07:00
Kevin Hovsäter
22b8173164 Fix typos 2023-08-08 14:27:34 +02:00
Mitchell Hashimoto
5e100a3b6b CSI r for top/bot margin must have no intermediates
We were incorrectly interpreting the restore mode CSI (`ESC [ ? r`) as
set top and bottom margin. We need to verify that there are no
intermediates.
2023-08-07 09:45:44 -07:00
Mitchell Hashimoto
e45c8d97d7 CSI for SGR only if there are no intermediates
Fixes #210

We were previously taking any `CSI <symbol> <data> m` as SGR. But SGR is
only if "symbol" is empty. There are other forms of `CSI m` that set the
intermediate symbol to `?` or `>` and we don't implement those. We
shouldn't treat that as a SGR attribute either.
2023-07-20 19:23:01 -07:00