Commit Graph

8104 Commits

Author SHA1 Message Date
Mitchell Hashimoto
bf46c4ebe7 terminal/tmux: many more output formats 2025-12-09 21:10:46 -08:00
Mitchell Hashimoto
4c30c5aa76 terminal/tmux: cleanup command queue logic 2025-12-09 20:31:51 -08:00
Mitchell Hashimoto
582ea5d84b terminal/tmux: window add 2025-12-09 20:07:08 -08:00
Mitchell Hashimoto
1a2b3c165a terminal/tmux: layoutChanged handling 2025-12-09 17:09:57 -08:00
Mitchell Hashimoto
071070faa3 terminal/tmux: handle session_changed inside command loop 2025-12-09 14:21:07 -08:00
Mitchell Hashimoto
64ef640127 terminal/tmux: exhaustive switch for command 2025-12-09 13:56:16 -08:00
Mitchell Hashimoto
938e419e04 terminal/tmux: handle output events 2025-12-09 13:13:52 -08:00
Mitchell Hashimoto
50ac848672 terminal/tmux: capture both primary/alt screen 2025-12-09 13:00:40 -08:00
Mitchell Hashimoto
a3e01581be terminal/tmux: history capture clears active area 2025-12-09 11:33:06 -08:00
Mitchell Hashimoto
b7fe9a926d terminal/tmux: capture visible area after history 2025-12-09 11:22:14 -08:00
Mitchell Hashimoto
41bf541005 terminal/tmux: test helper 2025-12-09 10:53:52 -08:00
Mitchell Hashimoto
e1e2791fb7 terminal/tmux: pane_history replays it into terminal 2025-12-09 10:00:43 -08:00
Mitchell Hashimoto
f02a2d5eed terminal/tmux: capture pane 2025-12-09 09:25:55 -08:00
Mitchell Hashimoto
766c306e04 terminal/tmux: pane history 2025-12-08 20:15:20 -08:00
Mitchell Hashimoto
ea09d257a1 terminal/tmux: initialize panes 2025-12-08 11:54:48 -08:00
Mitchell Hashimoto
86cd489701 terminal/tmux: introduce command queue for viewer 2025-12-08 09:00:38 -08:00
Mitchell Hashimoto
ec5a60a119 terminal/tmux: make sure we always have space for one action 2025-12-08 07:27:37 -08:00
Mitchell Hashimoto
b26c42f4a6 terminal/tmux: better formatting for notifications and actions 2025-12-08 07:00:44 -08:00
Mitchell Hashimoto
52dbca3d26 termio: hook up tmux viewer 2025-12-08 07:00:43 -08:00
Mitchell Hashimoto
3cbc232e31 terminal/tmux: return allocated list of actions 2025-12-08 07:00:43 -08:00
Mitchell Hashimoto
c1d686534e terminal/tmux: list windows 2025-12-08 07:00:43 -08:00
Mitchell Hashimoto
4c3ef8fa13 terminal/tmux: viewer list windows state 2025-12-08 07:00:43 -08:00
Mitchell Hashimoto
0d75a78747 terminal/tmux: start viewer state machine 2025-12-08 07:00:43 -08:00
Mitchell Hashimoto
af3a11b546 terminal/tmux: output has format/comptimeFormat 2025-12-08 07:00:43 -08:00
Mitchell Hashimoto
049b8826f6 macos: make QuickTerminalSize config C ABI compatible (#9837)
Hello! I did read `CONTRIBUTING.md`. I understand that the preference is
to receive pull requests for existing open issues and acknowledge that
I'm skipping a step wrt the preferred workflow since there aren't any
open issues yet for #8419. Living dangerously and hoping for the best
here. I hope you'll see that I'm acting in good faith 🤞.

In my attempts to debug why `quick-terminal-size` config wasn't working
reliably for me, I discovered that the
[`ghostty_config_quick_terminal_size_s`](08c9661683/include/ghostty.h (L460-L480))
struct used to initialize `QuickTerminalSize` in Swift-land, more often
than not, didn't match what I had in my config file (e.g.
`quick-terminal-size = 75%, 50%`)

<details>


08c9661683/include/ghostty.h (L460-L480)


08c9661683/macos/Sources/Ghostty/Ghostty.Config.swift (L507-L510)

</details>

Almost all mismatches seemed to be downstream of `tag` (for `primary`
and/or `secondary` `Size`) being an unexpected value for the
`ghostty_quick_terminal_size_tag_e` enum type, which led runtime
execution to fall into the `default` branch in this `switch` control
flow.


08c9661683/macos/Sources/Features/QuickTerminal/QuickTerminalSize.swift (L27-L38)

