This commit is contained in:
Kovid Goyal 2022-02-27 09:32:37 +05:30
commit f9621b1e11
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 49 additions and 57 deletions

View File

@ -137,6 +137,10 @@ Detailed list of changes
- Shell integration: bash: Fix rendering of multiline prompts with more than two lines (:iss:`4681`) - Shell integration: bash: Fix rendering of multiline prompts with more than two lines (:iss:`4681`)
- Shell integration: fish: Check fish version 3.3.0+ and exit on outdated versions (:pull:`4745`)
- Shell integration: fish: Fix pipestatus being overwritten (:pull:`4756`)
- Linux: Fix fontconfig alias not being used if the aliased font is dual spaced instead of monospaced (:iss:`4649`) - Linux: Fix fontconfig alias not being used if the aliased font is dual spaced instead of monospaced (:iss:`4649`)
- macOS: Add an option :opt:`macos_menubar_title_max_length` to control the max length of the window title displayed in the global menubar (:iss:`2132`) - macOS: Add an option :opt:`macos_menubar_title_max_length` to control the max length of the window title displayed in the global menubar (:iss:`2132`)

View File

@ -151,7 +151,9 @@ RPS1="{rps1}"
set -g fish_greeting set -g fish_greeting
function fish_prompt; echo -n "{fish_prompt}"; end function fish_prompt; echo -n "{fish_prompt}"; end
function fish_right_prompt; echo -n "{right_prompt}"; end function fish_right_prompt; echo -n "{right_prompt}"; end
function _ksi_test_comp; contains "{completions_dir}" $fish_complete_path; and echo ok; end function _test_comp_path; contains "{completions_dir}" $fish_complete_path; and echo ok; end
function _set_key; set -g fish_key_bindings fish_$argv[1]_key_bindings; end
function _set_status_prompt; function fish_prompt; echo -n "$pipestatus $status {fish_prompt}"; end; end
''') as pty: ''') as pty:
q = fish_prompt + ' ' * (pty.screen.columns - len(fish_prompt) - len(right_prompt)) + right_prompt q = fish_prompt + ' ' * (pty.screen.columns - len(fish_prompt) - len(right_prompt)) + right_prompt
pty.wait_till(lambda: pty.screen_contents().count(right_prompt) == 1) pty.wait_till(lambda: pty.screen_contents().count(right_prompt) == 1)
@ -164,7 +166,7 @@ function _ksi_test_comp; contains "{completions_dir}" $fish_complete_path; and e
# completion and prompt marking # completion and prompt marking
pty.send_cmd_to_child('clear') pty.send_cmd_to_child('clear')
pty.send_cmd_to_child('_ksi_test_comp') pty.send_cmd_to_child('_test_comp_path')
pty.wait_till(lambda: pty.screen_contents().count(right_prompt) == 2) pty.wait_till(lambda: pty.screen_contents().count(right_prompt) == 2)
q = '\n'.join(str(pty.screen.line(i)) for i in range(1, pty.screen.cursor.y)) q = '\n'.join(str(pty.screen.line(i)) for i in range(1, pty.screen.cursor.y))
self.ae(q, 'ok') self.ae(q, 'ok')
@ -196,16 +198,30 @@ function _ksi_test_comp; contains "{completions_dir}" $fish_complete_path; and e
pty.wait_till(lambda: pty.screen.cursor.shape == 0 and pty.screen.cursor.y > 1) pty.wait_till(lambda: pty.screen.cursor.shape == 0 and pty.screen.cursor.y > 1)
pty.write_to_child('\x04') pty.write_to_child('\x04')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM) pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
pty.send_cmd_to_child('fish_vi_key_bindings') pty.send_cmd_to_child('_set_key vi')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BLOCK) pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BLOCK)
pty.write_to_child('i')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM) pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
pty.write_to_child('\x1b') pty.write_to_child('\x1b')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BLOCK) pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BLOCK)
pty.write_to_child('r') pty.write_to_child('r')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_UNDERLINE) pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_UNDERLINE)
pty.write_to_child('\x1b')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BLOCK)
pty.write_to_child('i')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
pty.send_cmd_to_child('_set_key default')
pty.write_to_child('\x1biexit\r') # pipestatus
pty.send_cmd_to_child('clear;false|true|false')
pty.send_cmd_to_child('echo $pipestatus $status')
pty.wait_till(lambda: pty.screen_contents().count(right_prompt) == 2)
self.ae(pty.last_cmd_output(), '1 0 1 1')
pty.send_cmd_to_child('_set_status_prompt')
pty.send_cmd_to_child('false|true|false')
pty.wait_till(lambda: pty.screen_contents().count(right_prompt) == 4)
self.assertTrue(str(pty.screen.line(pty.screen.cursor.y)).startswith(f'1 0 1 1 {fish_prompt}'))
pty.send_cmd_to_child('exit')
@unittest.skipUnless(bash_ok(), 'bash not installed or too old') @unittest.skipUnless(bash_ok(), 'bash not installed or too old')
def test_bash_integration(self): def test_bash_integration(self):

