From c0db3b81bebc270a48a7e85b8eedb3973f611674 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 9 Oct 2012 14:30:35 +0200 Subject: [PATCH] NCursesUI::get_key returns the codepoint --- src/ncurses.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ncurses.cc b/src/ncurses.cc index 9a916086..6dd3359c 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -180,10 +180,16 @@ void NCursesUI::draw_window(Window& window) redraw(m_menu_win); } +struct getch_iterator +{ + int operator*() { return getch(); } + getch_iterator& operator++() { return *this; } + getch_iterator& operator++(int) { return *this; } +}; + Key NCursesUI::get_key() { - const utf8::Codepoint c = getch(); - + const unsigned c = getch(); if (c > 0 and c < 27) { return {Key::Modifiers::Control, c - 1 + 'a'}; @@ -209,7 +215,9 @@ Key NCursesUI::get_key() case KEY_NPAGE: return Key::PageDown; case KEY_BTAB: return Key::BackTab; } - return c; + + ungetch(c); + return utf8::codepoint(getch_iterator{}); } void NCursesUI::print_status(const String& status, CharCount cursor_pos)