Commit Graph

8690 Commits

Author SHA1 Message Date
Priyanshu
de49b7f27b rename copy_title action to copy_title_to_clipboard 2026-02-13 09:59:02 +05:30
Priyanshu
b4be13ed50 fix: copy_title_to_clipboard now respects user-overridden title
When a user renames a surface via "Change Terminal Title" and then
uses copy_title_to_clipboard, the raw terminal title was copied
instead of the custom name.

This adds a new `copy_title` apprt action so each platform resolves
the effective title (user override or terminal-set) before copying
to clipboard.

Fixes #10345
2026-02-13 01:19:15 +05:30
Tobias Kohlbau
f661d948a2 renderer: fix draw timer activation
The draw timer should only be activated in case a custom shader
is configured and the option custom-shader-animation is either always
or true. If the timer is kept alive CPU usage spiked enourmously.

Fixes #10667
2026-02-11 17:23:41 +01:00
Mitchell Hashimoto
f831258c0f elvish: improve the sudoedit detection code (#10587)
The previous logic didn't detect the `e` option when it was combined
with other flags (e.g. `-ie`). This change also attempts to improve the
general readability of this code to be a bit more explicit.
2026-02-10 15:36:36 -08:00
Mitchell Hashimoto
d8dd3e3523 bash: remove dependency on bash-preexec for bash 4.4+ (#10609)
bash-preexec implements support for its "precmd" and "preexec" hooks
using a combination of PROMPT_COMMAND and a DEBUG trap. The latter is
unfortunately quick slow (in a relative sense), and the overall system
is a bit more generalized than what we need for our shell integration
(e.g. supporting multiple function hooks, subshells, etc.).

Bash 4.4 introduced the PS0 variable, which is expanded and displayed by
interactive shells after reading a complete command but before executing
it. This is all we need to implement our own shell integration hooks.

In Bash 5.1, PROMPT_COMMAND can be an array variable, each element of
which can contain a command to be executed like a string PROMPT_COMMAND
variable. When adding our hook to PROMPT_COMMAND, we preserve its type
(string or array) to be minimally intrusive. This also matches direnv's
approach.

Bash 5.3 introduced support for function substitution, which is an even
more efficient way to run code from PS0, so we use that when available.
Otherwise, we use the more traditional command substitution approach.

Earlier versions of bash (such as 3.2, which still ships with macOS)
continue to use the bash-preexec path. This gives us two code paths to
maintain, but I think that's preferable to fully maintaining our own
DEBUG trap-based system for older bash versions given that bash-preexec
has proven to work reliably in those environments. We also wouldn't
unlock any other user benefits aside from removing the bash-preexec
script dependency.

See: #3724, #7734
2026-02-10 15:36:22 -08:00
Ēriks Remess
0aef823748 Latvian translation. Updated CODEOWNERS, src/os/i18n_locales.zig 2026-02-09 01:30:34 +02:00
Jon Parise
d0b403304d bash: use PROMPT_COMMAND array form in bash 5.1+
PROMPT_COMMAND array support for introduced in bash 5.1, and it's the
preferred format moving forward. Using the string form is also fine, but
it's easy to be a modern bash citizen here, so let's do so.
2026-02-08 09:40:05 -05:00
Jon Parise
5425569a19 bash: remove dependency on bash-preexec for bash 4.4+
bash-preexec implements support for its "precmd" and "preexec" hooks
using a combination of PROMPT_COMMAND and a DEBUG trap. The latter is
unfortunately quick slow (in a relative sense), and the overall system
is a bit more generalized than what we need for our shell integration
(e.g. supporting multiple function hooks, subshells, etc.).

Bash 4.4 introduced the PS0 variable, which is expanded and displayed by
interactive shells after reading a complete command but before executing
it. This is all we need to implement our own shell integration hooks.

In Bash 5.1, PROMPT_COMMAND can be an array variable, each element of
which can contain a command to be executed like a string PROMPT_COMMAND
variable. When adding our hook to PROMPT_COMMAND, we preserve its type
(string or array) to be minimally intrusive. This also matches direnv's
approach.

Bash 5.3 introduced support for function substitution, which is an even
more efficient way to run code from PS0, so we use that when available.
Otherwise, we use the more traditional command substitution approach.

Earlier versions of bash (such as 3.2, which still ships with macOS)
continue to use the bash-preexec path. This gives us two code paths to
maintain, but I think that's preferable to fully maintaining our own
DEBUG trap-based system for older bash versions given that bash-preexec
has proven to work reliably in those environments. We also wouldn't
unlock any other user benefits aside from removing the bash-preexec
script dependency.

See: #3724, #7734
2026-02-07 15:29:04 -05:00
Jeffrey C. Ollie
290ad05ea6 fix fish shell integration when cancelling a command
Cancelling a command should not send `OSC 133;A` as that starts a new
line.

Fixes #10544
2026-02-06 09:49:13 -06:00
Jon Parise
95a4d1675b elvish: improve the sudoedit detection code
The previous logic didn't detect the `e` option when it was combined
with other flags (e.g. `-ie`). This change also attempts to improve the
general readability of this code to be a bit more explicit.
2026-02-05 11:07:49 -05:00
Jeffrey C. Ollie
dd14ce6752 gtk: add two-finger left/right scroll to switch tab pages
This adds the ability to use two fingers on a touchpad to scroll left
or right on a Ghostty window to change tab pages. Uses the same basic
machinery as scrolling up and down the scrollback buffer. Scrolling
pages does not wrap around at the start or end of the tabs.
2026-02-04 20:23:50 -06:00
Ben Kircher
6c0a17cccf Fix clicking bare relative file paths
Related to #1972

The URL regex for file path detection requires paths to start with
`../`, `./`, or `/`. For bare relative paths like
`"src/config/url.zig"`, the regex could only match starting at the first
`/`, producing `"/config/url.zig"` as a result — always dropping the
first part of the path.

Fix: added a third top-level alternative to the regex. This matches bare
relative paths where:

1. The first component is word characters (possibly with dots/dashes):
   `[\w][\w\-.]*\/`
2. The remaining path must contain a dot (via positive lookahead) — this
   requires a file extension to avoid false positives on text like
   input/output
3. Add a `(?<!\w)\/` instead of `\/` in the existing prefix group — the
   standalone `/` prefix now requires that `/` is not preceded by a word
   character. This prevents `"input/output"` from falsely matching
   `"/output"`

Test cases added:
- src/config/url.zig → matches fully
- app/folder/file.rb:1 → matches with line number
- modified:   src/config/url.zig → matches only the path part
- lib/ghostty/terminal.zig:42:10 → matches with line:col
- some-pkg/src/file.txt more text → stops before trailing text
- input/output and foo/bar → correctly do not match (no file extension)

The issue was nailed down here:
https://github.com/ghostty-org/ghostty/issues/1972#issuecomment-3845717672
2026-02-04 15:17:46 +01:00
Mitchell Hashimoto
51897c0cd5 elvish: simplify XDG_DATA_DIRS cleanup (#10546)
We always add GHOSTTY_SHELL_INTEGRATION_XDG_DIR to XDG_DATA_DIRS with a
tailing colon (via our prependEnv routine), so we can greatly simplify
this cleanup code with a single str:replace call.
2026-02-02 20:02:24 -08:00
Mitchell Hashimoto
6e2d59f8e5 Don't reset click count on prompt move so we can still double click 2026-02-02 19:53:53 -08:00
Jon Parise
6a04662303 elvish: simplify XDG_DATA_DIRS cleanup
We always add GHOSTTY_SHELL_INTEGRATION_XDG_DIR to XDG_DATA_DIRS with a
tailing colon (via our prependEnv routine), so we can greatly simplify
this cleanup code with a single str:replace call.
2026-02-02 20:24:25 -05:00
Mitchell Hashimoto
00567ff427 remove obsolete impossible test scenario 2026-02-02 15:20:36 -08:00
Mitchell Hashimoto
e478f3bf76 remove legacy promptPath 2026-02-02 15:18:09 -08:00
Mitchell Hashimoto
8595558653 shell-integration/zsh: support cl=line 2026-02-02 15:13:37 -08:00
Mitchell Hashimoto
e60806942e terminal: when clicking right beyond the prompt line, move one more
This moves the cursor to the end properly.
2026-02-02 15:11:24 -08:00
Mitchell Hashimoto
2fa9eff0ef shell-integration/bash: advertise cl=line support 2026-02-02 13:36:29 -08:00
Mitchell Hashimoto
7af49f6cc6 Surface respects cl by using single arrow keys within a single line 2026-02-02 13:36:24 -08:00
Mitchell Hashimoto
4a1f02043a terminal: Screen.promptClickMove for cl handling 2026-02-02 13:36:24 -08:00
Mitchell Hashimoto
4ce1310371 renderer: reset overlay anytime sizing changes
Fixes #10522

This also fixes possible runtime safety crashes. Whenever the underlying
size information doesn't match what our renderer or grid see, then we
should deinit and reinit.
2026-02-02 11:29:14 -08:00
Mitchell Hashimoto
608d312651 Support OSC133 click_events Kitty extension (supported by Fish) (#10536)
This adds support for the `OSC 133 A click_events=1` extension
introduced by Kitty and supported by Fish.[^1]

**What this means:** If the shell advertises `click_events=1` support,
Ghostty will _unconditionally_ (no modifier required) send mouse events
to the shell for clicks on a prompt line, delegating to the supporting
shell to move the cursor as needed. For Fish 4.1+ this means that
clicking on the prompt line moves the cursor (see demo video below).

This PR also contains:

* A minor fix in `cl` parsing but we don't yet implement the logic there
* Updated inspector to show the semantic prompt click mode

## Demo


https://github.com/user-attachments/assets/03ef8975-7ad9-441f-aaa2-9d0eb5c5e36d

## Implementation Details

`click_events` is wildly underspecified, so here are the details the
best I understand them. This itself is not a specification (I omit
details) but adds some more context to it.

The `click_events=1` option can be specified with `OSC 133 A` (Ghostty
also allows it on OSC 133 N). When that is specified, it flags for all
future prompts that the screen supports click events for semantic
prompts. If both `click_events` and `cl` are specified, `click_events`
takes priority if true. If `click_events=0` (disable), then any set `cl`
will take priority.

When a mouse click comes in, we check for the following conditions:

1. The screen supports click events
2. The screen cursor is currently at a prompt
3. The mouse click was at or below the starting prompt line of the
current prompt

If those are met, we encode an SGR mouse event with: left button, press,
coordinates of click. It is up to the shell after that to handle it. Out
of prompt bounds SGR events are possible (specifically below). The shell
should robustly handle this.

[^1]: I don't know any other terminal or shell that supports it at the
moment.
2026-02-02 10:57:30 -08:00
Mitchell Hashimoto
e20a8ee797 shell-integration: fish sets click_events=1 for Fish >= 4.1 2026-02-02 10:44:35 -08:00
Mitchell Hashimoto
80d6e71aec inspector: show more semantic prompt state for screen 2026-02-02 10:44:35 -08:00
Mitchell Hashimoto
25b6423e7b Handle Kitty click_events OSC133 extension 2026-02-02 10:44:35 -08:00
Jeffrey C. Ollie
93f12b675c elvish: improve shell integration instructions (#10534)
Wrapping `use ghostty-integration` in a `try .. catch` here makes this
suggestion more resilient to environments where we didn't inject our
resource directory into XDG_DATA_DIRS (but are still running Ghostty).
2026-02-02 11:40:41 -06:00
Mitchell Hashimoto
b827e587d9 terminal: set semantic_prompt.click based on OSC133A options 2026-02-02 09:28:55 -08:00
Mitchell Hashimoto
e9b6fea11c terminal: move semantic prompt state into its own field in screen 2026-02-02 09:19:18 -08:00
Mitchell Hashimoto
9ff9298707 terminal: parse OSC 133 cl values correctly 2026-02-02 09:01:01 -08:00
Mitchell Hashimoto
8bc3cdcf7d nushell: refactor ssh wrapper for clarity (#10490)
The ssh wrapper previously used a separate set_ssh_terminfo function
that returned a record to be merged, which result in some redundant
control flow and TERM assignments.

This inlines the terminfo logic and builds env/opts incrementally based
on feature flags. TERM is set to a fallback early and only overridden on
success, which simplifies our error handling and avoids mutable variable
capture issues in closures.

Lastly, warnings are now consistently written to stderr, and I made
various other control flow and syntax improvements.
2026-02-02 08:37:47 -08:00
Jon Parise
95c6fca0a7 elvish: improve shell integration instructions
Wrapping `use ghostty-integration` in a `try .. catch` here makes this
suggestion more resilient to environments where we didn't inject our
resource directory into XDG_DATA_DIRS (but are still running Ghostty).
2026-02-02 11:33:40 -05:00
Jon Parise
37a534b747 elvish: always report current directory changes
This reporting shouldn't have been tied to the 'title' shell features.
That's a different feature where we change the window title (icon) to
reflect the current command using OSC 2.
2026-02-02 11:06:47 -05:00
Mitchell Hashimoto
2d02e4bb54 remove redraw_inspector message 2026-02-01 14:32:37 -08:00
Mitchell Hashimoto
63f9d4aaf7 apprt/gtk: move imgui widget to frame timer redraw 2026-02-01 14:30:53 -08:00
Mitchell Hashimoto
446b26bb72 renderer: don't ever redraw the inspector. Not your job! 2026-02-01 14:10:33 -08:00
Mitchell Hashimoto
ca1ee7d2c4 renderer: don't draw overlay if it isn't needed
This avoids loud log messages when no overlay is present.
2026-02-01 13:18:35 -08:00
Mitchell Hashimoto
a909a1f120 terminal: mark newlines for input lines as prompt continuation rows 2026-02-01 13:01:03 -08:00
Mitchell Hashimoto
8811d9b055 terminal: for prompt redraw, assume at a prompt if at input line
Nu properly marks input areas with OSC 133 B, but if it spans multiple
lines it doesn't mark the continuation lines with the k=s sequence.

Our prompt redraw logic before only cleared explicitly designated prompt
lines. But if the input line is multi-line and the continuation lines
are not marked, those lines would not be cleared, leading to visual
issues on resize.

To workaround this, we assume that if the current cursor semantic
content is anything other than "command output" (default), then we're
probably at a prompt line and should clear from there all the way up.
2026-01-31 20:59:31 -08:00
Mitchell Hashimoto
853fee9496 terminal: when semantic cursor is prompt, assume newline is prompt
This works around Fish (at least v4.2) having a non-compliant OSC133 
implementation paired with not having the hooks to fix this via shell
integration. We have to instead resort to heuristics in the terminal
emulator. Womp, womp.

The issue is that Fish does not emit OSC133 secondary prompt (`k=s`)
markers at the beginning of continuation lines. And, since Fish doesn't
provide a PS2-equivalent, we can't do this via shell integration.

We fix this by assuming on newline (`\n`) that a cursor that is already
painting prompt cells is continuing a prior prompt line, and
pre-emptively mark it as a prompt line. But this has two further issues
we have to work around:

  1. Newline/index (`\n`) is one of the _hottest path_ functions in
     terminal emulation. It sucks to add any new conditional logic here.
     We do our best to gate this on unlikely conditions that the branch
     predictor can easily optimize away.

  2. Fish also emits these for auto-complete hints that may be deleted 
     later. So, we also have to handle the scenario where a prompt is 
     continued, then replaced by command output, and fix up the prompt 
     continuation flag to go back to output mode.

Point 2 is ALMOST automatically handled, because Fish does emit a `CSI J`
(erase display below) to erase the auto-complete hint. This resets all
our rows back to output rows. **Unfortunately**, Fish emits `\n` before
triggering the preexec hooks which set OSC133C. So we get the newline
logic FIRST (sets the prompt line), THEN sets the output cursor. If they
switched ordering here everything would just work (with the one
heuristic). But now, we need two!

To address this, I put some extra heuristic logic in the OSC133C
(output starting) handler: if our row is marked as a prompt AND our 
cursor is at x=0, we assume that the prompt continuation was deleted
and we unmark it. 

I put the heuristic logic dependent on OSC133C because that's way colder
of a path than putting something in `printCell` (which is the actual
hottest path in Ghostty).

We could get more rigorous here by also checking if every cell is empty
but that doesn't seem to be necessary at this time for any Fish version
I've tested. I hope thats correct.

I'd really love for Fish to improve their OSC133 implementation to
conform more closely to the terminal-wg spec, but we're going to need
these workarounds indefinitely to handle older Fish versions anyway.
2026-01-31 20:45:01 -08:00
Mitchell Hashimoto
92d6dde583 shell-integration/zsh: set proper input and secondary prompt marks 2026-01-31 19:34:02 -08:00
Mitchell Hashimoto
918c2934a3 terminal: add redraw=last for bash for OSC133 2026-01-31 15:26:14 -08:00
Mitchell Hashimoto
4bee8202a8 shell-integration/bash: mark each line in multiline prompts as secondary
Insert OSC 133 A k=s marks after each newline in PS1, so that all lines
following the first are marked as secondary prompts. This prevents ghostty
from erasing leading lines during terminal resize.
2026-01-31 14:46:18 -08:00
Mitchell Hashimoto
e7e3903151 inspector: show if we've seen semantic content in screen 2026-01-31 13:41:54 -08:00
Mitchell Hashimoto
f14a1306cd renderer: semantic prompt overlay 2026-01-31 13:31:40 -08:00
Mitchell Hashimoto
a4b7a766fe PR review 2026-01-31 11:03:21 -08:00
Mitchell Hashimoto
c3e15a5cb6 terminal: rename semantic prompt 2026-01-31 11:01:03 -08:00
Mitchell Hashimoto
5f77b0ed98 terminal: remove old semantic_prompt 2026-01-31 11:01:03 -08:00
Mitchell Hashimoto
1b2376d366 terminal: remove last semantic_prompt usage from Terminal 2026-01-31 11:01:03 -08:00