From 9235238191dd292e9a875ad6013f466dc4dad152 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 Sep 2019 22:36:35 +1000 Subject: [PATCH] Fix input coming in packets characters being dropped --- src/ncurses_ui.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 0add3a6b..a68286c4 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -644,14 +644,15 @@ Optional NCursesUI::get_next_key() if (c == 127) return {Key::Backspace}; - struct getch_iterator + struct Sentinel{}; + struct CharIterator { - unsigned char operator*() { return *c; } - getch_iterator& operator++() { c = get_char(); return *this; } - bool operator==(const getch_iterator&) const { return not c; } + unsigned char operator*() { if (not c) c = get_char().value_or((unsigned char)0); return *c; } + CharIterator& operator++() { c.reset(); return *this; } + bool operator==(const Sentinel&) const { return false; } Optional c; }; - return Key{utf8::codepoint(getch_iterator{c}, getch_iterator{})}; + return Key{utf8::codepoint(CharIterator{c}, Sentinel{})}; }; auto parse_csi = [this]() -> Optional {