View File

@ -32,18 +32,14 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after
# Enable cursor shape changes for default mode and vi mode # Enable cursor shape changes for default mode and vi mode
if not contains "no-cursor" $_ksi if not contains "no-cursor" $_ksi
and not functions -q __ksi_set_cursor
function __ksi_block_cursor --on-event fish_preexec -d "Set cursor shape to blinking default shape before executing command"
echo -en "\e[0 q"
end
function __ksi_set_cursor --on-variable fish_key_bindings -d "Set the cursor shape for different modes when switching key bindings" function __ksi_set_cursor --on-variable fish_key_bindings -d "Set the cursor shape for different modes when switching key bindings"
if test "$fish_key_bindings" = fish_default_key_bindings if test "$fish_key_bindings" = fish_default_key_bindings
not functions -q __ksi_bar_cursor || return
function __ksi_bar_cursor --on-event fish_prompt -d "Set cursor shape to blinking bar on prompt" function __ksi_bar_cursor --on-event fish_prompt -d "Set cursor shape to blinking bar on prompt"
echo -en "\e[5 q" echo -en "\e[5 q"
end end
# Change the cursor shape on first run
set -q argv[1]
and __ksi_bar_cursor
else else
functions --erase __ksi_bar_cursor functions --erase __ksi_bar_cursor
contains "$fish_key_bindings" fish_vi_key_bindings fish_hybrid_key_bindings contains "$fish_key_bindings" fish_vi_key_bindings fish_hybrid_key_bindings
@ -66,61 +62,37 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after
test "$fish_bind_mode" = "insert" && echo -en "\e[5 q" || echo -en "\e[1 q" test "$fish_bind_mode" = "insert" && echo -en "\e[5 q" || echo -en "\e[1 q"
end end
__ksi_set_cursor function __ksi_default_cursor --on-event fish_preexec -d "Set cursor shape to blinking default shape before executing command"
functions -q __ksi_bar_cursor echo -en "\e[0 q"
and __ksi_bar_cursor end
__ksi_set_cursor init
end end
# Enable prompt marking with OSC 133 # Enable prompt marking with OSC 133
if not contains "no-prompt-mark" $_ksi if not contains "no-prompt-mark" $_ksi
and not set -q __ksi_prompt_state and not set -q __ksi_prompt_state
set --global __ksi_prompt_state first-run function __ksi_mark_prompt_start --on-event fish_prompt
contains "$__ksi_prompt_state" post-exec pre-exec ""
function __ksi_prompt_start and echo -en "\e]133;D\a"
# Preserve the command exit code from $status
set --local cmd_status $status
if contains "$__ksi_prompt_state" post-exec first-run
echo -en "\e]133;D\a"
end
set --global __ksi_prompt_state prompt-start set --global __ksi_prompt_state prompt-start
echo -en "\e]133;A\a" echo -en "\e]133;A\a"
return $cmd_status
end
function __ksi_prompt_end
set --local cmd_status $status
# fish trims one trailing newline from the output of fish_prompt, so
# we need to do the same. See https://github.com/kovidgoyal/kitty/issues/4032
set --local op (__ksi_original_fish_prompt) # op is a list because fish splits on newlines in command substitution
if set -q op[2]
printf '%s\n' $op[1..-2] # print all but last element of the list, each followed by a new line
end
printf '%s' $op[-1] # print the last component without a newline
set --global __ksi_prompt_state prompt-end
echo -en "\e]133;B\a"
return $cmd_status
end end
__ksi_mark_prompt_start
functions -c fish_prompt __ksi_original_fish_prompt functions -c fish_prompt __ksi_original_fish_prompt
function fish_prompt
# Check whether the mode prompt function exists and is not empty # fish trims one trailing newline from the output of fish_prompt, so
if functions --no-details fish_mode_prompt | string match -qnvr '^ *(#|function |end$|$)' # we need to do the same. See https://github.com/kovidgoyal/kitty/issues/4032
# When vi mode changes, fish redraws fish_prompt when fish_mode_prompt is empty. # op is a list because fish splits on newlines in command substitution
# Some prompt rely on this side effect to draw vi mode indicator. set --local op (__ksi_original_fish_prompt)
# See https://github.com/starship/starship/issues/1283 # print all but last element of the list, each followed by a new line
functions -c fish_mode_prompt __ksi_original_fish_mode_prompt set -q op[2]
function fish_mode_prompt and printf '%s\n' $op[1..-2]
__ksi_prompt_start # print the last component without a newline
__ksi_original_fish_mode_prompt printf '%s' $op[-1]
end set --global __ksi_prompt_state prompt-end
function fish_prompt echo -en "\e]133;B\a"
__ksi_prompt_end
end
else
function fish_prompt
__ksi_prompt_start
__ksi_prompt_end
end
end end
function __ksi_mark_output_start --on-event fish_preexec function __ksi_mark_output_start --on-event fish_preexec