diff options
author | Hüseyin ASLITÜRK <asliturk@hotmail.com> | 2020-06-13 13:56:39 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-16 13:15:17 +0200 |
commit | 7abca30f4147064b6364dd2ebb76a778262c7138 (patch) | |
tree | 615e9153c34e3dcb964391dfb9fe76595a7a475b | |
parent | 53227f400cfff6d9d295903eaf6de8d51bce6868 (diff) | |
download | serenity-7abca30f4147064b6364dd2ebb76a778262c7138.zip |
LibVT: Replace u8 type to u32 for code point
Replace KeyEvent text attribute usage with code_point.
-rw-r--r-- | Libraries/LibVT/Terminal.cpp | 17 | ||||
-rw-r--r-- | Libraries/LibVT/Terminal.h | 4 | ||||
-rw-r--r-- | Libraries/LibVT/TerminalWidget.cpp | 10 |
3 files changed, 13 insertions, 18 deletions
diff --git a/Libraries/LibVT/Terminal.cpp b/Libraries/LibVT/Terminal.cpp index 0823730c81..2ae12fcb76 100644 --- a/Libraries/LibVT/Terminal.cpp +++ b/Libraries/LibVT/Terminal.cpp @@ -1004,7 +1004,7 @@ void Terminal::emit_string(const StringView& string) m_client.emit((const u8*)string.characters_without_null_termination(), string.length()); } -void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags) +void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags) { bool ctrl = flags & Mod_Ctrl; bool alt = flags & Mod_Alt; @@ -1045,7 +1045,7 @@ void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags) break; } - if (!character) { + if (!code_point) { // Probably a modifier being pressed. return; } @@ -1058,10 +1058,10 @@ void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags) // Key event was not one of the above special cases, // attempt to treat it as a character... if (ctrl) { - if (character >= 'a' && character <= 'z') { - character = character - 'a' + 1; - } else if (character == '\\') { - character = 0x1c; + if (code_point >= 'a' && code_point <= 'z') { + code_point = code_point - 'a' + 1; + } else if (code_point == '\\') { + code_point = 0x1c; } } @@ -1069,7 +1069,10 @@ void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags) if (alt) emit_string("\033"); - emit_string({ &character, 1 }); + StringBuilder sb; + sb.append_codepoint(code_point); + + emit_string(sb.to_string()); } void Terminal::unimplemented_escape() diff --git a/Libraries/LibVT/Terminal.h b/Libraries/LibVT/Terminal.h index 1ce3b81d4f..a141dbade2 100644 --- a/Libraries/LibVT/Terminal.h +++ b/Libraries/LibVT/Terminal.h @@ -38,7 +38,7 @@ namespace VT { class TerminalClient { public: - virtual ~TerminalClient() { } + virtual ~TerminalClient() {} virtual void beep() = 0; virtual void set_window_title(const StringView&) = 0; @@ -97,7 +97,7 @@ public: const NonnullOwnPtrVector<Line>& history() const { return m_history; } void inject_string(const StringView&); - void handle_key_press(KeyCode, u8 charatcter, u8 flags); + void handle_key_press(KeyCode, u32, u8 flags); Attribute attribute_at(const Position&) const; diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp index cf56948ae7..4022cb7fce 100644 --- a/Libraries/LibVT/TerminalWidget.cpp +++ b/Libraries/LibVT/TerminalWidget.cpp @@ -231,15 +231,7 @@ void TerminalWidget::keydown_event(GUI::KeyEvent& event) update(); } - if (event.text().length() > 2) { - // Unicode (likely emoji), just emit it. - write(m_ptm_fd, event.text().characters(), event.text().length()); - } else { - // Ask the terminal to generate the correct character sequence and send - // it back to us via emit(). - u8 character = event.text().length() == 1 ? event.text()[0] : 0; - m_terminal.handle_key_press(event.key(), character, event.modifiers()); - } + m_terminal.handle_key_press(event.key(), event.code_point(), event.modifiers()); if (event.key() != Key_Control && event.key() != Key_Alt && event.key() != Key_Shift && event.key() != Key_Logo) m_scrollbar->set_value(m_scrollbar->max()); |