mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
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"
This commit is contained in:
parent
274b41e47c
commit
96ca8bea6c
1 changed files with 37 additions and 20 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue