shell-integration: implement "no-cursor" option

Implement a "no-cursor" option for shell integration. This option acts
like "detect" but doesn't set the cursor shape.
This commit is contained in:
Tim Culverhouse
2023-11-07 16:24:58 -06:00
parent 36dd5ef4ee
commit 4fac674016
5 changed files with 44 additions and 23 deletions

View File

@ -532,6 +532,8 @@ keybind: Keybinds = .{},
/// configure your shell to enable the integration. /// configure your shell to enable the integration.
/// * "detect" - Detect the shell based on the filename. /// * "detect" - Detect the shell based on the filename.
/// * "fish", "zsh" - Use this specific shell injection scheme. /// * "fish", "zsh" - Use this specific shell injection scheme.
/// * "no-cursor" - Detect the shell as in 'detect', but doesn't set cursor
/// shapes
/// ///
/// The default value is "detect". /// The default value is "detect".
@"shell-integration": ShellIntegration = .detect, @"shell-integration": ShellIntegration = .detect,
@ -2182,6 +2184,7 @@ pub const ShellIntegration = enum {
detect, detect,
fish, fish,
zsh, zsh,
@"no-cursor",
}; };
/// OSC 10 and 11 default color reporting format. /// OSC 10 and 11 default color reporting format.

View File

@ -41,8 +41,10 @@ function __ghostty_precmd() {
PS2=$PS2'\[\e]133;B\a\]' PS2=$PS2'\[\e]133;B\a\]'
# Cursor # Cursor
if test "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR" != "1"; then
PS1=$PS1'\[\e[5 q\]' PS1=$PS1'\[\e[5 q\]'
PS0=$PS0'\[\e[0 q\]' PS0=$PS0'\[\e[0 q\]'
fi
# Command # Command
PS0=$PS0'$(__ghostty_get_current_command)' PS0=$PS0'$(__ghostty_get_current_command)'

View File

@ -51,6 +51,10 @@ status --is-interactive || ghostty_exit
function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration" function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
functions -e __ghostty_setup functions -e __ghostty_setup
# Check if we are setting cursors
set --local no_cursor "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR"
if test -z $no_cursor
# Change the cursor to a beam on prompt. # Change the cursor to a beam on prompt.
function __ghostty_set_cursor_beam --on-event fish_prompt -d "Set cursor shape" function __ghostty_set_cursor_beam --on-event fish_prompt -d "Set cursor shape"
echo -en "\e[5 q" echo -en "\e[5 q"
@ -58,6 +62,7 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
function __ghostty_reset_cursor --on-event fish_preexec -d "Reset cursor shape" function __ghostty_reset_cursor --on-event fish_preexec -d "Reset cursor shape"
echo -en "\e[0 q" echo -en "\e[0 q"
end end
end
# Setup prompt marking # Setup prompt marking
function __ghostty_mark_prompt_start --on-event fish_prompt --on-event fish_cancel --on-event fish_posterror function __ghostty_mark_prompt_start --on-event fish_prompt --on-event fish_cancel --on-event fish_posterror
@ -93,7 +98,9 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
set --global fish_handle_reflow 1 set --global fish_handle_reflow 1
# Initial calls for first prompt # Initial calls for first prompt
if test -z $no_cursor
__ghostty_set_cursor_beam __ghostty_set_cursor_beam
end
__ghostty_mark_prompt_start __ghostty_mark_prompt_start
__update_cwd_osc __update_cwd_osc
end end

View File

@ -200,6 +200,7 @@ _ghostty_deferred_init() {
functions[_ghostty_preexec]+=" functions[_ghostty_preexec]+="
builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'" builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'"
if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR" != 1 ]]; then
# Enable cursor shape changes depending on the current keymap. # Enable cursor shape changes depending on the current keymap.
# This implementation leaks blinking block cursor into external commands # This implementation leaks blinking block cursor into external commands
# executed from zle. For example, users of fzf-based widgets may find # executed from zle. For example, users of fzf-based widgets may find
@ -215,6 +216,7 @@ _ghostty_deferred_init() {
# Restore the blinking default shape before executing an external command # Restore the blinking default shape before executing an external command
functions[_ghostty_preexec]+=" functions[_ghostty_preexec]+="
builtin print -rnu $_ghostty_fd \$'\\e[0 q'" builtin print -rnu $_ghostty_fd \$'\\e[0 q'"
fi
# Some zsh users manually run `source ~/.zshrc` in order to apply rc file # Some zsh users manually run `source ~/.zshrc` in order to apply rc file
# changes to the current shell. This is a terrible practice that breaks many # changes to the current shell. This is a terrible practice that breaks many

View File

@ -812,6 +812,13 @@ const Subprocess = struct {
.detect => null, .detect => null,
.fish => .fish, .fish => .fish,
.zsh => .zsh, .zsh => .zsh,
.@"no-cursor" => nc: {
// We add an environment variable for the shell integration
// scripts to pick up to prevent setting cursor shapes.
// Setting to "no_cursor" means we will detect the shell
try env.put("GHOSTTY_SHELL_INTEGRATION_NO_CURSOR", "1");
break :nc null;
},
}; };
const dir = opts.resources_dir orelse break :shell null; const dir = opts.resources_dir orelse break :shell null;