From e192066e982118eef87cecda987aba832c1f3232 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 12 Jan 2021 12:42:52 +0100 Subject: [PATCH] Add $fish_handle_reflow to disable winch handler Overriding event handlers is annoying. --- doc_src/index.rst | 2 ++ .../functions/__fish_config_interactive.fish | 33 +++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/doc_src/index.rst b/doc_src/index.rst index cd399e751..c7f08f281 100644 --- a/doc_src/index.rst +++ b/doc_src/index.rst @@ -1249,6 +1249,8 @@ You can change the settings of fish by changing the values of certain variables. - ``fish_greeting``, the greeting message printed on startup. This is printed by a function of the same name that can be overridden for more complicated changes (see :ref:`funced ` +- ``fish_handle_reflow``, determines whether fish should try to repaint the commandline when the terminal resizes. In terminals that reflow text this should be disabled. Set it to 1 to enable, anything else to disable. + - ``fish_history``, the current history session name. If set, all subsequent commands within an interactive fish session will be logged to a separate file identified by the value of the variable. If unset, or set to ``default``, the default session name "fish" is used. If set to an diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 7bd17dd52..d28938327 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -241,24 +241,31 @@ function __fish_config_interactive -d "Initializations that should be performed # __fish_enable_focus end - function __fish_winch_handler --on-signal WINCH -d "Repaint screen when window changes size" + # Detect whether the terminal reflows on its own + # If it does we shouldn't do it. + # Allow $fish_handle_reflow to override it. + if not set -q fish_handle_reflow # VTE reflows the text itself, so us doing it inevitably races against it. # Guidance from the VTE developers is to let them repaint. if set -q VTE_VERSION - return - end - # Same for alacritty - if string match -q -- 'alacritty*' $TERM - return - end - # Konsole since version 21.04(.00) - # Note that this is optional, but since we have no way of detecting it - # we go with the default, which is true. - if set -q KONSOLE_VERSION + # Same for alacritty + or string match -q -- 'alacritty*' $TERM + set -g fish_handle_reflow 0 + else if set -q KONSOLE_VERSION and test "$KONSOLE_VERSION" -ge 210400 2>/dev/null - return + # Konsole since version 21.04(.00) + # Note that this is optional, but since we have no way of detecting it + # we go with the default, which is true. + set -g fish_handle_reflow 0 + else + set -g fish_handle_reflow 1 + end + end + + function __fish_winch_handler --on-signal WINCH -d "Repaint screen when window changes size" + if test "$fish_handle_reflow" = 1 2>/dev/null + commandline -f repaint >/dev/null 2>/dev/null end - commandline -f repaint >/dev/null 2>/dev/null end # Notify terminals when $PWD changes (issue #906).