From ef56070a805c2fb38ce94aa4dba0cce0a5814e41 Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 21:55:35 +0200 Subject: [PATCH 01/13] utf8 --- cpp-terminal/event.cpp | 22 ++++++++-- cpp-terminal/input.cpp | 13 ------ cpp-terminal/input.hpp | 2 - cpp-terminal/key.cpp | 13 ++++++ cpp-terminal/key.hpp | 5 ++- cpp-terminal/platforms/input.cpp | 45 ++++++++++----------- examples/CMakeLists.txt | 6 +-- examples/events.cpp | 69 ++++++++++++++++++++++++++++++++ examples/read_stdin.cpp | 11 ----- 9 files changed, 129 insertions(+), 57 deletions(-) create mode 100644 examples/events.cpp delete mode 100644 examples/read_stdin.cpp diff --git a/cpp-terminal/event.cpp b/cpp-terminal/event.cpp index ece18697..c88cbcff 100644 --- a/cpp-terminal/event.cpp +++ b/cpp-terminal/event.cpp @@ -1,4 +1,6 @@ #include "cpp-terminal/event.hpp" +#include +#include "cpp-terminal/platforms/conversion.hpp" bool Term::Event::empty() { @@ -27,7 +29,7 @@ Term::Event::Event(const Term::Key& key) : m_Type(Type::Key), m_Key(key) {} Term::Event::Type Term::Event::type() { return m_Type; } -Term::Event::Event(const std::string& str) : m_Type(Type::CopyPaste), m_str(str) { parse(); } +Term::Event::Event(const std::string& str) : m_Type(Type::CopyPaste), m_str(str){ parse();} void Term::Event::parse() { @@ -191,13 +193,25 @@ void Term::Event::parse() m_Key = Key(Term::Key::Value::F20); else if(m_str == "\033[G") m_Key = Key(Term::Key::Value::NUMERIC_5); - if(!m_Key.empty()) + else if(m_str.size()==2 && ((m_str[0]&0b11100000)==0b11000000) && ((m_str[1]&0b11000000)==0b10000000)) { - m_Type = Type::Key; - m_str.clear(); + m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); + } + else if(m_str.size()==3 && ((m_str[0]&0b11110000)==0b11100000) && ((m_str[1]&0b11000000)==0b10000000) && ((m_str[2]&0b11000000)==0b10000000)) + { + m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); + } + else if(m_str.size()==4 && ((m_str[0]&0b11111000)==0b11110000) && ((m_str[1]&0b11000000)==0b10000000) && ((m_str[2]&0b11000000)==0b10000000) && ((m_str[2]&0b11000000)==0b10000000)) + { + m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); } } else { m_Type = Type::CopyPaste; } + if(!m_Key.empty()) + { + m_Type = Type::Key; + m_str.clear(); + } } Term::Event::operator Term::Key() diff --git a/cpp-terminal/input.cpp b/cpp-terminal/input.cpp index 4855a46a..2ae0892f 100644 --- a/cpp-terminal/input.cpp +++ b/cpp-terminal/input.cpp @@ -17,16 +17,3 @@ Term::Event Term::read_event() while((event = Platform::read_raw()).empty()) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } return event; } - -// returns the whole input from STDIN as string -std::string Term::read_stdin() -{ - std::string file; - char c{'\0'}; - while(true) - { - c = Platform::read_raw_stdin(); - if(c == 0x04) return file; - else { file.push_back(c); } - } -} diff --git a/cpp-terminal/input.hpp b/cpp-terminal/input.hpp index f11e8837..4f566802 100644 --- a/cpp-terminal/input.hpp +++ b/cpp-terminal/input.hpp @@ -12,8 +12,6 @@ namespace Platform // Returns true if a character is read, otherwise immediately returns false // This can't be made inline Term::Event read_raw(); - -char read_raw_stdin(); } // namespace Platform // Waits for an event (key press, screen resizing ...) diff --git a/cpp-terminal/key.cpp b/cpp-terminal/key.cpp index cbee45f3..020b7ce9 100644 --- a/cpp-terminal/key.cpp +++ b/cpp-terminal/key.cpp @@ -1,4 +1,17 @@ #include "cpp-terminal/key.hpp" +#include "cpp-terminal/platforms/conversion.hpp" + +char32_t Term::Key::codepoint() +{ + return static_cast(m_value); +} + +std::string Term::Key::str() +{ + std::string ret; + Term::Private::codepoint_to_utf8(ret,codepoint()); + return ret; +} Term::Key::Key(const Term::Key::Value& value) : m_value(value) {} diff --git a/cpp-terminal/key.hpp b/cpp-terminal/key.hpp index 500f28d1..910c1df9 100644 --- a/cpp-terminal/key.hpp +++ b/cpp-terminal/key.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace Term { @@ -223,7 +224,9 @@ class Key // Detect if Key is ALT+* bool isALT(); bool empty(); - char getChar(); + + std::string str(); + char32_t codepoint(); private: Value m_value{NO_KEY}; diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 635ebbb4..2a8acd4d 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,6 +1,8 @@ #ifdef _WIN32 #include #include + #include + #include #else #include #include @@ -25,19 +27,6 @@ static void sigwinchHandler(int sig) } #endif -char Term::Platform::read_raw_stdin() -{ - char c = getchar(); - if(c >= 0) { return c; } - else if(c == EOF) - { - // In non-raw (blocking) mode this happens when the input file - // ends. In such a case, return the End of Transmission (EOT) - // character (Ctrl-D) - return 0x04; - } - else { throw Term::Exception("getchar() failed"); } -} Term::Event Term::Platform::read_raw() { @@ -46,11 +35,11 @@ Term::Event Term::Platform::read_raw() GetNumberOfConsoleInputEvents(Private::std_cin.getHandler(), &nread); if(nread >= 1) { + std::string ret; + int processed{0}; DWORD nre{0}; std::vector buf{nread}; - if(!ReadConsoleInput(Private::std_cin.getHandler(), &buf[0], buf.size(), &nre)) { Term::Exception("ReadFile() failed"); } - std::string ret(nre, '\0'); - int processed{0}; + if(!ReadConsoleInputW(Private::std_cin.getHandler(), &buf[0], buf.size(), &nre)) { Term::Exception("ReadFile() failed"); } for(std::size_t i = 0; i != nre; ++i) { switch(buf[i].EventType) @@ -61,7 +50,10 @@ Term::Event Term::Platform::read_raw() if(skip == VK_SHIFT || skip == VK_LWIN || skip == VK_RWIN || skip == VK_APPS || skip == VK_CONTROL || skip == VK_MENU || skip == VK_CAPITAL) break; if(buf[i].Event.KeyEvent.bKeyDown) { - if(buf[i].Event.KeyEvent.uChar.AsciiChar != 0) ret[processed] = buf[i].Event.KeyEvent.uChar.AsciiChar; + std::size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, -1, NULL, 0, NULL, NULL); + std::string strTo( size_needed, '\0' ); + WideCharToMultiByte (CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, 1, &strTo[0], size_needed, NULL, NULL); + ret+=strTo.c_str(); ++processed; break; /*else @@ -109,20 +101,27 @@ Term::Event Term::Platform::read_raw() break; } case FOCUS_EVENT: + { + break; + } case MENU_EVENT: + { + break; + } case MOUSE_EVENT: + { + break; + } case WINDOW_BUFFER_SIZE_EVENT: { - COORD coord{buf[i].Event.WindowBufferSizeEvent.dwSize}; - return Event(Screen(coord.Y, coord.X)); + return Event(Screen(buf[i].Event.WindowBufferSizeEvent.dwSize.Y, buf[i].Event.WindowBufferSizeEvent.dwSize.X)); } - default: continue; } } - return Event(ret.c_str()); + if(processed>=1) return Event(ret); + else return Event(); } - else - return Event(); + else return Event(); #else static bool activated{false}; if(!activated) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index af16c0ae..823477f6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -31,9 +31,9 @@ target_link_libraries(keys PRIVATE cpp-terminal::cpp-terminal Warnings::Warnings add_executable(colors colors.cpp) target_link_libraries(colors PRIVATE cpp-terminal::cpp-terminal Warnings::Warnings) -add_executable(read_stdin read_stdin.cpp) -target_link_libraries(read_stdin PRIVATE cpp-terminal::cpp-terminal Warnings::Warnings) +add_executable(events events.cpp) +target_link_libraries(events PRIVATE cpp-terminal::cpp-terminal Warnings::Warnings) if(CPPTERMINAL_ENABLE_INSTALL) - install(TARGETS cin minimal prompt_multiline prompt_immediate prompt_not_immediate prompt_simple kilo menu menu_window keys colors read_stdin RUNTIME DESTINATION bin/examples) + install(TARGETS cin minimal prompt_multiline prompt_immediate prompt_not_immediate prompt_simple kilo menu menu_window keys colors RUNTIME DESTINATION bin/examples) endif() diff --git a/examples/events.cpp b/examples/events.cpp new file mode 100644 index 00000000..8cccbf02 --- /dev/null +++ b/examples/events.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include + +#include + +int main() +{ + try + { + // set options for the console + Term::terminal.setOptions( + Term::Option::ClearScreen, // start from a cear screen + Term::Option::NoSignalKeys, // deactivate key combinations that generate a signal or interrupt + Term::Option::NoCursor, // deactivate the cursor, we will display it ourselfs + Term::Option::Raw // get the raw and unprozessed io data from the console buffers + ); + + // initial render of the whole screen + std::cout << "CTRL + Q to end" << std::endl; + + bool main_loop_continue = true; + while(main_loop_continue) + { + auto event = Term::read_event(); + switch(event.type()) + { + case Term::Event::Type::Empty : + { + Term::terminal << "Event: Empty" << std::endl; + break; + } + case Term::Event::Type::Key : + { + Term::Key keyEvent = event; + Term::terminal << "Event: Key ("<(event)<<")"<< std::endl; + break; + } + default : + { + Term::terminal << "Event: Unknown" << std::endl; + break; + } + } + } + } + catch(...) + { + Term::terminal << "There was an exception!" << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/examples/read_stdin.cpp b/examples/read_stdin.cpp deleted file mode 100644 index a966f24e..00000000 --- a/examples/read_stdin.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "cpp-terminal/input.hpp" -#include "cpp-terminal/io.hpp" -#include "cpp-terminal/terminal.hpp" - -#include - -int main() -{ - Term::terminal.setOptions(Term::Option::NoClearScreen, Term::Option::NoSignalKeys, Term::Option::Cursor, Term::Option::Raw); - std::cout << "Input from stdin: " << Term::read_stdin() << std::endl; -} From 9c60196135ef8626b8234a3a9f98ab47ffd8b6aa Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 22:04:48 +0200 Subject: [PATCH 02/13] pre-commit fix --- cpp-terminal/event.cpp | 16 +++++---------- cpp-terminal/key.cpp | 8 +++----- cpp-terminal/platforms/input.cpp | 23 +++++++++++---------- examples/events.cpp | 35 +++++++++++++------------------- 4 files changed, 34 insertions(+), 48 deletions(-) diff --git a/cpp-terminal/event.cpp b/cpp-terminal/event.cpp index c88cbcff..8446136a 100644 --- a/cpp-terminal/event.cpp +++ b/cpp-terminal/event.cpp @@ -1,5 +1,5 @@ #include "cpp-terminal/event.hpp" -#include + #include "cpp-terminal/platforms/conversion.hpp" bool Term::Event::empty() @@ -29,7 +29,7 @@ Term::Event::Event(const Term::Key& key) : m_Type(Type::Key), m_Key(key) {} Term::Event::Type Term::Event::type() { return m_Type; } -Term::Event::Event(const std::string& str) : m_Type(Type::CopyPaste), m_str(str){ parse();} +Term::Event::Event(const std::string& str) : m_Type(Type::CopyPaste), m_str(str) { parse(); } void Term::Event::parse() { @@ -193,15 +193,9 @@ void Term::Event::parse() m_Key = Key(Term::Key::Value::F20); else if(m_str == "\033[G") m_Key = Key(Term::Key::Value::NUMERIC_5); - else if(m_str.size()==2 && ((m_str[0]&0b11100000)==0b11000000) && ((m_str[1]&0b11000000)==0b10000000)) - { - m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); - } - else if(m_str.size()==3 && ((m_str[0]&0b11110000)==0b11100000) && ((m_str[1]&0b11000000)==0b10000000) && ((m_str[2]&0b11000000)==0b10000000)) - { - m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); - } - else if(m_str.size()==4 && ((m_str[0]&0b11111000)==0b11110000) && ((m_str[1]&0b11000000)==0b10000000) && ((m_str[2]&0b11000000)==0b10000000) && ((m_str[2]&0b11000000)==0b10000000)) + else if(m_str.size() == 2 && ((m_str[0] & 0b11100000) == 0b11000000) && ((m_str[1] & 0b11000000) == 0b10000000)) { m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); } + else if(m_str.size() == 3 && ((m_str[0] & 0b11110000) == 0b11100000) && ((m_str[1] & 0b11000000) == 0b10000000) && ((m_str[2] & 0b11000000) == 0b10000000)) { m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); } + else if(m_str.size() == 4 && ((m_str[0] & 0b11111000) == 0b11110000) && ((m_str[1] & 0b11000000) == 0b10000000) && ((m_str[2] & 0b11000000) == 0b10000000) && ((m_str[2] & 0b11000000) == 0b10000000)) { m_Key = Key(static_cast(Term::Private::utf8_to_utf32(m_str)[0])); } diff --git a/cpp-terminal/key.cpp b/cpp-terminal/key.cpp index 020b7ce9..43cbc837 100644 --- a/cpp-terminal/key.cpp +++ b/cpp-terminal/key.cpp @@ -1,15 +1,13 @@ #include "cpp-terminal/key.hpp" + #include "cpp-terminal/platforms/conversion.hpp" -char32_t Term::Key::codepoint() -{ - return static_cast(m_value); -} +char32_t Term::Key::codepoint() { return static_cast(m_value); } std::string Term::Key::str() { std::string ret; - Term::Private::codepoint_to_utf8(ret,codepoint()); + Term::Private::codepoint_to_utf8(ret, codepoint()); return ret; } diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 2a8acd4d..59f5a3c2 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,8 +1,8 @@ #ifdef _WIN32 - #include - #include #include #include + #include + #include #else #include #include @@ -27,7 +27,6 @@ static void sigwinchHandler(int sig) } #endif - Term::Event Term::Platform::read_raw() { #ifdef _WIN32 @@ -35,8 +34,8 @@ Term::Event Term::Platform::read_raw() GetNumberOfConsoleInputEvents(Private::std_cin.getHandler(), &nread); if(nread >= 1) { - std::string ret; - int processed{0}; + std::string ret; + int processed{0}; DWORD nre{0}; std::vector buf{nread}; if(!ReadConsoleInputW(Private::std_cin.getHandler(), &buf[0], buf.size(), &nre)) { Term::Exception("ReadFile() failed"); } @@ -51,9 +50,9 @@ Term::Event Term::Platform::read_raw() if(buf[i].Event.KeyEvent.bKeyDown) { std::size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, -1, NULL, 0, NULL, NULL); - std::string strTo( size_needed, '\0' ); - WideCharToMultiByte (CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, 1, &strTo[0], size_needed, NULL, NULL); - ret+=strTo.c_str(); + std::string strTo(size_needed, '\0'); + WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, 1, &strTo[0], size_needed, NULL, NULL); + ret += strTo.c_str(); ++processed; break; /*else @@ -118,10 +117,12 @@ Term::Event Term::Platform::read_raw() } } } - if(processed>=1) return Event(ret); - else return Event(); + if(processed >= 1) return Event(ret); + else + return Event(); } - else return Event(); + else + return Event(); #else static bool activated{false}; if(!activated) diff --git a/examples/events.cpp b/examples/events.cpp index 8cccbf02..7df18503 100644 --- a/examples/events.cpp +++ b/examples/events.cpp @@ -1,59 +1,52 @@ #include +#include #include #include -#include - -#include int main() { try { // set options for the console - Term::terminal.setOptions( - Term::Option::ClearScreen, // start from a cear screen - Term::Option::NoSignalKeys, // deactivate key combinations that generate a signal or interrupt - Term::Option::NoCursor, // deactivate the cursor, we will display it ourselfs - Term::Option::Raw // get the raw and unprozessed io data from the console buffers - ); - + Term::terminal.setOptions(Term::Option::ClearScreen, Term::Option::NoSignalKeys, Term::Option::NoCursor, Term::Option::Raw); // initial render of the whole screen - std::cout << "CTRL + Q to end" << std::endl; - + Term::terminal << "CTRL + Q to end" << std::endl; bool main_loop_continue = true; while(main_loop_continue) { auto event = Term::read_event(); switch(event.type()) { - case Term::Event::Type::Empty : + case Term::Event::Type::Empty: { Term::terminal << "Event: Empty" << std::endl; break; } - case Term::Event::Type::Key : + case Term::Event::Type::Key: { Term::Key keyEvent = event; - Term::terminal << "Event: Key ("<(event)<<")"<< std::endl; + Term::terminal << "Event: CopyPaste (" << static_cast(event) << ")" << std::endl; break; } - default : + default: { Term::terminal << "Event: Unknown" << std::endl; break; @@ -66,4 +59,4 @@ int main() Term::terminal << "There was an exception!" << std::endl; } return 0; -} \ No newline at end of file +} From fa845f90ce7029bb3a8106f4104e82c45cc2c14f Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 22:10:17 +0200 Subject: [PATCH 03/13] suppress buggy read_stdin --- ci/examples.ps1 | 7 ------- ci/examples.sh | 7 ------- 2 files changed, 14 deletions(-) diff --git a/ci/examples.ps1 b/ci/examples.ps1 index dc694907..29480394 100644 --- a/ci/examples.ps1 +++ b/ci/examples.ps1 @@ -1,9 +1,2 @@ echo "running example programs" .\install\bin\examples\colors.exe - -echo "testing read_stind" -if ((echo test | .\install\bin\examples\read_stdin.exe) -ne "Input from stdin: test") -{ - echo "read_stdin gave wrong output" - exit 1 -} diff --git a/ci/examples.sh b/ci/examples.sh index 32086c8f..89af39fa 100755 --- a/ci/examples.sh +++ b/ci/examples.sh @@ -3,13 +3,6 @@ set -ex ./install/bin/examples/colors -./install/bin/examples/read_stdin - -echo "testing stdin example" -if [[ $(echo test | ./install/bin/examples/read_stdin) != "Input from stdin: test" ]]; then - echo "stdin example returned wrong input" - exit 1 -fi echo "Expected to succeed:" ./install/bin/examples/colors < ./install/bin/examples/colors From d388da0456b9a9fcbf75a353b66cd19432747ea0 Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 22:22:08 +0200 Subject: [PATCH 04/13] Fix windows --- cpp-terminal/platforms/input.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 59f5a3c2..263a9f46 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,8 +1,7 @@ #ifdef _WIN32 - #include + #include #include #include - #include #else #include #include From 09b2c46b404f8cc39593406e5ba05f0fdfb2d68d Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 22:48:05 +0200 Subject: [PATCH 05/13] Fix windows --- cpp-terminal/key.cpp | 10 ++++++---- cpp-terminal/key.hpp | 1 - cpp-terminal/platforms/input.cpp | 13 ++++++++++--- examples/events.cpp | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cpp-terminal/key.cpp b/cpp-terminal/key.cpp index 43cbc837..969d4f24 100644 --- a/cpp-terminal/key.cpp +++ b/cpp-terminal/key.cpp @@ -2,13 +2,15 @@ #include "cpp-terminal/platforms/conversion.hpp" -char32_t Term::Key::codepoint() { return static_cast(m_value); } - std::string Term::Key::str() { std::string ret; - Term::Private::codepoint_to_utf8(ret, codepoint()); - return ret; + if(m_value>=0x10FFFF) return std::string(); + else + { + Term::Private::codepoint_to_utf8(ret, static_cast(m_value)); + return ret; + } } Term::Key::Key(const Term::Key::Value& value) : m_value(value) {} diff --git a/cpp-terminal/key.hpp b/cpp-terminal/key.hpp index 910c1df9..2a56df49 100644 --- a/cpp-terminal/key.hpp +++ b/cpp-terminal/key.hpp @@ -226,7 +226,6 @@ class Key bool empty(); std::string str(); - char32_t codepoint(); private: Value m_value{NO_KEY}; diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 263a9f46..4a263a54 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,5 +1,12 @@ #ifdef _WIN32 - #include + #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) + #define _AMD64_ + #elif defined(i386) || defined(__i386) || defined(__i386__) || defined(__i386__) || defined(_M_IX86) + #define _X86_ + #elif defined(__arm__) || defined(_M_ARM) || defined(_M_ARMT) + #define _ARM_ + #endif + #include #include #include #else @@ -44,8 +51,8 @@ Term::Event Term::Platform::read_raw() { case KEY_EVENT: { - WORD skip = buf[i].Event.KeyEvent.wVirtualKeyCode; //skip them for now - if(skip == VK_SHIFT || skip == VK_LWIN || skip == VK_RWIN || skip == VK_APPS || skip == VK_CONTROL || skip == VK_MENU || skip == VK_CAPITAL) break; + + if(buf[i].Event.KeyEvent.wVirtualKeyCode!=0) break; //skip them for now if(buf[i].Event.KeyEvent.bKeyDown) { std::size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, -1, NULL, 0, NULL, NULL); diff --git a/examples/events.cpp b/examples/events.cpp index 7df18503..efee5985 100644 --- a/examples/events.cpp +++ b/examples/events.cpp @@ -8,7 +8,7 @@ int main() try { // set options for the console - Term::terminal.setOptions(Term::Option::ClearScreen, Term::Option::NoSignalKeys, Term::Option::NoCursor, Term::Option::Raw); + Term::terminal.setOptions(Term::Option::NoClearScreen, Term::Option::NoSignalKeys, Term::Option::Cursor, Term::Option::Raw); // initial render of the whole screen Term::terminal << "CTRL + Q to end" << std::endl; bool main_loop_continue = true; From cb92b3f2467610e6d28a41e9f3f665f35888401c Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 22:48:23 +0200 Subject: [PATCH 06/13] Fix windows --- cpp-terminal/key.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp-terminal/key.cpp b/cpp-terminal/key.cpp index 969d4f24..13ad3360 100644 --- a/cpp-terminal/key.cpp +++ b/cpp-terminal/key.cpp @@ -8,8 +8,8 @@ std::string Term::Key::str() if(m_value>=0x10FFFF) return std::string(); else { - Term::Private::codepoint_to_utf8(ret, static_cast(m_value)); - return ret; + Term::Private::codepoint_to_utf8(ret, static_cast(m_value)); + return ret; } } From ecc95c4a3c7c390f0a79b54251673e7387e4d225 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 11 Jun 2023 20:50:16 +0000 Subject: [PATCH 07/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cpp-terminal/key.cpp | 2 +- cpp-terminal/platforms/input.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cpp-terminal/key.cpp b/cpp-terminal/key.cpp index 13ad3360..38f2bbc7 100644 --- a/cpp-terminal/key.cpp +++ b/cpp-terminal/key.cpp @@ -5,7 +5,7 @@ std::string Term::Key::str() { std::string ret; - if(m_value>=0x10FFFF) return std::string(); + if(m_value >= 0x10FFFF) return std::string(); else { Term::Private::codepoint_to_utf8(ret, static_cast(m_value)); diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 4a263a54..507251ac 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -51,8 +51,7 @@ Term::Event Term::Platform::read_raw() { case KEY_EVENT: { - - if(buf[i].Event.KeyEvent.wVirtualKeyCode!=0) break; //skip them for now + if(buf[i].Event.KeyEvent.wVirtualKeyCode != 0) break; //skip them for now if(buf[i].Event.KeyEvent.bKeyDown) { std::size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, -1, NULL, 0, NULL, NULL); From d2c210a9cdcc06cab7e56f007ea710bb8e04aa45 Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 23:01:02 +0200 Subject: [PATCH 08/13] Update input.cpp --- cpp-terminal/platforms/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 507251ac..ce86b396 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -6,7 +6,7 @@ #elif defined(__arm__) || defined(_M_ARM) || defined(_M_ARMT) #define _ARM_ #endif - #include + #include #include #include #else From e6406a9a600ef4c84f34426c0aace36c2fcbeda0 Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 23:06:35 +0200 Subject: [PATCH 09/13] Update input.cpp --- cpp-terminal/platforms/input.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index ce86b396..69c9fe2c 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,14 +1,7 @@ #ifdef _WIN32 - #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) - #define _AMD64_ - #elif defined(i386) || defined(__i386) || defined(__i386__) || defined(__i386__) || defined(_M_IX86) - #define _X86_ - #elif defined(__arm__) || defined(_M_ARM) || defined(_M_ARMT) - #define _ARM_ - #endif - #include #include #include + #include #else #include #include From 1663037270dfbe532278cbc98f736de3845fe70d Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 23:19:05 +0200 Subject: [PATCH 10/13] Fix windows --- cpp-terminal/platforms/input.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 69c9fe2c..cc6f208c 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,7 +1,7 @@ #ifdef _WIN32 + #include #include #include - #include #else #include #include @@ -44,7 +44,8 @@ Term::Event Term::Platform::read_raw() { case KEY_EVENT: { - if(buf[i].Event.KeyEvent.wVirtualKeyCode != 0) break; //skip them for now + + if(buf[i].Event.KeyEvent.wVirtualKeyCode!=0) break; //skip them for now if(buf[i].Event.KeyEvent.bKeyDown) { std::size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, -1, NULL, 0, NULL, NULL); From c0fefd66a397ebb457a6e9819e3dec9ef90ae222 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 11 Jun 2023 21:19:27 +0000 Subject: [PATCH 11/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cpp-terminal/platforms/input.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index cc6f208c..69c9fe2c 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,7 +1,7 @@ #ifdef _WIN32 - #include #include #include + #include #else #include #include @@ -44,8 +44,7 @@ Term::Event Term::Platform::read_raw() { case KEY_EVENT: { - - if(buf[i].Event.KeyEvent.wVirtualKeyCode!=0) break; //skip them for now + if(buf[i].Event.KeyEvent.wVirtualKeyCode != 0) break; //skip them for now if(buf[i].Event.KeyEvent.bKeyDown) { std::size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, -1, NULL, 0, NULL, NULL); From e03253e50dc3d49b92da077e8854db486892e894 Mon Sep 17 00:00:00 2001 From: flagarde Date: Sun, 11 Jun 2023 23:23:03 +0200 Subject: [PATCH 12/13] Update input.cpp --- cpp-terminal/platforms/input.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 69c9fe2c..13460e91 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -1,7 +1,9 @@ #ifdef _WIN32 + // clang-format off + #include #include + // clang-format on #include - #include #else #include #include From aaa5482c17e1e45a96c19aef268e37b14bd84473 Mon Sep 17 00:00:00 2001 From: flagarde Date: Mon, 19 Jun 2023 00:00:14 +0200 Subject: [PATCH 13/13] Update input.cpp --- cpp-terminal/platforms/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index 13460e91..ee24e54c 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -46,7 +46,7 @@ Term::Event Term::Platform::read_raw() { case KEY_EVENT: { - if(buf[i].Event.KeyEvent.wVirtualKeyCode != 0) break; //skip them for now + //if(buf[i].Event.KeyEvent.wVirtualKeyCode != 0) break; //skip them for now if(buf[i].Event.KeyEvent.bKeyDown) { std::size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, &buf[i].Event.KeyEvent.uChar.UnicodeChar, -1, NULL, 0, NULL, NULL);