From faaa0dbf1d915c532bc80aa09af9d74450837baa Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 23 Jan 2019 19:58:45 +0100 Subject: [PATCH] Terminal: Various improvements to terminal emulation. --- Terminal/Terminal.cpp | 23 +++++++++++++++++------ Terminal/Terminal.h | 1 + Terminal/main.cpp | 16 ++-------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Terminal/Terminal.cpp b/Terminal/Terminal.cpp index 99cce00a33e..9e829f0ef67 100644 --- a/Terminal/Terminal.cpp +++ b/Terminal/Terminal.cpp @@ -376,6 +376,8 @@ void Terminal::set_cursor(unsigned row, unsigned column) invalidate_cursor(); m_cursor_row = row; m_cursor_column = column; + if (column != columns() - 1) + m_stomp = false; invalidate_cursor(); } @@ -438,7 +440,7 @@ void Terminal::on_char(byte ch) put_character_at(m_cursor_row, m_cursor_column, ' '); return; } - break; + return; case '\a': // FIXME: Bell! return; @@ -459,13 +461,22 @@ void Terminal::on_char(byte ch) return; } - put_character_at(m_cursor_row, m_cursor_column, ch); - auto new_column = m_cursor_column + 1; - if (new_column < columns()) + if (new_column < columns()) { + put_character_at(m_cursor_row, m_cursor_column, ch); set_cursor(m_cursor_row, new_column); - else - scroll_up(); + } else { + if (m_stomp) { + m_stomp = false; + scroll_up(); + put_character_at(m_cursor_row, m_cursor_column, ch); + set_cursor(m_cursor_row, 1); + } else { + // Curious: We wait once on the right-hand side + m_stomp = true; + put_character_at(m_cursor_row, m_cursor_column, ch); + } + } } void Terminal::set_size(word columns, word rows) diff --git a/Terminal/Terminal.h b/Terminal/Terminal.h index a7be780f040..f3165a9a1e2 100644 --- a/Terminal/Terminal.h +++ b/Terminal/Terminal.h @@ -72,6 +72,7 @@ private: byte m_cursor_column { 0 }; byte m_saved_cursor_row { 0 }; byte m_saved_cursor_column { 0 }; + bool m_stomp { false }; Attribute m_current_attribute; diff --git a/Terminal/main.cpp b/Terminal/main.cpp index 2f8f94e2124..977ce17b4c7 100644 --- a/Terminal/main.cpp +++ b/Terminal/main.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include "Terminal.h" static void make_shell(int ptm_fd) @@ -43,7 +43,7 @@ static void make_shell(int ptm_fd) perror("ioctl(TIOCSCTTY)"); exit(1); } - rc = execve("/bin/sh", nullptr, nullptr); + rc = execvp("/bin/sh", nullptr); if (rc < 0) { perror("execve"); exit(1); @@ -111,18 +111,6 @@ int main(int, char**) } assert(nread != 0); assert(nread == sizeof(event)); - dbgprintf("(Terminal:%d) ", getpid()); - switch (event.type) { - case GUI_Event::Type::Paint: dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); break; - case GUI_Event::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break; - case GUI_Event::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break; - case GUI_Event::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break; - case GUI_Event::Type::KeyDown: dbgprintf("WID=%x KeyDown 0x%b (%c)\n", event.window_id, event.key.character, event.key.character); break; - case GUI_Event::Type::WindowActivated: dbgprintf("WID=%x WindowActivated\n", event.window_id); break; - case GUI_Event::Type::WindowDeactivated: dbgprintf("WID=%x WindowDeactivated\n", event.window_id); break; - default: - ASSERT_NOT_REACHED(); - } if (event.type == GUI_Event::Type::Paint) { terminal.paint();