mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-23 03:10:01 +08:00
Merge remote-tracking branch 'origin' into feature/mouse-support
This commit is contained in:
commit
be219633e3
@ -142,7 +142,7 @@ foreach(lib screen dom component)
|
|||||||
# Add as many warning as possible:
|
# Add as many warning as possible:
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${lib} PRIVATE "/W4")
|
target_compile_options(${lib} PRIVATE "/W3")
|
||||||
target_compile_options(${lib} PRIVATE "/WX")
|
target_compile_options(${lib} PRIVATE "/WX")
|
||||||
target_compile_options(${lib} PRIVATE "/wd4244")
|
target_compile_options(${lib} PRIVATE "/wd4244")
|
||||||
target_compile_options(${lib} PRIVATE "/wd4267")
|
target_compile_options(${lib} PRIVATE "/wd4267")
|
||||||
@ -228,9 +228,10 @@ if (FTXUI_BUILD_TESTS AND ${CMAKE_VERSION} VERSION_GREATER "3.11.4")
|
|||||||
|
|
||||||
add_executable(tests
|
add_executable(tests
|
||||||
src/ftxui/component/container_test.cpp
|
src/ftxui/component/container_test.cpp
|
||||||
src/ftxui/component/terminal_input_parser_test.cpp
|
src/ftxui/component/input_test.cpp
|
||||||
src/ftxui/component/radiobox_test.cpp
|
src/ftxui/component/radiobox_test.cpp
|
||||||
src/ftxui/component/receiver_test.cpp
|
src/ftxui/component/receiver_test.cpp
|
||||||
|
src/ftxui/component/terminal_input_parser_test.cpp
|
||||||
src/ftxui/component/toggle_test.cpp
|
src/ftxui/component/toggle_test.cpp
|
||||||
src/ftxui/dom/gauge_test.cpp
|
src/ftxui/dom/gauge_test.cpp
|
||||||
src/ftxui/dom/hbox_test.cpp
|
src/ftxui/dom/hbox_test.cpp
|
||||||
|
@ -27,11 +27,13 @@ A simple C++ library for terminal based user interface.
|
|||||||
* Support for [UTF8](https://en.wikipedia.org/wiki/UTF-8) and [fullwidth chars](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) (→ 测试)
|
* Support for [UTF8](https://en.wikipedia.org/wiki/UTF-8) and [fullwidth chars](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) (→ 测试)
|
||||||
* No dependencies.
|
* No dependencies.
|
||||||
* Cross platform (mostly). Linux (main target), Windows (experimental), Mac.
|
* Cross platform (mostly). Linux (main target), Windows (experimental), Mac.
|
||||||
|
* Keyboard navigation.
|
||||||
|
* Mouse support (very soon, [feedback](https://github.com/ArthurSonzogni/FTXUI/issues/7#issuecomment-826339732) needed)
|
||||||
|
|
||||||
## Operating systems
|
## Operating systems
|
||||||
- [![linux-gcc][badge.linux-gcc]][link.linux-gcc]
|
- [![linux-gcc][badge.linux-gcc]][link.linux-gcc]
|
||||||
- [![linux-clang][badge.linux-clang]][link.linux-clang]
|
[![linux-clang][badge.linux-clang]][link.linux-clang]
|
||||||
- [![linux-emscripten][badge.linux-emscripten]][link.linux-emscripten]
|
[![linux-emscripten][badge.linux-emscripten]][link.linux-emscripten]
|
||||||
- [![windows-msvc][badge.windows-msvc]][link.windows-msvc]
|
- [![windows-msvc][badge.windows-msvc]][link.windows-msvc]
|
||||||
- [![mac-clang][badge.mac-clang]][link.mac-clang]
|
- [![mac-clang][badge.mac-clang]][link.mac-clang]
|
||||||
|
|
||||||
@ -88,7 +90,7 @@ Feel free to add your projects here:
|
|||||||
- [Pigeon ROS TUI](https://github.com/PigeonSensei/Pigeon_ros_tui)
|
- [Pigeon ROS TUI](https://github.com/PigeonSensei/Pigeon_ros_tui)
|
||||||
- [hastur](https://github.com/robinlinden/hastur)
|
- [hastur](https://github.com/robinlinden/hastur)
|
||||||
- [CryptoCalculator](https://github.com/brevis/CryptoCalculator)
|
- [CryptoCalculator](https://github.com/brevis/CryptoCalculator)
|
||||||
-
|
- [todoman](https://github.com/aaleino/todoman)
|
||||||
|
|
||||||
## Hosted on:
|
## Hosted on:
|
||||||
* [github](https://github.com/ArthurSonzogni/ftxui)
|
* [github](https://github.com/ArthurSonzogni/ftxui)
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<div class="page">
|
<div class="page">
|
||||||
<h1>FTXUI WebAssembly Example </h1>
|
<h1>FTXUI WebAssembly Example </h1>
|
||||||
<p>
|
<p>
|
||||||
<a href="https://github.com/ArthurSonzogni/FTXUI">FTXUI</a> is a simple
|
<a href="https://github.com/ArthurSonzogni/FTXUI">FTXUI</a> is a single
|
||||||
C++ library for terminal user interface.
|
C++ library for terminal user interface.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
@ -93,7 +93,6 @@
|
|||||||
stdout_buffer = [];
|
stdout_buffer = [];
|
||||||
let stdout = code => {
|
let stdout = code => {
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
console.log(code);
|
|
||||||
term.write(new Uint8Array(stdout_buffer));
|
term.write(new Uint8Array(stdout_buffer));
|
||||||
stdout_buffer = [];
|
stdout_buffer = [];
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,6 +47,12 @@ struct Event {
|
|||||||
static const Event TabReverse;
|
static const Event TabReverse;
|
||||||
static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
|
static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
|
||||||
|
|
||||||
|
static const Event Home;
|
||||||
|
static const Event End;
|
||||||
|
|
||||||
|
static const Event PageUp;
|
||||||
|
static const Event PageDown;
|
||||||
|
|
||||||
// --- Custom ---
|
// --- Custom ---
|
||||||
static Event Custom;
|
static Event Custom;
|
||||||
|
|
||||||
@ -66,6 +72,7 @@ struct Event {
|
|||||||
const std::string& input() const { return input_; }
|
const std::string& input() const { return input_; }
|
||||||
|
|
||||||
bool operator==(const Event& other) const { return input_ == other.input_; }
|
bool operator==(const Event& other) const { return input_ == other.input_; }
|
||||||
|
bool operator!=(const Event& other) const { return !operator==(other); }
|
||||||
|
|
||||||
//--- State section ----------------------------------------------------------
|
//--- State section ----------------------------------------------------------
|
||||||
private:
|
private:
|
||||||
|
@ -81,6 +81,11 @@ const Event Event::F9 = Event::Special("\x1B[20~");
|
|||||||
const Event Event::F10 = Event::Special("\x1B[21~");
|
const Event Event::F10 = Event::Special("\x1B[21~");
|
||||||
const Event Event::F11 = Event::Special("\x1B[21~"); // Doesn't exist
|
const Event Event::F11 = Event::Special("\x1B[21~"); // Doesn't exist
|
||||||
const Event Event::F12 = Event::Special("\x1B[24~");
|
const Event Event::F12 = Event::Special("\x1B[24~");
|
||||||
|
const Event Event::Home = Event::Special({27, 91, 72});
|
||||||
|
const Event Event::End = Event::Special({27, 91, 70});
|
||||||
|
const Event Event::PageUp = Event::Special({27, 91, 53, 126});
|
||||||
|
const Event Event::PageDown = Event::Special({27, 91, 54, 126});
|
||||||
|
|
||||||
Event Event::Custom = Event::Special({0});
|
Event Event::Custom = Event::Special({0});
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
@ -94,6 +94,16 @@ bool Input::OnEvent(Event event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event == Event::Home) {
|
||||||
|
cursor_position = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event == Event::End) {
|
||||||
|
cursor_position = (int)content.size();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Content
|
// Content
|
||||||
if (event.is_character()) {
|
if (event.is_character()) {
|
||||||
content.insert(cursor_position, 1, event.character());
|
content.insert(cursor_position, 1, event.character());
|
||||||
|
159
src/ftxui/component/input_test.cpp
Normal file
159
src/ftxui/component/input_test.cpp
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
#include "ftxui/component/input.hpp"
|
||||||
|
#include "ftxui/component/event.hpp"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
using namespace ftxui;
|
||||||
|
|
||||||
|
TEST(InputTest, Init) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
EXPECT_EQ(input.content, L"");
|
||||||
|
EXPECT_EQ(input.placeholder, L"");
|
||||||
|
EXPECT_EQ(input.cursor_position, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(InputTest, Type) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('a'));
|
||||||
|
EXPECT_EQ(input.content, L"a");
|
||||||
|
EXPECT_EQ(input.cursor_position, 1u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('b'));
|
||||||
|
EXPECT_EQ(input.content, L"ab");
|
||||||
|
EXPECT_EQ(input.cursor_position, 2u);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(InputTest, Arrow) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('a'));
|
||||||
|
input.OnEvent(Event::Character('b'));
|
||||||
|
input.OnEvent(Event::Character('c'));
|
||||||
|
|
||||||
|
EXPECT_EQ(input.cursor_position, 3u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(input.cursor_position, 2u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(input.cursor_position, 1u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(input.cursor_position, 0u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(input.cursor_position, 0u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(input.cursor_position, 1u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(input.cursor_position, 2u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(input.cursor_position, 3u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(input.cursor_position, 3u);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(InputTest, Insert) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('a'));
|
||||||
|
input.OnEvent(Event::Character('b'));
|
||||||
|
input.OnEvent(Event::Character('c'));
|
||||||
|
EXPECT_EQ(input.content, L"abc");
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
input.OnEvent(Event::Character('-'));
|
||||||
|
EXPECT_EQ(input.content, L"a-bc");
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
input.OnEvent(Event::Character('-'));
|
||||||
|
EXPECT_EQ(input.content, L"a--bc");
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
input.OnEvent(Event::Character('-'));
|
||||||
|
EXPECT_EQ(input.content, L"-a--bc");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(InputTest, Home) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('a'));
|
||||||
|
input.OnEvent(Event::Character('b'));
|
||||||
|
input.OnEvent(Event::Character('c'));
|
||||||
|
EXPECT_EQ(input.content, L"abc");
|
||||||
|
|
||||||
|
EXPECT_EQ(input.cursor_position, 3u);
|
||||||
|
input.OnEvent(Event::Home);
|
||||||
|
EXPECT_EQ(input.cursor_position, 0u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('-'));
|
||||||
|
EXPECT_EQ(input.content, L"-abc");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(InputTest, End) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('a'));
|
||||||
|
input.OnEvent(Event::Character('b'));
|
||||||
|
input.OnEvent(Event::Character('c'));
|
||||||
|
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
|
||||||
|
EXPECT_EQ(input.cursor_position, 1u);
|
||||||
|
input.OnEvent(Event::End);
|
||||||
|
EXPECT_EQ(input.cursor_position, 3u);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(InputTest, Delete) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('a'));
|
||||||
|
input.OnEvent(Event::Character('b'));
|
||||||
|
input.OnEvent(Event::Character('c'));
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
|
||||||
|
EXPECT_EQ(input.content, L"abc");
|
||||||
|
EXPECT_EQ(input.cursor_position, 2u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::Delete);
|
||||||
|
EXPECT_EQ(input.content, L"ab");
|
||||||
|
EXPECT_EQ(input.cursor_position, 2u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::Delete);
|
||||||
|
EXPECT_EQ(input.content, L"ab");
|
||||||
|
EXPECT_EQ(input.cursor_position, 2u);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(InputTest, Backspace) {
|
||||||
|
Input input;
|
||||||
|
|
||||||
|
input.OnEvent(Event::Character('a'));
|
||||||
|
input.OnEvent(Event::Character('b'));
|
||||||
|
input.OnEvent(Event::Character('c'));
|
||||||
|
input.OnEvent(Event::ArrowLeft);
|
||||||
|
|
||||||
|
EXPECT_EQ(input.content, L"abc");
|
||||||
|
EXPECT_EQ(input.cursor_position, 2u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::Backspace);
|
||||||
|
EXPECT_EQ(input.content, L"ac");
|
||||||
|
EXPECT_EQ(input.cursor_position, 1u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::Backspace);
|
||||||
|
EXPECT_EQ(input.content, L"c");
|
||||||
|
EXPECT_EQ(input.cursor_position, 0u);
|
||||||
|
|
||||||
|
input.OnEvent(Event::Backspace);
|
||||||
|
EXPECT_EQ(input.content, L"c");
|
||||||
|
EXPECT_EQ(input.cursor_position, 0u);
|
||||||
|
}
|
@ -110,7 +110,7 @@ void EventListener(std::atomic<bool>* quit, Sender<Event> out) {
|
|||||||
|
|
||||||
char c;
|
char c;
|
||||||
while (!*quit) {
|
while (!*quit) {
|
||||||
while (read(STDIN_FILENO, &c, 1), c)
|
while(read(STDIN_FILENO, &c, 1), c)
|
||||||
parser.Add(c);
|
parser.Add(c);
|
||||||
|
|
||||||
emscripten_sleep(1);
|
emscripten_sleep(1);
|
||||||
|
@ -5,7 +5,11 @@
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/ioctl.h> // for winsize, ioctl, TIOCGWINSZ
|
#include <sys/ioctl.h> // for winsize, ioctl, TIOCGWINSZ
|
||||||
|
Loading…
Reference in New Issue
Block a user