diff --git a/README.md b/README.md index a0c1921..8c2cb71 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Uses macro magic (not intentionally, but it's needed to reduce code size and ove - raw mode - alternate screen - performant screen size query -- custom function for resize handling, NOTE: you should probably lock `stdout`, stdin when you use this feature, also, **doesn't work on Windows** +- custom function for resize handling, **_NOTE_**: you should probably lock `stdout`, stdin when you use this feature, also, **doesn't work on Windows** ### input @@ -34,9 +34,11 @@ a pretty handy header with functions and types to improve reading input from `st - basic symbols, such as `['~', ';', '*', ...]`, but not `['$', '€', ...]` - Ctrl`+alphabetical characters` - arrows +- touchpad/mouse scroll - Backspace, (Shift)Tab, Enter/Return, Delete, Page[Up,Down], Home,End, Insert, - F[1,2,3,4] **_NOTE_**: the other F-keys are damn hard to implement, might be done in the future though -- basic characters, be it upper or lowercase, special ones like: `['ö', 'ä', 'á', ...]` are safely ignored +- basic characters, be it upper or lowercase +- **_NOTE_**: special ones like: `['ö', 'ä', 'á', ...]` are safely ignored ### coordinates @@ -94,7 +96,7 @@ int main() { ## non-goals -- mouse support +- full mouse support - huge number of widgets - high level functions - thousands of more features: just what's necessary diff --git a/input.hpp b/input.hpp index 7251876..d519e60 100644 --- a/input.hpp +++ b/input.hpp @@ -13,14 +13,6 @@ #include // For read(), usleep() on Unix-like systems #endif -// Function to set stdin non-blocking on Unix-like systems -#ifndef _WIN32 -inline void set_non_blocking(bool enable) { - int flags = fcntl(STDIN_FILENO, F_GETFL, 0); - fcntl(STDIN_FILENO, F_SETFL, enable ? flags | O_NONBLOCK : flags & ~O_NONBLOCK); -} -#endif - // sorry for this ugly code, I really feel very bad about it. // damn macros, because given `MyEnum::Core` you can't do // `cout << MyEnum::Core; assert(cout.string() == "Core"|"MyEnum::Core")` @@ -199,11 +191,9 @@ struct Input { break; case SpecKey::Esc: { #ifndef _WIN32 - set_non_blocking(false); // Temporarily make stdin non-blocking char next_byte = get_char(); - switch (next_byte) { - case 91: { + if (next_byte == 79 || next_byte == 91) { char special = get_char(); switch (special) { case Arrow::Up: @@ -212,6 +202,10 @@ struct Input { case Arrow::Left: input = Input(static_cast(special)); break; + case SpecKey::F1: + case SpecKey::F2: + case SpecKey::F3: + case SpecKey::F4: case SpecKey::End: case SpecKey::Home: case SpecKey::ShiftTab: @@ -225,33 +219,13 @@ struct Input { input = Input(static_cast(special)); break; default: - // ignore_byte = _getch(3); - break; - } - break; - } - case 79: { - // get function key character - char f_key = get_char(); - switch (f_key) { - case SpecKey::F1: - case SpecKey::F2: - case SpecKey::F3: - case SpecKey::F4: - input = Input(static_cast(f_key)); - break; - default: + // ignore_byte = get_char(); break; } break; } - default: - input = Input(SpecKey::Esc); - } - set_non_blocking(false); // Temporarily make stdin non-blocking -#else - input = Input(SpecKey::Esc); #endif + input = Input(SpecKey::Esc); } default: break; @@ -266,21 +240,17 @@ struct Input { char tmp = _getch(); return tmp; } - static Input read() { - // read raw input - return Input::read_helper(Input::read_ch); - } #else // not windows static char read_ch() { char tmp = 0; ::read(STDIN_FILENO, &tmp, 1); return tmp; } +#endif static Input read() { // read raw input return Input::read_helper(Input::read_ch); } -#endif }; inline std::ostream& operator<<(std::ostream& os, const Input& inp) {