502 Commits

Author SHA1 Message Date
Mitchell Hashimoto
7dac9e02b3 terminal: reflow the saved cursor if we have one
Fixes #5718

When a terminal is resized with text reflow (i.e. soft-wrapped text), the cursor
is generally reflowed with it.

For example, imagine a terminal window 5-columns wide and you type the
following without pressing enter. The cursor is on the X.

```
OOOOO
OOX
```

If you resize the window now to 8 or more columns, this happens, as expected:

```
OOOOOOOX
```

As expected, the cursor remains on the "X". This behaves like any other text
input...

Terminals also provide an escape sequence to
[save the cursor (ESC 7 aka DECSC)](https://ghostty.org/docs/vt/esc/decsc).
This includes, amongst other things, the cursor position. The cursor can be
restored with [DECRC](https://ghostty.org/docs/vt/esc/decrc).

The behavior of the position of the _saved cursor_ in the context of text
reflow is unspecified and varies wildly between terminals Ghostty does this
right now (as do many other terminals):

```
OOOOOOOO
   X
```

This commit changes the behavior so that we reflow the saved cursor.
2025-02-12 10:34:31 -08:00
Mitchell Hashimoto
e5e090deaf test: big perf win by pausing integ checks while growing pages (#2956)
In multiple tests we create 1 or more pages by growing them 1 row at a
time, which results in an integrity check of the page for each row grown
which is just... horrible. By simply pausing integrity checks while
growing these pages (since growing them is not the point of the test) we
MASSIVELY speed up all of these tests.

Also reduced grapheme bytes during testing and made the Terminal "glitch
text" test actually assert what it intends to achieve, rather than just
blindly assuming 100 copies of the text will be the right amount -- this
lets us stop a lot earlier, making it take practically no time.
2024-12-12 16:12:22 -08:00
Qwerasd
10abeba414 test: big perf win by pausing integ checks while growing pages
In multiple tests we create 1 or more pages by growing them 1 row at a
time, which results in an integrity check of the page for each row grown
which is just... horrible. By simply pausing integrity checks while
growing these pages (since growing them is not the point of the test) we
MASSIVELY speed up all of these tests.

Also reduced grapheme bytes during testing and made the Terminal "glitch
text" test actually assert what it intends to achieve, rather than just
blindly assuming 100 copies of the text will be the right amount -- this
lets us stop a lot earlier, making it take practically no time.
2024-12-12 16:58:48 -05:00
Mitchell Hashimoto
fd1201323e unicode: emoji modifier requires emoji modifier base preceding to not break
Fixes #2941

This fixes the rendering of the text below. For those that can't see it,
it is the following in UTF-32: `0x22 0x1F3FF 0x22`.

```
"🏿"
```

`0x1F3FF` is the Fitzpatrick modifier for dark skin tone. It has the
Unicode property `Emoji_Modifier`. Emoji modifiers are defined in UTS
#51 and are only valid based on ED-13:

```
emoji_modifier_sequence := emoji_modifier_base emoji_modifier
emoji_modifier_base := \p{Emoji_Modifier_Base}
emoji_modifier := \p{Emoji_Modifier}
```

Additional quote from UTS #51:

> To have an effect on an emoji, an emoji modifier must immediately follow
> that base emoji character. Emoji presentation selectors are neither needed
> nor recommended for emoji characters when they are followed by emoji
> modifiers, and should not be used in newly generated emoji modifier
> sequences; the emoji modifier automatically implies the emoji presentation
> style.

Our precomputed grapheme break table was mistakingly not following this
rule. This commit fixes that by adding a check for that every
`Emoji_Modifier` character must be preceded by an `Emoji_Modifier_Base`.
This only has a cost during compilation (table generation). The runtime
cost is identical; the table size didn't increase since we had leftover
bits we could use.
2024-12-12 12:53:08 -08:00
Mitchell Hashimoto
212bd3d5fb terminal: fullReset uses the new screen reset methods 2024-12-02 17:44:07 -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
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
Mitchell Hashimoto
39627e3221 termio: set pw input state on terminal and wake up renderer 2024-09-18 10:47:26 -07: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
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
a6031efa04 terminal: DECALN must use clearRows to clear protected memory 2024-09-05 14:35:12 -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
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
Qwerasd
3807ee34c1 terminal: handle clonePartialRowFrom errors in insert/deleteLines
Handle `clonePartialRowFrom` errors in `insertLines` and `deleteLines`
by adjusting page capacity. To do this, I've rewritten both functions
with a new way of iterating rows by moving a tracked pin up/down.

Benchmarks seem to indicate that this has no effect on performance.
2024-08-30 13:45:18 -04:00
Mitchell Hashimoto
6a2d57edfd terminal: cursorCopy has option to not copy hyperlink 2024-08-28 09:41:57 -07:00
Qwerasd
a3fb96f543 this should be a doc comment 2024-08-27 01:23:29 -04:00
Qwerasd
38bb9b40a6 Terminal: release hyperlink before copying cursor when switching screen
To avoid an unnecessary copy.
2024-08-27 01:07:29 -04:00
Mitchell Hashimoto
1028fe1c56 terminal: only call new method 2024-08-17 22:02:48 -07:00
Mitchell Hashimoto
adb382f1c8 terminal: call new method for scroll operation 2024-08-17 22:00:52 -07:00
Mitchell Hashimoto
a125dc9682 terminal: add more tests for index, verified that l/r margin handling is
good
2024-08-17 20:01:47 -07:00
Mitchell Hashimoto
1d7e87c88d terminal: index from bottom row of scroll region always makes scrollback
Ghostty previously incorrectly only created scrollback if the top/bot
margins were the full height of the viewport. The actual xterm behavior
is to create scrollback as long as the top margin is the top row and the
cursor is on the bottom margin (wherever that may be).
2024-08-17 10:58:34 -07:00
Łukasz Niemier
f9be02a20f chore: clean up typos 2024-08-05 13:56:57 +02:00
Mitchell Hashimoto
d40101fea0 terminal: more tests 2024-07-31 09:51:32 -07:00
Mitchell Hashimoto
3549619a64 terminal: introduce row bit for kitty virtual placeholders 2024-07-25 21:32:45 -07:00
Mitchell Hashimoto
deacb10fb1 terminal: print must use codepoint() now to work with placeholders 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
2c0f9bfc28 terminal: cell returns empty for Kitty placeholder
So we don't render the replacement char
2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
902913554b terminal: printing over a cell with the same hyperlink keeps flag
Fixes #1990

This fixes and adds a unit test for an edge case where when printing
over the same cell with the same hyperlink ID, we were unsetting the
cell hyperlink state.

This commit also adds a number of integrity checks to verify hyperlinks
remain in a consistent state.
2024-07-23 16:00:09 -07:00
Qwerasd
730185b212 terminal: spacer heads and tails should be codepoint 0, not ' ' 2024-07-08 22:25:39 -04:00
Mitchell Hashimoto
251ec0c9f3 terminal: on print, adjust page size if we need to grow for hyperlinks 2024-07-05 21:40:40 -07:00
Mitchell Hashimoto
ff9ab70091 terminal: end hyperlink state when switching screens 2024-07-05 21:40:39 -07:00
Mitchell Hashimoto
f920068ce6 terminal: full reset clears OSC8 state 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
d9e654da4a terminal: scrollUp hyperlink tests 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
84edaed690 terminal: scrollDown with hyperlinks 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
bac1307c4b terminal: index hyperlink tests 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
96ff17a9b4 terminal: save/restore cursor doesn't modify hyperlink state 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
57c5522a6b terminal: handle moving/swapping/clearing cells with hyperlinks 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
e2133cbd92 terminal: row needs hyperlink state, test clearing hyperlink 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
a3a445a066 terminal: print sets hyperlink state, tests 2024-07-05 21:40:38 -07:00
Qwerasd
93b038f490 fix(RefCountedSet): add NeedsRehash error and fix PSL counting bug
Prevent bad input from causing repeated OutOfMemory errors by erroring
with NeedsRehash instead when there are unused dead IDs available.

Additionally, properly decrement PSL stats when reviving dead IDs.
2024-06-24 20:32:22 -07:00
Qwerasd
9741b3a18c perf: introduce RefCountedSet structure, use it for Style.Set 2024-06-13 22:59:03 -04:00
Mitchell Hashimoto
0d94fb61c9 terminal: all cursor movement needs to mark the old and new page dirty 2024-06-07 15:03:02 -07:00
Mitchell Hashimoto
c2b0bb6395 terminal: mark old/new rows as dirty when moving the cursor absolute 2024-06-07 14:55:02 -07:00