1478 Commits

Author SHA1 Message Date
Mitchell Hashimoto
d7fcaefdf3 terminal: PageList.reset 2024-12-02 17:26:19 -05:00
Mitchell Hashimoto
d57d1d2395 terminal: failing tracked pin test on fullReset 2024-12-02 09:39:43 -05:00
Mitchell Hashimoto
853ba9e3c7 terminal: reset should preserve desired default mode values
Fixes #2857

Some terminal modes always reset, but there are others that should be
conditional based on how the terminal's default state is configured.
Primarily from #2857 is the grapheme clustering mode (mode 2027) which
was always resetting to false but should be conditional based on the
the `grapheme-width-method` configuration.
2024-11-29 14:42:01 -08:00
Mitchell Hashimoto
e20b27de84 terminal: eraseChars was checking wide char split boundary on wrong cell
Fixes #2817

The test is pretty explanatory. I also renamed `end` to `count` since I
think this poor naming was the reason for the bug. In `eraseChars`, the
`count` (nee `end`) is the number of cells to erase, not the index of
the last cell to erase.
2024-11-26 14:29:58 -08:00
Mitchell Hashimoto
039f9231de terminal: parse CSI 22/23 for push/pop title
Related to #2668

This just implements the VT stream parsing. The actual handling of these
events still needs to be done.
2024-11-13 19:49:45 -08:00
Mitchell Hashimoto
e225eb9eff terminal: OSC7 with empty URL resets the pwd to nil
When an empty string is given to OSC7, the pwd is reset to nil (as if
the terminal never received a pwd report to begin with). This is
analogous to how OSC0/2 reset the title to nil when given an empty
string.

This is practically useful for macOS because it allows our proxy icon to
also be reset instead of being stuck on the last known path.

This breaks from any known terminal behavior. As far as I can find, this
is totally unspecified so we're somewhat free to do what we want. I
don't think any terminal programs depend on this behavior, so I think
it's safe to change it.
2024-11-13 13:43:49 -08:00
Mitchell Hashimoto
067a36d67c termio: handle empty titles (OSC 0/2)
Fixes #2651

First, our OSC parser didn't allow blank OSC 0 or 2 requests. This
should be allowed and this fixes that with a test.

Second, it seems many terminals (iTerm2, Kitty) treat setting a blank
title as resetting to whatever the default title is rather than
explicitly setting it as blank. If a program wants a title to be blank
they should send a single space. This commit follows this behavior.
2024-11-13 12:12:43 -08:00
Mitchell Hashimoto
1335af3e4a terminal: change pagelist linked list to an intrusive linked list 2024-11-07 15:12:54 -08:00
Mitchell Hashimoto
aed51fd0b0 terminal: PageList rename "page" to "node" everywhere
This is more correct: a pagelist is a linked list of nodes, not pages.
The nodes themselves contain pages but we were previously calling the
nodes "pages" which was confusing, especially as I plan some future
changes to the way pages are stored.
2024-11-07 13:44:39 -08:00
Rick Calixte
e0c5bdc53b Terminal: Reinitialize screens on scrollback reset
When resetting the terminal screen, the memory buffer allocated for the
scrollback is now cleared by reinitializing the screen and falling back to the
current method if any of the attempts to reinitialize fail.

Closes #2464
2024-10-30 17:21:38 -04:00
Qwerasd
487f08b1dd fix(PageList, Page): fix off-by-1 in map capacity checks
We're already using `>=`, we don't need to also use `- 1`
2024-10-28 15:41:34 -07:00
Mitchell Hashimoto
6109edd00b terminal: refactor hyperlink memory management
Fixes #2500
Based on #2508

This separates out the concept of a "hyperlink" from a "hyperlink page
entry." The difference is that the former has real Zig slices into
things like strings and the latter has offsets into terminal page
memory.

From this separation, the Page structure now has an `insertHyperlink`
function that takes a hyperlink and converts it to a page entry.

This does a couple things: (1) it moves page memory management out of
Screen and into Page which is historically more appropriate and (2) it
let's us more easily test hyperlinks from the Page unit tests.

Finally, this PR makes some error sets explicit.
2024-10-28 15:30:04 -07:00
Marijn Besseling
4496e7d314 implement overline decoration (SGR 53/55) 2024-10-21 08:36:08 -04:00
Tim Culverhouse
93643d1741 sgr: add support for legacy double underline
SGR 21 is defined to be a double underline. This behavior is common
among many terminals, notably xterm.

References: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
2024-09-27 22:22:22 -05:00
Mitchell Hashimoto
fade882574 Merge pull request #2300 from vancluever/terminal-kitty-large-signed-ints
terminal/kitty: increase value buffer, make 'H' and 'V' i32
2024-09-25 09:41:40 -07:00
Chris Marchesi
861531a1fd terminal/kitty: increase value buffer, make 'H' and 'V' i32
This commit increases the value buffer to 11 characters - this is
technically what it should be to allow for large negative integers
(i.e., 2.4 billion plus the sign character).

Additionally corrected the types for 'H' (horizontal offset) and 'V'
(vertical offset) - these are supposed to be i32 versus u32.

Added some extra tests to test all of this stuff as well.

I've also added a few more tests to help track these cases.
2024-09-25 09:01:39 -07:00
Mitchell Hashimoto
f858ae13ae terminal: clarify comment 2024-09-21 21:05:46 -07:00
Mitchell Hashimoto
f0eb5d0d43 terminal: test for scenario where grow() has to prune with a single page
See comments in the test, also this:

> The scenario is if you adjustCapacity a page beyond a std_size then our
> precondition no longer holds. PageList.adjustCapacity makes no guarantee
> that the resulting capacity fits within a standard page size. It is in fact
> documented this way and that it is slow since we have to mmap out of our
> memory pool.
2024-09-21 21:05:01 -07:00
Khang Nguyen Duy
d5ab772b66 fix(terminal/PageList): ensure enough pages before first page reuse
Running alacritty/vtebench on some machines causes Ghostty to fail on
`assert(first != last)` when trying to grow scrollback. We now make sure
we have enough pages before trying to reuse pages.
2024-09-21 22:03:06 +07:00
Mitchell Hashimoto
39627e3221 termio: set pw input state on terminal and wake up renderer 2024-09-18 10:47:26 -07:00
Mitchell Hashimoto
15a9c191d3 terminal: avoid double free by resetting command to non-managed
Fixes a reported macOS crash. Test case shows how its possible.
2024-09-17 13:15:44 -07:00
Tim Culverhouse
723d79c9de graphics: set default transmission format as .rgba
The default format for transmission is defined as RGBA (f=32) in the
Kitty Graphics specification. When no format is specified, this can
result in an error for length checking.

Fixes: #2212
Reference: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference
2024-09-10 11:03:51 -07:00
Mitchell Hashimoto
4501991325 Merge pull request #2201 from qwerasd205/wide-boundary-conds
Wide cell boundary conditions in ECH & DCH + soft-wrap reset correctness
2024-09-06 19:00:15 -07:00
Qwerasd
5138801b7b comment 2024-09-06 18:03:56 -04:00
Qwerasd
9669332134 terminal: cursorResetWrap should not reset wrap_continuation 2024-09-06 17:57:14 -04:00
Mitchell Hashimoto
8f47581e22 terminal: add test for wide character on right margin boundary 2024-09-06 14:28:04 -07:00
Mitchell Hashimoto
f4052fd824 terminal: fix uninitialized memory access when kitty color protocol 2024-09-06 14:08:33 -07:00
Qwerasd
057f218c9e perf(terminal): specialize splitCellBoundary to cursor row
+ do some abstraction leakage in `cursorResetWrap`, since they're both
used in hot functions for TUI stuff so performance is important.
2024-09-06 13:26:57 -04:00
Qwerasd
8d12044f1d Terminal: fix ECH & DCH wide char boundary cond. behavior 2024-09-06 12:35:11 -04:00
Qwerasd
04271c6a07 test(Terminal): test ECH wide char boundary conditions 2024-09-06 12:35:11 -04:00
Qwerasd
1692a82b33 test(Terminal): test DCH wide char boundary conditions 2024-09-06 12:35:11 -04:00
Mitchell Hashimoto
738a4c568a terminal: do not reset OSC parser if its already empty
This is not a safe operation since the OSC parser has undefined memory
when it is in the empty state. This is on purpose for performance
reasons.
2024-09-05 16:53:34 -07:00
Mitchell Hashimoto
693755693a terminal: can't assert page integrity on screen 2024-09-05 14:41:02 -07:00
Mitchell Hashimoto
a6031efa04 terminal: DECALN must use clearRows to clear protected memory 2024-09-05 14:35:12 -07:00
Mitchell Hashimoto
f0149722e6 terminal: add integrity check for unmarked grapheme cell 2024-09-05 14:17:11 -07:00
Gregory Anders
df06697899 termio: send initial focus reports
When the focus reporting mode (1004) is enabled, send the current focus
state. This allows applications to track their own focus state without
first having to wait for a focus event (or query
it by sending a DECSET followed by a DECRST).

Ghostty's focus state is stored only in the renderer, where the termio
thread cannot access it. We duplicate the focus state tracking in the
Terminal struct with the addition of a new (1-bit) flag. We duplicate
the state because the renderer uses the focus state for its own purposes
(in particular, the Metal renderer uses the focus state to manage
its DisplayLink), and synchronizing access to the shared terminal state
is more cumbersome than simply tracking the focus state in the renderer
in addition to the terminal.
2024-09-04 22:13:52 -05:00
Mitchell Hashimoto
761bcfad50 kitty gfx: handle q with chunked transmissions properly
Fixes #2190

The `q` value with chunk transmissions is a bit complicated. The initial
transmission ("start" command) `q` value is used for all subsequent
chunks UNLESS a subsequent chunk specifies a `q >= 1`. If a chunk
specifies `q >= 1`, then that `q` value is subsequently used for all
future chunks unless another chunk specifies `q >= 1`. And so on.

This commit importantly also introduces the ability to test a full Kitty
command from string request to structured response. This will let us
prevent regressions in the future and ensure that we are correctly
handling the complex underspecified behavior of Kitty Graphics.
2024-09-04 10:24:25 -07:00
Mitchell Hashimoto
e014c68cf0 kitty kbd: progressive enhancement = mode off by one
Fixes #2161
2024-09-03 11:59:25 -07:00
Mitchell Hashimoto
2acd7e8a42 kitty: respond OK with metadata on display transmissions 2024-09-03 11:05:16 -07:00
Mitchell Hashimoto
e9c83a5f64 kitty: ENOENT when image ID not found for placement 2024-09-03 10:38:10 -07:00
Mitchell Hashimoto
de612934a0 some tweaks for wuffs 2024-09-02 20:47:07 -07:00
Jeffrey C. Ollie
6edeb45e7e kitty graphics: address review comments
- move wuffs code from src/ to pkg/
- eliminate stray debug logs
- make logs a warning instead of an error
- remove initialization of some structs to zero
2024-09-02 20:47:07 -07:00
Jeffrey C. Ollie
6dbb82c259 kitty graphics: performance enhancements
Improve the performance of Kitty graphics by switching to the WUFFS
library for decoding PNG images and for "swizzling" G, GA, and RGB data
to RGBA formats needed by the renderers.

WUFFS claims 2-3x performance benefits over other implementations, as
well as memory-safe operations.

Although not thorougly benchmarked, performance is on par with Kitty's
graphics decoding.

https://github.com/google/wuffs
2024-09-02 20:45:08 -07:00
Mitchell Hashimoto
d8fc54d1bf Merge pull request #2177 from jcollie/kitty-graphics-local-more
kitty graphics: fix usage of "m" key for local-only transmission mediums
2024-09-01 21:19:05 -07:00
Jeffrey C. Ollie
5e925db521 kitty graphics: fix usage of "m" key for local-only transmission mediums
If the transmission medium is a local-only medium, ignore the "m"
key. The Kitty graphics protocol specification does not explicitly
call out this behavior (although the "m" key is only mentioned in
connection with remote clients) but that's how it's implemented in
Kitty and at least one client (mpv) relies on this behavior when
using the shared memory transmission medium.

https://sw.kovidgoyal.net/kitty/graphics-protocol/#the-transmission-medium
ccc3bee9af/kitty/graphics.c (L547-L592)
2024-09-01 21:10:08 -07:00
Mitchell Hashimoto
5d476135c5 terminal: do not run page integrity checks unless slow runtime safety 2024-09-01 21:02:44 -07:00
Mitchell Hashimoto
5ade197f91 Merge pull request #2175 from qwerasd205/pagelist-fix
fix(terminal/PageList): update self.cols at start of resizeCols
2024-09-01 09:58:39 -07:00
Qwerasd
7fb2bd16a9 fix(terminal/PageList): update self.cols at start of resizeCols
It's possible for `self.grow` to be called within the body of the
function, and `self.grow` uses `self.cols` to create a new page if
there's no more room in the current one.
2024-09-01 09:55:00 -07:00
Mitchell Hashimoto
6aab430caf terminal: disable slow safety tests in releasesafe 2024-08-31 21:14:12 -07:00
Mitchell Hashimoto
9d08ed32ee terminal: make error sets more explicit, capture explicit errors 2024-08-31 10:31:38 -07:00