avoid utf8 errors with invalid keys, like ncurse KEY_RESIZE

This commit is contained in:
Maxime Coste 2012-10-18 19:56:57 +02:00
parent 132c31042e
commit abf514f305
3 changed files with 13 additions and 3 deletions

View File

@ -627,7 +627,9 @@ void InputHandler::on_next_key(KeyCallback callback)
void InputHandler::handle_next_input(Context& context)
{
m_mode->on_key(context.ui().get_key(), context);
Key key = context.ui().get_key();
if (key != Key::Invalid)
m_mode->on_key(key, context);
context.draw_ifn();
}

View File

@ -29,6 +29,7 @@ struct Key
PageUp,
PageDown,
BackTab,
Invalid,
};
Modifiers modifiers;
@ -42,6 +43,9 @@ struct Key
constexpr bool operator==(const Key& other) const
{ return modifiers == other.modifiers and key == other.key; }
constexpr bool operator!=(const Key& other) const
{ return modifiers != other.modifiers or key != other.key; }
};
typedef std::vector<Key> KeyList;

View File

@ -216,8 +216,12 @@ Key NCursesUI::get_key()
case KEY_BTAB: return Key::BackTab;
}
ungetch(c);
return utf8::codepoint(getch_iterator{});
if (c < 256)
{
ungetch(c);
return utf8::codepoint(getch_iterator{});
}
return Key::Invalid;
}
void NCursesUI::print_status(const String& status, CharCount cursor_pos)