Add support for Home/End key in prompts

This commit is contained in:
Maxime Coste 2013-02-19 13:50:27 +01:00
parent b08749285e
commit a453ddaf37
4 changed files with 17 additions and 3 deletions

View File

@ -95,6 +95,10 @@ public:
if (m_cursor_pos < m_line.char_length()) if (m_cursor_pos < m_line.char_length())
++m_cursor_pos; ++m_cursor_pos;
} }
else if (key == Key::Home)
m_cursor_pos = 0;
else if (key == Key::End)
m_cursor_pos = m_line.char_length();
else if (key == Key::Backspace) else if (key == Key::Backspace)
{ {
if (m_cursor_pos != 0) if (m_cursor_pos != 0)

View File

@ -19,12 +19,18 @@ using KeyAndName = std::pair<String, Codepoint>;
static std::vector<KeyAndName> keynamemap = { static std::vector<KeyAndName> keynamemap = {
{ "ret", '\r' }, { "ret", '\r' },
{ "space", ' ' }, { "space", ' ' },
{ "tab", '\t' },
{ "backspace", Key::Backspace},
{ "esc", Key::Escape }, { "esc", Key::Escape },
{ "left", Key::Left },
{ "right", Key::Right },
{ "up", Key::Up }, { "up", Key::Up },
{ "down", Key::Down}, { "down", Key::Down},
{ "backspace", Key::Backspace} { "left", Key::Left },
{ "right", Key::Right },
{ "pageup", Key::PageUp },
{ "pagedown", Key::PageDown },
{ "home", Key::Home },
{ "end", Key::End },
{ "backtab", Key::BackTab },
}; };
KeyList parse_keys(const String& str) KeyList parse_keys(const String& str)

View File

@ -28,6 +28,8 @@ struct Key
Right, Right,
PageUp, PageUp,
PageDown, PageDown,
Home,
End,
BackTab, BackTab,
Invalid, Invalid,
}; };

View File

@ -273,6 +273,8 @@ Key NCursesUI::get_key()
case KEY_RIGHT: return Key::Right; case KEY_RIGHT: return Key::Right;
case KEY_PPAGE: return Key::PageUp; case KEY_PPAGE: return Key::PageUp;
case KEY_NPAGE: return Key::PageDown; case KEY_NPAGE: return Key::PageDown;
case KEY_HOME: return Key::Home;
case KEY_END: return Key::End;
case KEY_BTAB: return Key::BackTab; case KEY_BTAB: return Key::BackTab;
} }