summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-05-17 16:25:35 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-17 18:19:49 +0200
commit5d80debc1f891cacb155aa7eaaad51a9a3325ec9 (patch)
treea57c6b63fac9ae058f961941a336b7e97b11c881 /Userland
parentf25209113fcd15df5778938c4accf13c5139d278 (diff)
downloadserenity-5d80debc1f891cacb155aa7eaaad51a9a3325ec9.zip
LibVT: Fix newline handling
Before this commit, we would jump to the first column after receiving the '\n' line feed character. This is not the correct behavior, as it should only move the cursor now. Translating the typed Return key into the correct CR LF ("\r\n") is the TTY's job, which was fixed in #7184. Fixes #6820 Fixes #6960
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibVT/Terminal.cpp20
-rw-r--r--Userland/Libraries/LibVT/Terminal.h4
2 files changed, 17 insertions, 7 deletions
diff --git a/Userland/Libraries/LibVT/Terminal.cpp b/Userland/Libraries/LibVT/Terminal.cpp
index 42ee743396..90cdc569f5 100644
--- a/Userland/Libraries/LibVT/Terminal.cpp
+++ b/Userland/Libraries/LibVT/Terminal.cpp
@@ -521,7 +521,7 @@ void Terminal::DCH(Parameters params)
}
#endif
-void Terminal::newline()
+void Terminal::linefeed()
{
u16 new_row = m_cursor_row;
if (m_cursor_row == m_scroll_region_bottom) {
@@ -529,8 +529,11 @@ void Terminal::newline()
} else {
++new_row;
};
- set_cursor(new_row, 0);
+ // We shouldn't jump to the first column after receiving a line feed.
+ // The TTY will take care of generating the carriage return.
+ set_cursor(new_row, m_cursor_column);
}
+
void Terminal::carriage_return()
{
set_cursor(m_cursor_row, 0);
@@ -591,7 +594,7 @@ void Terminal::set_cursor(unsigned a_row, unsigned a_column)
void Terminal::NEL()
{
- newline();
+ linefeed();
carriage_return();
}
@@ -658,7 +661,7 @@ void Terminal::emit_code_point(u32 code_point)
if (m_stomp) {
m_stomp = false;
carriage_return();
- newline();
+ linefeed();
put_character_at(m_cursor_row, m_cursor_column, code_point);
set_cursor(m_cursor_row, 1);
} else {
@@ -690,7 +693,9 @@ void Terminal::execute_control_code(u8 code)
return;
}
case '\n':
- newline();
+ case '\v':
+ case '\f':
+ linefeed();
return;
case '\r':
carriage_return();
@@ -961,6 +966,11 @@ void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
case KeyCode::Key_PageDown:
emit_tilde_with_modifier(6);
return;
+ case KeyCode::Key_Return:
+ // The standard says that CR should be generated by the return key.
+ // The TTY will take care of translating it to CR LF for the terminal.
+ emit_string("\r");
+ return;
default:
break;
}
diff --git a/Userland/Libraries/LibVT/Terminal.h b/Userland/Libraries/LibVT/Terminal.h
index 853319353b..f5d8560013 100644
--- a/Userland/Libraries/LibVT/Terminal.h
+++ b/Userland/Libraries/LibVT/Terminal.h
@@ -161,13 +161,13 @@ protected:
#ifndef KERNEL
void scroll_up();
void scroll_down();
- void newline();
+ void linefeed();
void put_character_at(unsigned row, unsigned column, u32 ch);
void set_window_title(const String&);
#else
virtual void scroll_up() = 0;
virtual void scroll_down() = 0;
- virtual void newline() = 0;
+ virtual void linefeed() = 0;
virtual void put_character_at(unsigned row, unsigned column, u32 ch) = 0;
virtual void set_window_title(const String&) = 0;
#endif