Skip to content

Commit

Permalink
LibVT+Kernel: Support clearing the scrollback buffer
Browse files Browse the repository at this point in the history
As per the `xterm ctlseqs` documentation, `\e3J` should clear the
scrollback buffer, and leave the visible lines unchanged.

This commit fixes a FIXME.
  • Loading branch information
BertalanD authored and awesomekling committed Jun 10, 2021
1 parent 221ba1a commit 8f8fd9c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Kernel/TTY/VirtualConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ConsoleImpl::clear()
{
m_client.clear();
}
void ConsoleImpl::clear_including_history()
void ConsoleImpl::clear_history()
{
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/TTY/VirtualConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ConsoleImpl final : public VT::Terminal {
private:
virtual void invalidate_cursor() override;
virtual void clear() override;
virtual void clear_including_history() override;
virtual void clear_history() override;

virtual void scroll_up(u16 region_top, u16 region_bottom, size_t count) override;
virtual void scroll_down(u16 region_top, u16 region_bottom, size_t count) override;
Expand Down
11 changes: 4 additions & 7 deletions Userland/Libraries/LibVT/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ void Terminal::clear()
{
dbgln_if(TERMINAL_DEBUG, "Clear the entire screen");
for (size_t i = 0; i < rows(); ++i)
active_buffer()[i].clear(m_current_state.attribute);
active_buffer()[i].clear(Attribute());
set_cursor(0, 0);
}

void Terminal::clear_including_history()
void Terminal::clear_history()
{
dbgln_if(TERMINAL_DEBUG, "Clear history");
m_history.clear();
m_history_start = 0;

clear();

m_client.terminal_history_changed();
}
#endif
Expand Down Expand Up @@ -626,8 +624,7 @@ void Terminal::ED(Parameters params)
clear();
break;
case 3:
// FIXME: <esc>[3J should also clear the scrollback buffer.
clear();
clear_history();
break;
default:
unimplemented_csi_sequence(params, {}, 'J');
Expand Down
10 changes: 8 additions & 2 deletions Userland/Libraries/LibVT/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ class Terminal : public EscapeSequenceExecutor {

void set_cursor(unsigned row, unsigned column, bool skip_debug = false);

void clear_including_history()
{
clear_history();
clear();
}

#ifndef KERNEL
void clear();
void clear_including_history();
void clear_history();
#else
virtual void clear() = 0;
virtual void clear_including_history() = 0;
virtual void clear_history() = 0;
#endif

#ifndef KERNEL
Expand Down

0 comments on commit 8f8fd9c

Please sign in to comment.