Looking at `src/config/CApi.zig`, `src/config/c_get.zig`,
`src/config/Config.zig`, and [Zig documentation for `extern
enum`](https://ziglang.org/documentation/master/#extern-enum), led me to
conclude that the crux of the issue is lack of guaranteed C ABI
compatibility for `Tag`


08c9661683/src/config/Config.zig (L7986-L7990)


08c9661683/include/ghostty.h (L461-L465)

Further research revealed that based on C language spec alone, one
cannot assume a fixed width for `enum` and that the behaviour is
compiler dependant. But given how the Zig documentation suggests using
`enum(c_int)` for C-ABI-compatible enums and extern enums + comments
elsewhere in `Config.zig` suggesting that `enum(c_int)` was chosen for
extern compatibility,


08c9661683/src/config/Config.zig (L4877)

I think that this fix (changing `enum(u8)` to `enum(c_int)`) is likely
the most straightforward and appropriate one.
2025-12-08 07:00:16 -08:00
Mitchell Hashimoto
9cd96e4b64 quirks: remove type signature for inlineAssert (#9843)
Functions with different calling conventions are not compatible with
each other

Fixes all release builds + CI
2025-12-07 21:57:48 -08:00
Leah Amelia Chen
2ac9e03c52 quirks: remove type signature for inlineAssert
Functions with different calling conventions are not compatible with
each other

Fixes all release builds + CI
2025-12-08 13:19:16 +08:00
Mitchell Hashimoto
0bbd7c8f9a os: fix off-by-one error in ShellEscapeWriter (#9842)
I am truly not sure why the tests never caught this, but I just fell for
the oldest trick in the book

Fixes a crash on GTK when a file is dragged then dropped into the
terminal - should not impact 1.2 as this is a casualty of the Zig 0.15
port
2025-12-07 21:17:12 -08:00
Leah Amelia Chen
6da2f0e3e7 os/shell: actually run tests 2025-12-08 13:04:20 +08:00
Leah Amelia Chen
ed1d77d518 os: fix off-by-one error in ShellEscapeWriter
I am truly not sure why the tests never caught this, but I just fell for
the oldest trick in the book
2025-12-08 12:42:35 +08:00
Mitchell Hashimoto
9d4f96381a make our quirks assert use std.debug.assert in debug builds
This fixes an issue I have on both macOS and Linux (ARM and x86_64)
where stack traces are broken for inlined functions. They don't point to
the proper location in the source code, making debugging difficult.

Release builds use the same previous function.
2025-12-07 14:15:06 -08:00
voideanvalue
aa0afa2d02 fix C ABI compat for ghostty_quick_terminal_size_tag_e 2025-12-06 22:17:33 +00:00
Mitchell Hashimoto
f98b12579e core: selection and copy bindings need to hold the big lock
This was found by LLM hunting! We were not holding the lock properly
during these operations. There aren't any known cases where we can
directly attribute these races to issues but we did find at least one
consistent crash for a user when `linkAtPos` wasn't properly locked (in
another PR).

This continues those fixes.
2025-12-05 08:33:11 -08:00
Mitchell Hashimoto
6b2097e872 core: hold lock during keyCallback when mouseRefreshLinks is called
From #9812

I'm not sure if this is the root cause of the crash in #9812 but the
LLM-discovered issue that we are not holding a lock here appears to be a
real issue. I manually traced the code paths and thought about this and
looked where we call `mouseRefreshLinks` in other places and this
appears to be a real bug.
2025-12-04 19:45:03 -08:00
Mitchell Hashimoto
3f241502c2 terminal/tmux: a lot more control mode parsing, functionality (#9803)
Continuing just build foundation for #1935. There are no user-facing
changes here.

- This adds more command parsing for control mode output. I _believe_ we
now parse enough to at least render everything initially for most tmux
sessions. At least, from the VT parsing side (we haven't done any GUI
work whatsoever to react to this).

- This also adds a new layout string parser, e.g.
`159x48,0,0{79x48,0,0,79x48,80,0}` into a useful struct. We'll need this
to convert our visible layouts into actual GUI components, eventually.

- This adds a new output format parser for commands such as
`list-windows`. Control mode sends output framed in `%begin/%end`
blocks, but the output is in an arbitrary format depending on the input
command and unrelated to control mode itself. The output format parser
will let us parse this output.

I think this is a good place to stop and PR. I think next up I might try
hooking up a state machine to `src/termio/stream_handler.zig` to start
actually working with this. Before that, it may behoove me to change
`stream_readonly` to support non-readonly operations via callback so I
can do DCS and maybe unit test this whole thing too.... we'll see where
the wind blows.

**AI disclosure:** AI wrote many tests and did a lot of implementation
here. I reviewed everything manually though and understand it all
completely.
2025-12-04 15:30:13 -08:00
Jeffrey C. Ollie
68426dc21a core: rate limit BEL character processing
If the BEL character is received too frequently, the GUI thread can be
starved and Ghostty will lock up and eventually crash. This PR limits
BEL handling to 1 per 100ms.

Fixes #9800.
2025-12-04 12:32:58 -06:00
Mitchell Hashimoto
6b21b9147c terminal/tmux: add output format parsing (minimal) 2025-12-03 20:23:28 -08:00
Mitchell Hashimoto
b95965cb5a terminal/tmux: add layout-change to control mode parsing 2025-12-03 13:27:37 -08:00
Mitchell Hashimoto
92ea8d0eb5 terminal/tmux: layout checksums 2025-12-03 13:27:37 -08:00
Mitchell Hashimoto
dfa22379b2 terminal/tmux: layout string parser 2025-12-03 13:27:37 -08:00
Mitchell Hashimoto
7a9dc77a94 terminal/tmux: clean up error handling, explicit error sets 2025-12-03 13:27:36 -08:00
Mitchell Hashimoto
6e016ea81e terminal: move tmux into folder 2025-12-03 13:27:36 -08:00
Mitchell Hashimoto
5bc78d59fb terminal/tmux: add more control mode parsing keys 2025-12-03 13:27:36 -08:00
Mitchell Hashimoto
b4a48303ed build: fix path access to work with relative build roots (#9780)
## Problem

When ghostty is used as a dependency (e.g., in another Zig project), the
build can panic on Linux with:

\`\`\`
GhosttyDist.zig:173:34: 0x1768046 in exists (build.zig)
    if (std.fs.accessAbsolute(b.pathFromRoot(self.dist), .{})) {
\`\`\`

This happens because \`b.pathFromRoot()\` can return a relative path
(e.g., when the build root is \`.\`), but \`std.fs.accessAbsolute()\`
asserts the path must be absolute.

## Solution

Replace \`std.fs.accessAbsolute(b.pathFromRoot(...))\` with
\`b.build_root.handle.access(...)\`, which uses the build root's
directory handle directly and works correctly with relative paths.

Context:
https://ampcode.com/threads/T-7511e7e4-4b4a-4f11-9c3c-817aaa519b84
2025-12-02 11:13:52 -08:00
Mitchell Hashimoto
8d25ab0ae3 zsh: improve ZDOTDIR documentation (#9779)
The main thing to emphasize is that end users should never source
.zshenv directly; it's only meant to be used as part of our shell
injection environment.

At the moment, there's no way to guard against accidentally use, but we
can consider making e.g. GHOSTTY_SHELL_FEATURES always defined in this
environment to that it can be used to differentiate the cases.

In practice, it's unlikely that people actually source this .zshenv
script directly, so hopefully this additional documentation clarifies
things well enough.
2025-12-02 11:13:10 -08:00
Jon Parise
6babcc97f5 zsh: move version check to ghostty-integration
The ghostty-integration script can be manually sourced, and it uses the
Zsh 5.1+ features, so that's a better place to guard against older Zsh
versions.

This also keeps the .zshenv script focused on just bootstrapping our
automatic shell integration.

I also changed the version check to a slightly more idiomatic pattern.
2025-12-01 20:34:55 -05:00
Tim Culverhouse
7fe3f5cd3f build: fix path access to work with relative build roots
Replace std.fs.accessAbsolute(b.pathFromRoot(...)) with
b.build_root.handle.access(...) since pathFromRoot can return
relative paths, but accessAbsolute asserts the path is absolute.
2025-12-01 18:29:54 -06:00
Jon Parise
da014d98cd zsh: improve ZDOTDIR documentation
The main thing to emphasize is that end users should never source
.zshenv directly; it's only meant to be used as part of our shell
injection environment.

At the moment, there's no way to guard against accidentally use, but we
can consider making e.g. GHOSTTY_SHELL_FEATURES always defined in this
environment to that it can be used to differentiate the cases.

In practice, it's unlikely that people actually source this .zshenv
script directly, so hopefully this additional documentation clarifies
things well enough.
2025-12-01 19:07:50 -05:00
Jon Parise
5714ed07a1 zsh: improve minimum version check (#9772)
- Handle autoload failures
- Prefer ">&2" to "/dev/stderr" for portability
- Quote commands for consistency and to avoid alias conflicts
2025-12-01 11:15:02 -05:00
Jon Parise
b776b3df61 zsh: improve minimum version check
- Handle autoload failures
- Prefer ">&2" to "/dev/stderr" for portability
- Quote commands for consistency and to avoid alias conflicts
2025-12-01 10:19:00 -05:00