PerBothner / DomTerm

DOM/JavaScript-based terminal-emulator/console

Home Page:https://domterm.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: clear screen support

albertz opened this issue · comments

Many other terminal emulators have the option to clear the scroll buffer + screen (e.g. in MacOSX Terminal: Cmd+K -> clear to start). This is pretty useful. Can we have that in DomTerm as well?

Do you mean the same as the Unix screen command, but as a keyboard or menu command?

No, screen is a terminal multiplexer. I just want to reset the scroll buffer + the screen. Just exactly what Cmd+K does in the MacOSX Terminal. Basically you get the (visual) state as if you open a new terminal tab/window (in the current directory).

I mistyped. I meant the Unix clear command.

No, clear is not the same. That usually does not clear the scroll buffer.

On Linux clear does clear the scroll buffer:

`clear` clears your screen if this is possible, including its scrollback
buffer (if the extended “E3” capability is defined).

There is also an option:

  -x   do not attempt to clear the terminal's  scrollback  buffer  using
        the extended “E3” capability.

Does the BSD or Mac version not do that?

Hm, I just tried Gnome Terminal on Ubuntu Linux, and there, clear does not clear the scroll back (I mean, I still can scroll up and see the previous output).

On Fedora 29, clear does clear the scrollback buffer. I'm pretty sure it has been that way for a long time and I'm very surprised if Ubuntu is different. What does man clear say?

This is one official man page.
This is the one I see on Ubuntu.

This is clear in the Gnome Terminal on Ubuntu Linux:
cast-gnome-terminal-clear mov

This is clear in the Terminal on MacOSX (exactly as in Ubuntu):
cast-osx-terminal-clear mov

This is Menu: Edit / Clear to Start (Cmd+K) in the Terminal on MacOSX, and what I would like to have (it really clears the scrollbuf, I cannot scroll up anymore):
cast-osx-terminal-clear-scrollbuf mov

"This [linux.die.net] is one official man page."

There is nothing official about it and the site looks pretty old. This is more up-to-date and official (the site appears to be that of the maintainer of the man-pages project).

I'm wondering if this is a termcap/terminfo problem: Either TERM is set wrong (Gnome Terminal, Konsole and domterm all set it to xterm-256color), or the appropriate termcap/terminfo does not set the appropriate capability.

Regardless, I'm OK adding this feature as a menu command. "Edit"-> "Clear to Start" seems fine.

The keyboard shortcut is a little trickier because we want to use a different sequence on non-Macs. Maybe Ctrl-Shift-K. It would be cleaner after we change to use keymaps more extensively - which is planned.

I realized that clearing the scroll buffer and the screen is problematical, since if you're at any kind of prompt it's going to delete the prompt and mess up the input line. The name "clear to start" suggests it might only clear the scrolled-out area, or maybe it clears to the start of the line containing the cursor. I read "There is also ⌥+⌘+K, which just clears the scroll-back."

Could you confirm/clarify the exact behavior? Clear to start of current line may be the behavior we want.

clear now behaves exactly like what I wanted to have (after your fix in #64), and exactly in the same way as Clear to Start (⌘K) in MacOSX. I.e.:

  • It clears the whole scrollbuf (you cannot scroll up anymore).
  • It clears the whole current visible screen, except the last line (of the prompt), which then appears in the beginning of the screen, as the only visible line, and nothing else.

As you said, there is also Clear Scrollback (⌥⌘K), which does:

  • It clears the whole scrollbuf.
  • It leaves the current visible screen just as-is.
    However, this is often (always) not what I want. I really want that Clear to Start functionality.

Then, there is also Clear Screen (^⌘L), which does:

  • It leaves the scrollbuf as-is.
  • Scrolls down such that the last line is the first visible line on the screen.
    This is somewhat similar to the behavior of clear (in the MacOSX Terminal, or Gnome Terminal), but also not exactly the same.
    And this is also often (always) not what I want, because I often scroll up & down, and I often clear it on the purpose that I don't see that anymore.

Responding to #64 (comment), to consolidate relevant information here:
"On Linux/elsewhere, I would maybe chose the same [keyboard shortcut] as what you have in Gnome Terminal."

I can't find any keyboard shortcut or menu entry for "clear screen" on Gnome Terminal. Xterm has a "Reset and Clear Saved Lines" menu option. Konsole has View->"Clear Scrollback" (which seems useful, as you can adjust how much to clear) (no shortcut), and "Clear Scrollback and Reset" (Ctrl-Shift-K).

"clear now behaves exactly like what I wanted to have (after your fix in #64), and exactly in the same way as Clear to Start (⌘K) in MacOSX"

Presumably not exactly the same: The clear command clears the entire screen, including the last line. Then the shell prints another prompt..

Can you take another look at Clear to Start? What happens if you have scrolled output, then start an "alternative buffer" program like emacs -nw, navigate the cursor to the middle of the screen, and then do Clear to Start? What happens when you return from Emacs - how much of the old "main" screen is left?

What I think would make sense for DomTerm is for all lines before the cursor (including the scrollbuffer) to be deleted, with the current line and cursor now at the top of the screen. If using the alternate buffer, everything from the main buffer would also be deleted. If the current line is wrapped from the previous line, then "start of line" should probably be the start of the "logical line" .

I don't quite understand what you are asking. The behavior of Clear to Start is always the same. It clears everything (scrollbuf + visible screen), except the current line.
Another cast. This time with scrollbar always visible (this is a OSX system setting), to make it clear when the scrollbuf is empty. Ignore the Emacs part of the recording; later I did with Vim what you where asking.
cast-clear-to-start mov

I implemented a clear-buffer command. This deletes all lines in the buffer, except the current line, which at this point means the current logical lines (after line-warps removed). This is for consistency if there are multiple windows showing the same session. (For the same reason, the command to the buffer has to be sent to to the server so it can send it to all the windows.)

It's a bit rough (there is a problem when in line-editing) mode, which is why I haven't enabled it by default. However, I made it possible to change the "master" keybindings, so you can try it out by setting it in ~/.domterm/settings.ini:

keymap.master =
 | "Ctrl-Shift-K": clear-buffer

I'd also like to add a clear-scrolled-output command but not yet.

I've implemented a Edit->Clear Buffer menu entry. It seems to work on Electron, Qt, and Firefox.

I thinks is ok at this point.