diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-28 21:44:32 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-28 21:46:05 +0200 |
commit | 96ca8bea6cf9419be07af63bb1c865526e762599 (patch) | |
tree | 64e998b8aa527587c1bd68a57e77240828ca3f21 /Applications | |
parent | 274b41e47c9c517b199263dba20eef70fec16dba (diff) | |
download | serenity-96ca8bea6cf9419be07af63bb1c865526e762599.zip |
Terminal: Don't write erroneous characters to PTY when modifiers pressed.
Additionally the Alt modifier now generates the correct characters, as do
Insert/Delete/PgUp/PgDown.
Patch contributed by "pd"
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/Terminal/Terminal.cpp | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index 0807e56135..10a88ee0f4 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -1010,42 +1010,59 @@ void Terminal::event(CEvent& event) void Terminal::keydown_event(GKeyEvent& event) { - char ch = !event.text().is_empty() ? event.text()[0] : 0; - if (event.ctrl()) { - if (ch >= 'a' && ch <= 'z') { - ch = ch - 'a' + 1; - } else if (ch == '\\') { - ch = 0x1c; - } - } switch (event.key()) { case KeyCode::Key_Up: write(m_ptm_fd, "\033[A", 3); - break; + return; case KeyCode::Key_Down: write(m_ptm_fd, "\033[B", 3); - break; + return; case KeyCode::Key_Right: write(m_ptm_fd, "\033[C", 3); - break; + return; case KeyCode::Key_Left: write(m_ptm_fd, "\033[D", 3); - break; + return; + case KeyCode::Key_Insert: + write(m_ptm_fd, "\033[2~", 4); + return; + case KeyCode::Key_Delete: + write(m_ptm_fd, "\033[3~", 4); + return; case KeyCode::Key_Home: write(m_ptm_fd, "\033[H", 3); - break; + return; case KeyCode::Key_End: write(m_ptm_fd, "\033[F", 3); - break; - case KeyCode::Key_RightShift: - // Prevent RightShift from being sent to whatever's running in the - // terminal. Prevents `~@` (null) character from being sent after every - // character entered with right shift. - break; + return; + case KeyCode::Key_PageUp: + write(m_ptm_fd, "\033[5~", 4); + return; + case KeyCode::Key_PageDown: + write(m_ptm_fd, "\033[6~", 4); + return; default: - write(m_ptm_fd, &ch, 1); break; } + + // Key event was not one of the above special cases, + // attempt to treat it as a character... + char ch = !event.text().is_empty() ? event.text()[0] : 0; + if (ch) { + if (event.ctrl()) { + if (ch >= 'a' && ch <= 'z') { + ch = ch - 'a' + 1; + } else if (ch == '\\') { + ch = 0x1c; + } + } + + // ALT modifier sends escape prefix + if (event.alt()) + write(m_ptm_fd, "\033", 1); + + write(m_ptm_fd, &ch, 1); + } } void Terminal::paint_event(GPaintEvent& event) |