New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to bind the "Ctrl-l" to empty the screen instead of clearing the terminal buffer? #2855

Closed
c02y opened this Issue Mar 24, 2016 · 24 comments

Comments

Projects
None yet
5 participants
@c02y

c02y commented Mar 24, 2016

I use fish with tmux, fish provides a default binding for "C-l":

bind \cl 'clear; commandline -f repaint'

but it will clear the terminal buffer (leaving only one whole screen of content if I scroll it) and I won't be able to scroll the terminal to view the content or the result of the history commands.

I can make it work by defining a key binding in tmux configuration file, but it seems there is a bug with it because of the conflict of two bindings in fish and tmux. And I have to call a function defined in ~/.config/fish/functions when hitting Ctrl-l (clear and then call the function), so it is better to make a binding in config.fish to replace the default one.

So how can I do that?

@krader1961 krader1961 added the question label Mar 24, 2016

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Mar 24, 2016

Contributor

The way to create your own key bindings, including overriding a default binding, is to create a function named fish_user_key_bindings and put your own bindings in that function. For example, you might put something like the following in your config.fish:

if status --is-interactive
    source $HOME/.config/fish/interactive.fish
    function fish_user_key_bindings
       bind \n backward-delete-char
       bind -M insert \n backward-delete-char
       bind -m insert \n backward-delete-char
    end
end
Contributor

krader1961 commented Mar 24, 2016

The way to create your own key bindings, including overriding a default binding, is to create a function named fish_user_key_bindings and put your own bindings in that function. For example, you might put something like the following in your config.fish:

if status --is-interactive
    source $HOME/.config/fish/interactive.fish
    function fish_user_key_bindings
       bind \n backward-delete-char
       bind -M insert \n backward-delete-char
       bind -m insert \n backward-delete-char
    end
end
@c02y

This comment has been minimized.

Show comment
Hide comment
@c02y

c02y Mar 24, 2016

I know how to bind a key in fish,

Please read the description.

On March 25, 2016 01:58:27 Kurtis Rader notifications@github.com wrote:

The way to create your own key bindings, including overriding a default
binding, is to create a function named fish_user_key_bindings and put
your own bindings in that function. For example, you might put something
like the following in your config.fish:

if status --is-interactive
    source $HOME/.config/fish/interactive.fish
    function fish_user_key_bindings
       bind \n backward-delete-char
       bind -M insert \n backward-delete-char
       bind -m insert \n backward-delete-char
    end
end

You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2855 (comment)

c02y commented Mar 24, 2016

I know how to bind a key in fish,

Please read the description.

On March 25, 2016 01:58:27 Kurtis Rader notifications@github.com wrote:

The way to create your own key bindings, including overriding a default
binding, is to create a function named fish_user_key_bindings and put
your own bindings in that function. For example, you might put something
like the following in your config.fish:

if status --is-interactive
    source $HOME/.config/fish/interactive.fish
    function fish_user_key_bindings
       bind \n backward-delete-char
       bind -M insert \n backward-delete-char
       bind -m insert \n backward-delete-char
    end
end

You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2855 (comment)

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Mar 24, 2016

Contributor

Please read the description.

I did and couldn't make sense of what you're asking. But you ended with

so it is better to make a binding in config.fish to replace the default one. So how I do that?

So I took a guess that you needed a pointer on how to create a binding to replace the default one for [ctrl-L].

Contributor

krader1961 commented Mar 24, 2016

Please read the description.

I did and couldn't make sense of what you're asking. But you ended with

so it is better to make a binding in config.fish to replace the default one. So how I do that?

So I took a guess that you needed a pointer on how to create a binding to replace the default one for [ctrl-L].

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Mar 24, 2016

Member

