use abreviated form for keys in client.cc

This commit is contained in:
Maxime Coste 2013-11-10 22:48:56 +00:00
parent cd867135a0
commit 03a6561f50

View File

@ -106,14 +106,12 @@ class LineEditor
public: public:
void handle_key(Key key) void handle_key(Key key)
{ {
if (key == Key::Left or if (key == Key::Left or key == ctrl('b'))
key == Key{Key::Modifiers::Control, 'b'})
{ {
if (m_cursor_pos > 0) if (m_cursor_pos > 0)
--m_cursor_pos; --m_cursor_pos;
} }
else if (key == Key::Right or else if (key == Key::Right or key == ctrl('f'))
key == Key{Key::Modifiers::Control, 'f'})
{ {
if (m_cursor_pos < m_line.char_length()) if (m_cursor_pos < m_line.char_length())
++m_cursor_pos; ++m_cursor_pos;
@ -198,7 +196,7 @@ public:
return boost::regex_match(str.begin(), str.end(), m_filter); return boost::regex_match(str.begin(), str.end(), m_filter);
}; };
if (key == Key(Key::Modifiers::Control, 'm')) if (key == ctrl('m'))
{ {
context().ui().menu_hide(); context().ui().menu_hide();
context().print_status(DisplayLine{}); context().print_status(DisplayLine{});
@ -224,20 +222,16 @@ public:
m_callback(selected, MenuEvent::Abort, context()); m_callback(selected, MenuEvent::Abort, context());
} }
} }
else if (key == Key::Down or else if (key == Key::Down or key == ctrl('i') or
key == Key(Key::Modifiers::Control, 'i') or key == ctrl('n') or key == 'j')
key == Key(Key::Modifiers::Control, 'n') or
key == Key(Key::Modifiers::None, 'j'))
{ {
auto it = std::find_if(m_selected+1, m_choices.end(), match_filter); auto it = std::find_if(m_selected+1, m_choices.end(), match_filter);
if (it == m_choices.end()) if (it == m_choices.end())
it = std::find_if(m_choices.begin(), m_selected, match_filter); it = std::find_if(m_choices.begin(), m_selected, match_filter);
select(it); select(it);
} }
else if (key == Key::Up or else if (key == Key::Up or key == Key::BackTab or
key == Key::BackTab or key == ctrl('p') or key == 'k')
key == Key(Key::Modifiers::Control, 'p') or
key == Key(Key::Modifiers::None, 'k'))
{ {
ChoiceList::const_reverse_iterator selected(m_selected+1); ChoiceList::const_reverse_iterator selected(m_selected+1);
auto it = std::find_if(selected+1, m_choices.rend(), match_filter); auto it = std::find_if(selected+1, m_choices.rend(), match_filter);
@ -337,7 +331,7 @@ public:
m_line_editor.insert(reg); m_line_editor.insert(reg);
m_mode = Mode::Default; m_mode = Mode::Default;
} }
else if (key == Key{Key::Modifiers::Control, 'm'}) // enter else if (key == ctrl('m')) // enter
{ {
if (not line.empty()) if (not line.empty())
{ {
@ -354,7 +348,7 @@ public:
m_callback(line, PromptEvent::Validate, context()); m_callback(line, PromptEvent::Validate, context());
return; return;
} }
else if (key == Key::Escape or key == Key { Key::Modifiers::Control, 'c' }) else if (key == Key::Escape or key == ctrl('c'))
{ {
context().print_status(DisplayLine{}); context().print_status(DisplayLine{});
context().ui().menu_hide(); context().ui().menu_hide();
@ -362,12 +356,11 @@ public:
m_callback(line, PromptEvent::Abort, context()); m_callback(line, PromptEvent::Abort, context());
return; return;
} }
else if (key == Key{Key::Modifiers::Control, 'r'}) else if (key == ctrl('r'))
{ {
m_mode = Mode::InsertReg; m_mode = Mode::InsertReg;
} }
else if (key == Key::Up or else if (key == Key::Up or key == ctrl('p'))
key == Key{Key::Modifiers::Control, 'p'})
{ {
if (m_history_it != history.begin()) if (m_history_it != history.begin())
{ {
@ -387,8 +380,7 @@ public:
} while (it != history.begin()); } while (it != history.begin());
} }
} }
else if (key == Key::Down or // next else if (key == Key::Down or key == ctrl('n')) // next
key == Key{Key::Modifiers::Control, 'n'})
{ {
if (m_history_it != history.end()) if (m_history_it != history.end())
{ {
@ -404,8 +396,7 @@ public:
m_line_editor.reset(m_prefix); m_line_editor.reset(m_prefix);
} }
} }
else if (key == Key(Key::Modifiers::Control, 'i') or // tab completion else if (key == ctrl('i') or key == Key::BackTab) // tab completion
key == Key::BackTab)
{ {
const bool reverse = (key == Key::BackTab); const bool reverse = (key == Key::BackTab);
CandidateList& candidates = m_completions.candidates; CandidateList& candidates = m_completions.candidates;