summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVT/Terminal.cpp
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/Libraries/LibVT/Terminal.cpp
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/Libraries/LibVT/Terminal.cpp')
-rw-r--r--Userland/Libraries/LibVT/Terminal.cpp20
1 files changed, 15 insertions, 5 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;
}