akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.33k stars 77 forks source link

[ncurses 6.1] ctrl+l and clear not working properly #417

Closed cmndrsp0ck closed 4 months ago

cmndrsp0ck commented 4 months ago

ble version: 0.4.0-devel4+ef8272a

ble.sh, version 0.4.0-devel4+ef8272a (noarch) [git 2.37.3, GNU Make 4.3, GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)]
bash-completion, version 2.11 (hash:b42f5d6a7ad6d4921ec73838ba54a96d6bd30936, 77071 bytes) (noarch)
fzf key-bindings, version +3dd42f5a (noarch)
WARNING: fzf integration "integration/fzf-key-bindings" is not activated.
fzf completion, version +3dd42f5a (noarch) (integration: on)
locale: LANG=en_US.UTF-8
terminal: TERM=tmux-256color wcwidth=14.0-west/15.1-2+ri, tmux:0 (84;0;0), tmux:0 (84;0;0)

ctrl+l and clear completely wipe the previous command's output. I tried it in just terminal as well as running in tmux. Used Tilix as well as Alacritty. Running ble-detach allows me to clear the screen without completely removing the previous command's output. once I ble-attach, it will stop ctrl+l/clear from working as it previously did.

Wasn't sure if canvas_winch_action was the variable to adjust but I tried it anyway. Unfortunately no luck.

akinomyoga commented 4 months ago

Thanks for the report.

fzf key-bindings, version +3dd42f5a (noarch)
WARNING: fzf integration "integration/fzf-key-bindings" is not activated.

I'm not sure if it is related, but how do you set up the fzf keybindings? The fzf keybindings need adjustments. You can check README 2.8.

ctrl+l and clear completely wipe the previous command's output. I tried it in just terminal as well as running in tmux. Used Tilix as well as Alacritty. Running ble-detach allows me to clear the screen without completely removing the previous command's output. once I ble-attach, it will stop ctrl+l/clear from working as it previously did.

(parent session)$ bash --norc        # start a plain session
(child session)$ source /path/to/ble.sh --norc       # load ble.sh without any configuration
(child session)$ clear        # check the behavior
(child session)$ exit
(parent session)$ 

Wasn't sure if canvas_winch_action was the variable to adjust but I tried it anyway. Unfortunately no luck.

canvas_winch_action is unrelated here. It is the option to control the behavior when the terminal display size is changed.

cmndrsp0ck commented 4 months ago

I moved my bashrc and .profile, ran through the following commands

user@system-ncc1701:~$ bash --norc 
bash-5.1$ source ~/.local/share/blesh/ble.sh --norc
bash-5.1$ pwd
/home/user
bash-5.1$ ls -alhF 
...

running clear or ctrl+l still caused the previous output to be removed. once I used ble-detach, I was able to run commands and successfully clear the screen with the ability to scroll back up into the previous output.

my previous config that worked for quite a while was the following:

if [[ -f ${HOME}/.local/share/blesh/ble.sh ]]; then
    source ${HOME}/.local/share/blesh/ble.sh;
    blesh_loaded="true"
fi

if [[ -f ~/.fzf.bash ]]; then
        source ~/.fzf.bash
        if [[ -v $blesh_loaded ]]; then
              # clear blesh completer for cd
              blehook/eval-after-load complete 'unset -f ble/cmdinfo/complete:cd'

              # patch fzf functions
              ble/function#advice around __fzf_generic_path_completion _fzf_complete.advice
              ble/function#advice around _fzf_complete                 _fzf_complete.advice
              ble/function#advice around _fzf_complete_kill            _fzf_complete.advice
              function _fzf_complete.advice {
                      [[ :$comp_type: == *:auto:* ]] && { compopt -o default; return; }
                      compopt -o noquote
                      COMP_WORDS=("${comp_words[@]}") COMP_CWORD=$comp_cword
                      COMP_LINE=$comp_line COMP_POINT=$comp_point
                      ble/function#push printf '[[ $1 == "\e[5n" ]] || builtin printf "$@"'
                      ble/function#advice/do < /dev/tty &> /dev/tty
                      ble/function#pop printf
                      ble/textarea#invalidate
              }
        fi
fi
akinomyoga commented 4 months ago

Sorry for the late reply.

I was able to run commands and successfully clear the screen with the ability to scroll back up into the previous output.

It turned out that the command tput clear in newer systems seems to return both control sequences of clear (clear screen) and E3 (clear screen and scrollback buffer). ble.sh uses the control sequence of clear for C-l, and it determines the sequence by tput clear, which is affected by the new behavior of tput clear. Maybe the same thing is happening in your system.

$ infocmp | grep clear
$ tput clear | cat -v
$ clear | cat -v

edit: But this assumption slightly contradicts your report. Based on your report, the clear command outside ble.sh (or in the detached state of ble.sh) doesn't clear the scrollback buffer of the terminal. I guess the clear command still clears everything including the scrollback buffer outside ble.sh. Could you confirm that?

cmndrsp0ck commented 4 months ago
user@system-ncc1701 in ~
❯❯❯ infocmp | grep clear
        clear=\E[H\E[J, cnorm=\E[34h\E[?25h, cr=\r,

user@system-ncc1701 in ~
❯❯❯ tput clear | cat -v
^[[H^[[J^[[3J[ble: EOF]

user@system-ncc1701 in ~
❯❯❯ clear | cat -v
^[[H^[[J^[[3J[ble: EOF]

with ble-detach or just not enabled at all, the clear command clears the screen but I can still view the scrollback buffer.

akinomyoga commented 4 months ago

Thank you for those results.

with ble-detach or just not enabled at all, the clear command clears the screen but I can still view the scrollback buffer.

Thank you for confirmation. I'm interested in the result of clear | cat -v in the detached state. Could you check the result of the following command in the detached state?

$ clear | cat -v        # <-- in detached state

I checked the source code of ncurses. It seems ncurses 6.1 started to treat the argument clear in a special way. An option -x was added to tput to get terminfo's clear entry. However, the option -x is not POSIX and is unsupported by tput not based on ncurses. I probably have to add a workaround in obtaining terminfo's clear.

cmndrsp0ck commented 4 months ago

here's the output from a shell (--norc)

bash-5.1$ clear | cat -v; echo
^[[H^[[2J^[[3J
bash-5.1$ source ~/.local/share/blesh/ble.sh 
bash-5.1$ clear | cat -v; echo
^[[H^[[2J^[[3J
bash-5.1$ ble-detach
[ble: detached]
Please run `stty sane' to recover the correct TTY state.
bash-5.1$  stty sane;            
bash-5.1$ clear | cat -v; echo
^[[H^[[2J^[[3J
akinomyoga commented 4 months ago

Thank you! Hmm, even in the --norc session and in the detached state, clear seems to produce ^[[3J (clearing scrollback buffer) in your environment. I'm not sure why in your environment, clear doesn't clear the scrollback buffer in the --norc session and in the detached state.

akinomyoga commented 4 months ago

I added a workaround 18dd51abdcbf943a08b6fccdf4c50c3694067354. Could you check it?

cmndrsp0ck commented 4 months ago

nice. Ok, so ctrl+l works just like it did before. clear wipes the screen and scrollback buffer.

bash-5.1$ source ~/.local/share/blesh/ble.sh
bash-5.1$ clear | cat -v; echo
^[[H^[[J^[[3J
akinomyoga commented 4 months ago

clear wipes the screen and scrollback buffer.

I don't have an idea why the behavior of clear changes in your environment. At least, https://github.com/akinomyoga/ble.sh/issues/417#issuecomment-1975756757 tells that the clear still outputs E3 in the --norc session and in the detached state, which suggests that it should wipe out the scrollback buffer of the terminal.

Could you check again the result of clear in the --norc session (or in the detached state)? (Note: I'm not asking about the behavior of C-l but specifically the result of running the command clear. C-l and clear are implemented independently, so the behaviors can be different in general).

In my understanding, as far as I see the output in https://github.com/akinomyoga/ble.sh/issues/417#issuecomment-1975756757, clear is supposed to wipe out the scrollback buffer even outside ble.sh. In fact, in my environment, clear consistently wipes out the scrollback buffer (in terminals with the E3 support and ncurses >= 6.1) both inside and outside ble.sh.

cmndrsp0ck commented 4 months ago

the scrollback buffer is being wiped in the --norc session with and without ble.sh being loaded. Here is the output:

bash --norc
bash-5.1$ clear | cat -v; echo 
^[[H^[[2J^[[3J

That works for me. The main issue was ctrl+l also wiping scrollback but your last push has corrected that.

akinomyoga commented 4 months ago

OK, thank you for your confirmation!