Of note here is that clear is an external command that as far as I can tell just does the same thing as echo \e\[H\e\2J - an escape sequence that the terminal recognizes and then proceeds to do its thing.

So the question here is if the mechanism is just deficient for you in tmux (which acts as a terminal), or in your actual terminal (to which tmux talks).

What happens for me (and presumably @krader1961, which is why he does not understand what you're asking), is that the terminal adds a full screen's worth of whitespace, pushing the old content out. I can still scroll back, though. This is with KDE's konsole (version 15.12) and no multiplexer (screen or tmux).

Member

faho commented Mar 24, 2016

Of note here is that clear is an external command that as far as I can tell just does the same thing as echo \e\[H\e\2J - an escape sequence that the terminal recognizes and then proceeds to do its thing.

So the question here is if the mechanism is just deficient for you in tmux (which acts as a terminal), or in your actual terminal (to which tmux talks).

What happens for me (and presumably @krader1961, which is why he does not understand what you're asking), is that the terminal adds a full screen's worth of whitespace, pushing the old content out. I can still scroll back, though. This is with KDE's konsole (version 15.12) and no multiplexer (screen or tmux).

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Mar 24, 2016

Member

Works about the same in tmux for me, except that tmux will buffer the output instead of the actual terminal, so I'd need to use the tmux bindings to scroll up or down ("Ctrl-b [", then arrow keys to move around, then "q" to stop scrolling).

Member

faho commented Mar 24, 2016

Works about the same in tmux for me, except that tmux will buffer the output instead of the actual terminal, so I'd need to use the tmux bindings to scroll up or down ("Ctrl-b [", then arrow keys to move around, then "q" to stop scrolling).

@c02y

This comment has been minimized.

Show comment
Hide comment
@c02y

c02y Mar 25, 2016

I'd need to use the tmux bindings to scroll up or down ("Ctrl-b [", then arrow keys to move around, then "q" to stop scrolling

This is what I do.

The Weird thing is I got three computers, the same configuration works just as what I want in two of them:
Work:

  1. Ubuntu 14.04. LTS 32-bit, fish-shell v2.2.0, tmux v2.2, yakuake v2.9.9 based on konsole v2.13.2
  2. Centos 6.5 32-bit, fish-shell v2.2.0, tmux v2.2, yakuake v2.9.8 based on konsole v.2.3.3

Not work:
Fedora 23 63-bit

I currently got no access to the Fedora computer, I'll provide more info about the as soon as I can.

c02y commented Mar 25, 2016

I'd need to use the tmux bindings to scroll up or down ("Ctrl-b [", then arrow keys to move around, then "q" to stop scrolling

This is what I do.

The Weird thing is I got three computers, the same configuration works just as what I want in two of them:
Work:

  1. Ubuntu 14.04. LTS 32-bit, fish-shell v2.2.0, tmux v2.2, yakuake v2.9.9 based on konsole v2.13.2
  2. Centos 6.5 32-bit, fish-shell v2.2.0, tmux v2.2, yakuake v2.9.8 based on konsole v.2.3.3

Not work:
Fedora 23 63-bit

I currently got no access to the Fedora computer, I'll provide more info about the as soon as I can.

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Mar 25, 2016

Contributor

I see the same behavior that @faho mentioned. Although when he says "the terminal adds a full screen's worth of whitespace, pushing the old content out" that isn't an entirely accurate description of what occurs. Still, what we're all seeing is the expected behavior. So I still do not understand what the problem is let alone what behavior you would prefer.

Is it simply that you don't want the current screen to be cleared, thus losing the ability to see that content by scrolling back in the tmux or terminal buffer? If so, then simply replace the clear command in the \cL binding with a command that actually writes enough spaces to fill the screen. Thereby actually "pushing the old content out" as @faho described. Unfortunately, doing so efficiently (i.e., with the minimum number of space characters) requires parsing the output of the stty -a command to get the rows and columns values. Then compute their product and write that many spaces.

Contributor

krader1961 commented Mar 25, 2016

I see the same behavior that @faho mentioned. Although when he says "the terminal adds a full screen's worth of whitespace, pushing the old content out" that isn't an entirely accurate description of what occurs. Still, what we're all seeing is the expected behavior. So I still do not understand what the problem is let alone what behavior you would prefer.

Is it simply that you don't want the current screen to be cleared, thus losing the ability to see that content by scrolling back in the tmux or terminal buffer? If so, then simply replace the clear command in the \cL binding with a command that actually writes enough spaces to fill the screen. Thereby actually "pushing the old content out" as @faho described. Unfortunately, doing so efficiently (i.e., with the minimum number of space characters) requires parsing the output of the stty -a command to get the rows and columns values. Then compute their product and write that many spaces.

@c02y

This comment has been minimized.

Show comment
Hide comment
@c02y

c02y Mar 25, 2016

simply replace the clear command in the \cL binding with a command that actually writes enough spaces to fill the screen.

do I have to do this, is there any existed smarter command or function to replace clear?

c02y commented Mar 25, 2016

simply replace the clear command in the \cL binding with a command that actually writes enough spaces to fill the screen.

do I have to do this, is there any existed smarter command or function to replace clear?

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Mar 25, 2016

Contributor

is there any existed smarter command or function to replace clear?

Not that I am aware of but try this:

function slow_clear --description 'Clear screen by writing lots of spaces'
    set -l size (string match -r '(\d+) (\d+)' (stty size))
    set -l chars (math "$size[2] * $size[3]")
    for x in (seq $chars)
        echo -n ' '
    end
    echo ''
end

That assumes your system supports stty size writing the rows and columns of the terminal.

Contributor

krader1961 commented Mar 25, 2016

is there any existed smarter command or function to replace clear?

Not that I am aware of but try this:

function slow_clear --description 'Clear screen by writing lots of spaces'
    set -l size (string match -r '(\d+) (\d+)' (stty size))
    set -l chars (math "$size[2] * $size[3]")
    for x in (seq $chars)
        echo -n ' '
    end
    echo ''
end

That assumes your system supports stty size writing the rows and columns of the terminal.

@krader1961 krader1961 self-assigned this Mar 25, 2016

@c02y

This comment has been minimized.

Show comment
Hide comment
@c02y

c02y Mar 25, 2016

the slow_clear is really slow and I can see some movements in the screen, besides, the prompt will be at the bottom of the terminal not the top after executing slow_clear function.

c02y commented Mar 25, 2016

the slow_clear is really slow and I can see some movements in the screen, besides, the prompt will be at the bottom of the terminal not the top after executing slow_clear function.

@krader1961 krader1961 closed this Mar 25, 2016

@zanchey

This comment has been minimized.

Show comment
Hide comment
@zanchey

zanchey Mar 25, 2016

Member

What about

bind \cl 'for i in (seq 1 $LINES); echo; end; clear; commandline -f repaint'

This pushes enough blank lines into the output buffer that clear overwrites them all.

Member

zanchey commented Mar 25, 2016

What about

bind \cl 'for i in (seq 1 $LINES); echo; end; clear; commandline -f repaint'

This pushes enough blank lines into the output buffer that clear overwrites them all.

@peterstory

This comment has been minimized.

Show comment
Hide comment
@peterstory

peterstory Feb 9, 2017

Doesn't requiring configuration like this to get expected behavior go against Fish's philosophy of having a great out-of-box experience? Coming from Bash, I think that the expected behavior is not to kill scrollback. So I think Fish should have a similar default behavior, unless there's a good reason not to.

peterstory commented Feb 9, 2017

Doesn't requiring configuration like this to get expected behavior go against Fish's philosophy of having a great out-of-box experience? Coming from Bash, I think that the expected behavior is not to kill scrollback. So I think Fish should have a similar default behavior, unless there's a good reason not to.

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Feb 9, 2017

Member

@peterstory: The expectation here is that this is a weird terminal/multiplexer bug that can be worked around via binding something different.

It originally didn't seem like anyone but @c02y had this issue, so we couldn't reproduce it and just chalked it up to weirdness elsewhere. Are you saying that you have this issue?

Because I'd certainly consider using a different binding, but we then need to figure out what proper behavior here is. We certainly don't intentionally do anything to "kill scrollback".

If you have this issue, we're going to need to know your terminal and multiplexer (if any) so we can attempt to reproduce.

Member

faho commented Feb 9, 2017

@peterstory: The expectation here is that this is a weird terminal/multiplexer bug that can be worked around via binding something different.

It originally didn't seem like anyone but @c02y had this issue, so we couldn't reproduce it and just chalked it up to weirdness elsewhere. Are you saying that you have this issue?

Because I'd certainly consider using a different binding, but we then need to figure out what proper behavior here is. We certainly don't intentionally do anything to "kill scrollback".

If you have this issue, we're going to need to know your terminal and multiplexer (if any) so we can attempt to reproduce.

@peterstory

This comment has been minimized.

Show comment
Hide comment
@peterstory

peterstory Feb 10, 2017

Ah, that makes sense. But I'm actually just using Terminal.app on MacOS Sierra, 10.12.3.

peterstory commented Feb 10, 2017

Ah, that makes sense. But I'm actually just using Terminal.app on MacOS Sierra, 10.12.3.

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Feb 10, 2017

Contributor

Are you seeing a problem, @peterstory? Because I just tested bash and it does the same thing fish does so they produce the same result. Both Terminal.app and iTerm2.app. Both fish and bash use the \e[2J sequence to erase the entire visible screen.

Contributor

krader1961 commented Feb 10, 2017

Are you seeing a problem, @peterstory? Because I just tested bash and it does the same thing fish does so they produce the same result. Both Terminal.app and iTerm2.app. Both fish and bash use the \e[2J sequence to erase the entire visible screen.

@peterstory

This comment has been minimized.

Show comment
Hide comment
@peterstory

peterstory Feb 10, 2017

The attached screenshots should help demonstrate the issue I'm seeing. I opened two Terminal.app windows. The left started with bash, and the right with fish. Then, I did ls -l /System/Library a couple times in both windows. Then, I did Control-L in both windows.

As can be seen in the first screenshot, the scrollbar in the left window is shorter than in the right window, indicating that the left window has more scrollback. Scrolling up, in the second screenshot you can see that the right-hand window's scrollback has been truncated.

screen shot 2017-02-10 at 9 14 16 am

screen shot 2017-02-10 at 9 14 31 am

peterstory commented Feb 10, 2017

The attached screenshots should help demonstrate the issue I'm seeing. I opened two Terminal.app windows. The left started with bash, and the right with fish. Then, I did ls -l /System/Library a couple times in both windows. Then, I did Control-L in both windows.

As can be seen in the first screenshot, the scrollbar in the left window is shorter than in the right window, indicating that the left window has more scrollback. Scrolling up, in the second screenshot you can see that the right-hand window's scrollback has been truncated.

screen shot 2017-02-10 at 9 14 16 am

screen shot 2017-02-10 at 9 14 31 am

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Feb 10, 2017

Member

Okay, I see what's happening here. The clear sequence works like this:

CSI n J

ED – Erase in Display

Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).

("CSI" here is \e[)

Both my clear command and (for some reason) tput clear print "CSI 3 J ; CSI H ; CSI 2 J". I.e. delete scrollback, move cursor to home (IIRC) and then clear entire screen. This even though infocmp says my terminal's clear sequence is \E[\E[2J.

bash only uses that one.

The reason why we haven't caught this? Probably that we didn't scroll back enough or look at the scrollbar, since my term doesn't seem to delete the entire scrollback, but leaves a page.

The cleanest solution here would be to find something to stop clear from adding the 3J sequence, the uglier one is to replace clear invocation with printf \e\[H\e\[2J, or to check terminfo for the sequence and use it ourselves.

Member

faho commented Feb 10, 2017

Okay, I see what's happening here. The clear sequence works like this:

CSI n J

ED – Erase in Display

Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).

("CSI" here is \e[)

Both my clear command and (for some reason) tput clear print "CSI 3 J ; CSI H ; CSI 2 J". I.e. delete scrollback, move cursor to home (IIRC) and then clear entire screen. This even though infocmp says my terminal's clear sequence is \E[\E[2J.

bash only uses that one.

The reason why we haven't caught this? Probably that we didn't scroll back enough or look at the scrollbar, since my term doesn't seem to delete the entire scrollback, but leaves a page.

The cleanest solution here would be to find something to stop clear from adding the 3J sequence, the uglier one is to replace clear invocation with printf \e\[H\e\[2J, or to check terminfo for the sequence and use it ourselves.

@faho faho reopened this Feb 10, 2017

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Feb 10, 2017

Member

This was added to ncurses 6.0 (see https://www.gnu.org/software/ncurses/ncurses.html):

modified the clear program to take into account the “E3” extended capability to clear the terminal's scrollback buffer.

xterm of course has that cap. To view it, you'll need to add "-x" to infocmp to also show "unknown capabilities".

I have to say, I strongly disagree with the decision to bind this so strongly to clear - they are two different capabilities, so sending one should not send the other automatically. This seems uncharacteristic. There doesn't even seem to be a way to turn it off - clear ignores all arguments.

So unless @krader1961 does some magic, I'm writing a function to figure out just that sequence from terminfo.

Member

faho commented Feb 10, 2017

This was added to ncurses 6.0 (see https://www.gnu.org/software/ncurses/ncurses.html):

modified the clear program to take into account the “E3” extended capability to clear the terminal's scrollback buffer.

xterm of course has that cap. To view it, you'll need to add "-x" to infocmp to also show "unknown capabilities".

I have to say, I strongly disagree with the decision to bind this so strongly to clear - they are two different capabilities, so sending one should not send the other automatically. This seems uncharacteristic. There doesn't even seem to be a way to turn it off - clear ignores all arguments.

So unless @krader1961 does some magic, I'm writing a function to figure out just that sequence from terminfo.

@faho faho self-assigned this Feb 10, 2017

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Feb 11, 2017

Contributor

@peterstory: What does otool -L (command -s clear) output? On my system it is the macOS /usr/bin/clear command which uses ncurses version 5.4. If you have a different clear command that could explain why you are seeing a different result. Also, what does clear | od -tx1z report? If that doesn't work do clear | od -ba.

This document, http://invisible-island.net/xterm/ctlseqs/ctlseqs.html, states that Ps == 2 is "Erase All" while Ps == 3 is "Erase Saved Lines". Which appears to mean it also erases the scrollback and thus the opposite of what you and everyone else wants. If a clear command that is linked against ncurses 6.0 uses the Ps 3 variant that is definitely unfortunate but not strictly speaking fish's fault. My Ubuntu 16.10 server still has ncurses 5.9 but I did confirm that the clear command nonetheless output the \e[3J sequence even though tput clear does not.

@faho: I tentatively agree that we want to avoid the behavior of the new ncurses clear command and using tput clear is probably the simplest change. But before we change anything I'd like to understand why @peterstory and I are seeing different behavior on macOS as there may be something else going on.

Contributor

krader1961 commented Feb 11, 2017

@peterstory: What does otool -L (command -s clear) output? On my system it is the macOS /usr/bin/clear command which uses ncurses version 5.4. If you have a different clear command that could explain why you are seeing a different result. Also, what does clear | od -tx1z report? If that doesn't work do clear | od -ba.

This document, http://invisible-island.net/xterm/ctlseqs/ctlseqs.html, states that Ps == 2 is "Erase All" while Ps == 3 is "Erase Saved Lines". Which appears to mean it also erases the scrollback and thus the opposite of what you and everyone else wants. If a clear command that is linked against ncurses 6.0 uses the Ps 3 variant that is definitely unfortunate but not strictly speaking fish's fault. My Ubuntu 16.10 server still has ncurses 5.9 but I did confirm that the clear command nonetheless output the \e[3J sequence even though tput clear does not.

@faho: I tentatively agree that we want to avoid the behavior of the new ncurses clear command and using tput clear is probably the simplest change. But before we change anything I'd like to understand why @peterstory and I are seeing different behavior on macOS as there may be something else going on.

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Feb 11, 2017

Member

using tput clear is probably the simplest change.

That unfortunately does not work on my system:

> tput clear | od -t x1z
0000000 1b 5b 33 4a 1b 5b 48 1b 5b 32 4a                 >.[3J.[H.[2J<
0000013

If a clear command that is linked against ncurses 6.0

It's not just "linked against" ncurses 6.0, it's from the ncurses 6.0 release. This "clear" is part of the ncurses package.

I have prepared a function that reads infocmps output for the correct sequence to use and then printfs it. This still might fail on weird terminals - I have no idea if it'll interpret the "z-100" sequence of "\EE$<5*/>" correctly.

function fish_clear --description 'Clear the terminal'
    # clear from ncurses >= 6.0 also sends the "E3" sequence that clears scrollback
    # Even `tput clear` does it.
    # So instead we figure out just the "clear" sequence.
    # (It might be possible to just always `printf \e\[H\e\[2J`, but let's be pedantic here)
	set -l clear (infocmp | string match -r 'clear=[^,]+,' | string replace -r 'clear=(.+),' '$1')
    if test -n "$clear"
        printf (string replace -a "E" "e" -- $clear)
    end
end
Member

faho commented Feb 11, 2017

using tput clear is probably the simplest change.

That unfortunately does not work on my system:

> tput clear | od -t x1z
0000000 1b 5b 33 4a 1b 5b 48 1b 5b 32 4a                 >.[3J.[H.[2J<
0000013

If a clear command that is linked against ncurses 6.0

It's not just "linked against" ncurses 6.0, it's from the ncurses 6.0 release. This "clear" is part of the ncurses package.

I have prepared a function that reads infocmps output for the correct sequence to use and then printfs it. This still might fail on weird terminals - I have no idea if it'll interpret the "z-100" sequence of "\EE$<5*/>" correctly.

function fish_clear --description 'Clear the terminal'
    # clear from ncurses >= 6.0 also sends the "E3" sequence that clears scrollback
    # Even `tput clear` does it.
    # So instead we figure out just the "clear" sequence.
    # (It might be possible to just always `printf \e\[H\e\[2J`, but let's be pedantic here)
	set -l clear (infocmp | string match -r 'clear=[^,]+,' | string replace -r 'clear=(.+),' '$1')
    if test -n "$clear"
        printf (string replace -a "E" "e" -- $clear)
    end
end
@peterstory

This comment has been minimized.

Show comment
Hide comment
@peterstory

peterstory Feb 11, 2017

Ah, perhaps the issue is that I've inadvertently installed a newer version of ncurses with MacPorts!

> otool -L (command -s clear)
/opt/local/bin/clear:
	/opt/local/lib/libncurses.6.dylib (compatibility version 6.0.0, current version 6.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
> clear | od -ba
0000000   033 133 063 112 033 133 110 033 133 062 112                    
         esc   [   3   J esc   [   H esc   [   2   J                    
0000013
> clear | od -tx1z
od: z: unrecognised format character
> port installed | grep curse
  ncurses @6.0_0 (active)

peterstory commented Feb 11, 2017

Ah, perhaps the issue is that I've inadvertently installed a newer version of ncurses with MacPorts!

> otool -L (command -s clear)
/opt/local/bin/clear:
	/opt/local/lib/libncurses.6.dylib (compatibility version 6.0.0, current version 6.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
> clear | od -ba
0000000   033 133 063 112 033 133 110 033 133 062 112                    
         esc   [   3   J esc   [   H esc   [   2   J                    
0000013
> clear | od -tx1z
od: z: unrecognised format character
> port installed | grep curse
  ncurses @6.0_0 (active)
@c02y

This comment has been minimized.

Show comment
Hide comment
@c02y

c02y Feb 12, 2017

Guys, sorry about this, I've solved this long time ago.

Here is my solution:
in config.fish

function fish_user_key_bindings
    bind \cl 'clear; commandline -f repaint'
end

in tmux.conf

bind -n C-l send-keys "C-l"

After these, if C-l does not work like I said in the beginning. Then use this:

in conf.fish

function fish_user_key_bindings
    bind \cl 'tput reset; clear; commandline -f repaint'
end 

Now C-l should work as expected.

c02y commented Feb 12, 2017

Guys, sorry about this, I've solved this long time ago.

Here is my solution:
in config.fish

function fish_user_key_bindings
    bind \cl 'clear; commandline -f repaint'
end

in tmux.conf

bind -n C-l send-keys "C-l"

After these, if C-l does not work like I said in the beginning. Then use this:

in conf.fish

function fish_user_key_bindings
    bind \cl 'tput reset; clear; commandline -f repaint'
end 

Now C-l should work as expected.

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Feb 12, 2017

Contributor

@peterstory: Thanks for that info as it confirms what we suspected.

@faho: Apparently ncurses 5.9 modified clear but not tput clear to include the \e[3J sequence. It's a shame that ncurses 6.0 has them both sending the unwanted sequence. I'm not confident we can depend on the infocmp output not including the unwanted sequence. I think it would be better to capture the output of clear and just remove that sequence if present before echoing it. This seems to work fine:

set c (clear | string replace \e\[3J '')
echo -n $c
Contributor

krader1961 commented Feb 12, 2017

@peterstory: Thanks for that info as it confirms what we suspected.

@faho: Apparently ncurses 5.9 modified clear but not tput clear to include the \e[3J sequence. It's a shame that ncurses 6.0 has them both sending the unwanted sequence. I'm not confident we can depend on the infocmp output not including the unwanted sequence. I think it would be better to capture the output of clear and just remove that sequence if present before echoing it. This seems to work fine:

set c (clear | string replace \e\[3J '')
echo -n $c

@faho faho closed this in afdd1a9 Feb 12, 2017

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Feb 12, 2017

Member

afdd1a9 should fix this for everyone, by default. Sorry for taking this long!

Member

faho commented Feb 12, 2017

afdd1a9 should fix this for everyone, by default. Sorry for taking this long!

@faho faho added bug and removed needs more info question labels Feb 12, 2017

@faho faho added this to the 2.6.0 milestone Feb 12, 2017

develop7 added a commit to develop7/fish-shell that referenced this issue Apr 17, 2017

Don't clear scrollback with the \cl binding
ncurses since 6.0 sends the "E3" sequence along with "clear", even for
just `clear` or `tput clear`. This deletes the scrollback buffer which
is usually not what you want.

Fixes fish-shell#2855.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment