From 8605711f4bb5404d0368343f14896f716963d864 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 10 Nov 2018 00:56:10 +0100 Subject: [PATCH] Make /bin/clear work again. After I made stdio buffered, we were dropping anything unflushed on exit. Since /bin/clear just prints out some escape sequences without a newline, the entire buffer was being discarded. Also add VirtualConsole::clear() that handles clearing of background VC's. --- Kernel/VirtualConsole.cpp | 14 ++++++++++++-- Kernel/VirtualConsole.h | 2 ++ LibC/entry.cpp | 3 +++ Userland/clear.cpp | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Kernel/VirtualConsole.cpp b/Kernel/VirtualConsole.cpp index 2199cc509a..530913f47a 100644 --- a/Kernel/VirtualConsole.cpp +++ b/Kernel/VirtualConsole.cpp @@ -39,6 +39,16 @@ VirtualConsole::~VirtualConsole() { } +void VirtualConsole::clear() +{ + word* linemem = m_active ? (word*)s_vga_buffer : (word*)m_buffer; + for (word i = 0; i < 80 * 25; ++i) + linemem[i] = 0x0720; + if (m_active) + set_vga_start_row(0); + set_cursor(0, 0); +} + void VirtualConsole::switch_to(unsigned index) { if ((int)index == s_active_console) @@ -248,11 +258,11 @@ void VirtualConsole::escape$J(const Vector& params) notImplemented(); break; case 2: - vga_clear(); + clear(); break; case 3: // FIXME: [3J should also clear the scrollback buffer. - vga_clear(); + clear(); break; } } diff --git a/Kernel/VirtualConsole.h b/Kernel/VirtualConsole.h index 1af03699b5..545a8a4894 100644 --- a/Kernel/VirtualConsole.h +++ b/Kernel/VirtualConsole.h @@ -43,6 +43,8 @@ private: void escape$s(const Vector&); void escape$u(const Vector&); + void clear(); + const byte m_rows { 25 }; const byte m_columns { 80 }; byte m_cursor_row { 0 }; diff --git a/LibC/entry.cpp b/LibC/entry.cpp index d24be1ff07..2753137e2c 100644 --- a/LibC/entry.cpp +++ b/LibC/entry.cpp @@ -41,6 +41,9 @@ extern "C" int _start() goto epilogue; status = main(argc, argv); + fflush(stdout); + fflush(stderr); + epilogue: Syscall::invoke(Syscall::SC_exit, status); diff --git a/Userland/clear.cpp b/Userland/clear.cpp index c7568b384e..e31f99328b 100644 --- a/Userland/clear.cpp +++ b/Userland/clear.cpp @@ -1,8 +1,9 @@ -#include +#include int main(int, char**) { printf("\033[3J\033[H\033[2J"); + fflush(stdout); return 0; }