Skip to content

Commit 059bd54

Browse files
committed
elvish: improve OSC 133 semantic prompt support
Add `aid=$pid` to 133;A and 133;D for nested shell tracking, and fix the state comparison which was incorrectly using `constantly` (comparing a string to a function, which always evaluated to true). OSC 133;B (input start) and 133;P;k=r (right prompt) cannot be reliably implemented at the script level because Elvish escapes control characters in prompt function output, and writing directly to /dev/tty has timing issues because Elvish renders its prompts on a background thread. Full semantic prompt support requires a native implementation: elves/elvish#1917 See: ghostty-org#10523
1 parent 472b926 commit 059bd54

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/shell-integration/elvish/lib/ghostty-integration.elv

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
# List of enabled shell integration features
1212
var features = [(str:split ',' $E:GHOSTTY_SHELL_FEATURES)]
1313

14-
# helper used by `mark-*` functions
14+
# State tracking for semantic prompt sequences
15+
# Values: 'prompt-start', 'pre-exec', 'post-exec'
1516
fn set-prompt-state {|new| set-env __ghostty_prompt_state $new }
1617

1718
fn mark-prompt-start {
18-
if (not-eq prompt-start (constantly $E:__ghostty_prompt_state)) {
19-
printf "\e]133;D\a"
19+
if (not-eq $E:__ghostty_prompt_state 'prompt-start') {
20+
printf "\e]133;D;aid="$pid"\a"
2021
}
2122
set-prompt-state 'prompt-start'
22-
printf "\e]133;A\a"
23+
printf "\e]133;A;aid="$pid"\a"
2324
}
2425

2526
fn mark-output-start {|_|
@@ -44,9 +45,15 @@
4445
}
4546
}
4647

47-
printf "\e]133;D;"$exit-status"\a"
48+
printf "\e]133;D;"$exit-status";aid="$pid"\a"
4849
}
4950

51+
# NOTE: OSC 133;B (end of prompt, start of input) cannot be reliably
52+
# implemented at the script level in Elvish. The prompt function's output is
53+
# escaped, and writing to /dev/tty has timing issues because Elvish renders
54+
# its prompts on a background thread. Full semantic prompt support requires a
55+
# native implementation: https://github.com/elves/elvish/pull/1917
56+
5057
fn sudo-with-terminfo {|@args|
5158
var sudoedit = $false
5259
for arg $args {

0 commit comments

Comments
 (0)