8000 Add a clear-screen bind function to clear the screen by faho · Pull Request #10044 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content

Add a clear-screen bind function to clear the screen#10044

Merged
faho merged 4 commits intofish-shell:masterfrom
faho:clear-hack
Oct 8, 2023
Merged

Add a clear-screen bind function to clear the screen#10044
faho merged 4 commits intofish-shell:masterfrom
faho:clear-hack

Conversation

@faho
Copy link
Member
@faho faho commented Oct 3, 2023

Description

This adds a bind function called clear-screen and binds it to ctrl+l by default, removing the rather awkward invocation of the clear command.

What that does is:

  1. Print the "clear_screen" escape sequence, if possible
  2. Redraw with the old prompt
  3. Reexecute the prompt
  4. Repaint again

This makes for a smooth experience removing any flicker, and still leaves an up-to-date prompt (eventually, once it comes through).

I've tested this with TERM=dumb (it'll do nothing) and with an awkwardly slow prompt - it will show the old prompt, won't react to input and then update the prompt and the commandline.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

faho added 2 commits October 3, 2023 20:51
This can be bound like `bind \cl clear-screen`.

In contrast to the current way it doesn't need the external `clear`
command that was always awkward.

Also it will clear the screen and first draw the old prompt to remove
flicker.
Then it will immediately trigger a repaint, so the prompt will be overwritten.
@faho faho added this to the fish 3.7.0 milestone Oct 3, 2023
@faho
Copy link
Member Author
faho commented Oct 3, 2023

I'm reasonably sure the test failure is down to $TERM/terminfo being wrong on these machines, and so it doesn't do anything.

I'm not sure why command clear would work in that case, I'll have to check.

@faho
Copy link
Member Author
faho commented Oct 4, 2023

Ah, this was a crash - clear_screen was NULL.

This should really be shown in pexpect, also the test that failed doesn't really check clearing because the pexpect tests are run with TERM=dumb.

faho added a commit that referenced this pull request Oct 4, 2023
This would have been helpful in #10044:

> signals.py:28: SIGNAL SIGSEGV from expect_prompt()

instead of "EOF".
@ridiculousfish
Copy link
Member

Seems fine to me - though I use the terminal's clear function which also clears scrollback.

@faho
Copy link
Member Author
faho commented Oct 8, 2023

Seems fine to me - though I use the terminal's clear function which also clears scrollback.

That is of course a valid choice.

We already removed scrollback clear from clear's output because it makes clearing destructive, which seems like a surprising and therefore bad default. So there's no change related to that here.

It would be possible to add a "repaint-old" function that repaints without reexecuting. This would allow you to add a fast repaint after your clear by doing bind \cl 'clear; commandline -f repaint-old repaint'. It does of course make it possible to accidentally carry around a stale prompt. Or a function that does "repaint-old repaint", by first redrawing the cached information and then reexecuting - this would of course send a bit more in case both need to be done and is typically unnecessary.

So I chose this version because skipping the awkward clear | string replace was on my agenda anyway and this is simple and impossible to misuse.

@faho faho merged commit c4ca1a6 into fish-shell:master Oct 8, 2023
@faho faho deleted the clear-hack branch October 8, 2023 09:41
faho added a commit that referenced this pull request Oct 8, 2023
This can be bound like `bind \cl clear-screen`, and is, by default

In contrast to the current way it doesn't need the external `clear`
command that was always awkward.

Also it will clear the screen and first draw the old prompt to remove
flicker.
Then it will immediately trigger a repaint, so the prompt will be overwritten.

(cherry picked from commit c4ca1a6)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0