mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-21 19:48:16 +08:00
Warn against Microsoft <windows.h> min and max macro (#1084)
Warn users they have defined the min/max macros which is not compatible with other code from the standard library or FTXUI. Co-authored-by: Sylko Olzscher <sylko.olzscher@solostec.ch> Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
@@ -23,8 +23,9 @@ bool GeneratorBool(const char*& data, size_t& size) {
|
||||
|
||||
std::string GeneratorString(const char*& data, size_t& size) {
|
||||
int index = 0;
|
||||
while (index < size && data[index])
|
||||
while (index < size && data[index]) {
|
||||
++index;
|
||||
}
|
||||
|
||||
auto out = std::string(data, data + index);
|
||||
data += index;
|
||||
@@ -40,8 +41,9 @@ std::string GeneratorString(const char*& data, size_t& size) {
|
||||
}
|
||||
|
||||
int GeneratorInt(const char* data, size_t size) {
|
||||
if (size == 0)
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
auto out = int(data[0]);
|
||||
data++;
|
||||
size--;
|
||||
@@ -113,8 +115,9 @@ Components GeneratorComponents(const char*& data, size_t& size, int depth);
|
||||
Component GeneratorComponent(const char*& data, size_t& size, int depth) {
|
||||
depth--;
|
||||
int value = GeneratorInt(data, size);
|
||||
if (depth <= 0)
|
||||
if (depth <= 0) {
|
||||
return Button(GeneratorString(data, size), [] {});
|
||||
}
|
||||
|
||||
constexpr int value_max = 19;
|
||||
value = (value % value_max + value_max) % value_max;
|
||||
|
@@ -1057,8 +1057,9 @@ void ScreenInteractive::FetchTerminalEvents() {
|
||||
case KEY_EVENT: {
|
||||
auto key_event = r.Event.KeyEvent;
|
||||
// ignore UP key events
|
||||
if (key_event.bKeyDown == FALSE)
|
||||
if (key_event.bKeyDown == FALSE) {
|
||||
continue;
|
||||
}
|
||||
std::wstring wstring;
|
||||
wstring += key_event.uChar.UnicodeChar;
|
||||
for (auto it : to_string(wstring)) {
|
||||
|
@@ -28,8 +28,9 @@ namespace {
|
||||
class StdCapture {
|
||||
public:
|
||||
explicit StdCapture(std::string* captured) : captured_(captured) {
|
||||
if (pipe(pipefd_) != 0)
|
||||
if (pipe(pipefd_) != 0) {
|
||||
return;
|
||||
}
|
||||
old_stdout_ = dup(fileno(stdout));
|
||||
fflush(stdout);
|
||||
dup2(pipefd_[1], fileno(stdout));
|
||||
|
@@ -16,5 +16,4 @@ bool PendingTask::operator<(const PendingTask& other) const {
|
||||
}
|
||||
return time.value() > other.time.value();
|
||||
}
|
||||
} // namespace ftxui::task
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
@@ -21,8 +21,7 @@ struct PendingTask {
|
||||
|
||||
// Delayed task with a duration
|
||||
PendingTask(Task t, std::chrono::steady_clock::duration duration)
|
||||
: task(std::move(t)),
|
||||
time(std::chrono::steady_clock::now() + duration) {}
|
||||
: task(std::move(t)), time(std::chrono::steady_clock::now() + duration) {}
|
||||
|
||||
/// The task to be executed.
|
||||
Task task;
|
||||
@@ -36,7 +35,6 @@ struct PendingTask {
|
||||
bool operator<(const PendingTask& other) const;
|
||||
};
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
#endif // TASK_HPP_
|
||||
|
@@ -50,5 +50,4 @@ auto TaskQueue::Get() -> MaybeTask {
|
||||
return std::monostate{};
|
||||
}
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
@@ -25,16 +25,13 @@ struct TaskQueue {
|
||||
std::variant<Task, std::chrono::steady_clock::duration, std::monostate>;
|
||||
auto Get() -> MaybeTask;
|
||||
|
||||
bool HasImmediateTasks() const {
|
||||
return !immediate_tasks_.empty();
|
||||
}
|
||||
bool HasImmediateTasks() const { return !immediate_tasks_.empty(); }
|
||||
|
||||
private:
|
||||
std::queue<PendingTask> immediate_tasks_;
|
||||
std::priority_queue<PendingTask> delayed_tasks_;
|
||||
};
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
#endif
|
||||
|
@@ -20,7 +20,6 @@ TaskRunner::~TaskRunner() {
|
||||
current_task_runner = previous_task_runner_;
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
auto TaskRunner::Current() -> TaskRunner* {
|
||||
assert(current_task_runner);
|
||||
@@ -73,5 +72,4 @@ auto TaskRunner::Run() -> void {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
@@ -21,8 +21,8 @@ class TaskRunner {
|
||||
auto PostTask(Task task) -> void;
|
||||
|
||||
/// Schedules a task to be executed after a certain duration.
|
||||
auto PostDelayedTask(Task task,
|
||||
std::chrono::steady_clock::duration duration) -> void;
|
||||
auto PostDelayedTask(Task task, std::chrono::steady_clock::duration duration)
|
||||
-> void;
|
||||
|
||||
/// Runs the tasks in the queue, return the delay until the next delayed task
|
||||
/// can be executed.
|
||||
@@ -31,9 +31,7 @@ class TaskRunner {
|
||||
// Runs the tasks in the queue, blocking until all tasks are executed.
|
||||
auto Run() -> void;
|
||||
|
||||
bool HasImmediateTasks() const {
|
||||
return queue_.HasImmediateTasks();
|
||||
}
|
||||
bool HasImmediateTasks() const { return queue_.HasImmediateTasks(); }
|
||||
|
||||
size_t ExecutedTasks() const { return executed_tasks_; }
|
||||
|
||||
@@ -43,7 +41,6 @@ class TaskRunner {
|
||||
size_t executed_tasks_ = 0;
|
||||
};
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
} // namespace ftxui::task
|
||||
|
||||
#endif // TASK_RUNNER_HPP
|
||||
|
@@ -91,4 +91,4 @@ TEST(TaskTest, RunDelayedTask) {
|
||||
EXPECT_EQ(values, (std::vector<int>{1, 2, 3}));
|
||||
}
|
||||
|
||||
} // namespace ftxui::task
|
||||
} // namespace ftxui::task
|
||||
|
@@ -152,8 +152,8 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
|
||||
|
||||
case CURSOR_POSITION:
|
||||
out_(Event::CursorPosition(std::move(pending_), // NOLINT
|
||||
output.cursor.x, // NOLINT
|
||||
output.cursor.y)); // NOLINT
|
||||
output.cursor.x, // NOLINT
|
||||
output.cursor.y)); // NOLINT
|
||||
pending_.clear();
|
||||
return;
|
||||
|
||||
|
@@ -17,16 +17,19 @@ namespace ftxui {
|
||||
// Test char |c| to are trivially converted into |Event::Character(c)|.
|
||||
TEST(Event, Character) {
|
||||
std::vector<char> basic_char;
|
||||
for (char c = 'a'; c <= 'z'; ++c)
|
||||
for (char c = 'a'; c <= 'z'; ++c) {
|
||||
basic_char.push_back(c);
|
||||
for (char c = 'A'; c <= 'Z'; ++c)
|
||||
}
|
||||
for (char c = 'A'; c <= 'Z'; ++c) {
|
||||
basic_char.push_back(c);
|
||||
}
|
||||
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
for (char c : basic_char)
|
||||
for (char c : basic_char) {
|
||||
parser.Add(c);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < basic_char.size(); ++i) {
|
||||
EXPECT_TRUE(received_events[i].is_character());
|
||||
@@ -285,8 +288,9 @@ TEST(Event, UTF8) {
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
for (auto input : test.input)
|
||||
for (auto input : test.input) {
|
||||
parser.Add(input);
|
||||
}
|
||||
|
||||
if (test.valid) {
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
@@ -315,8 +319,9 @@ TEST(Event, Control) {
|
||||
};
|
||||
std::vector<TestCase> cases;
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
if (i == 8 || i == 13 || i == 24 || i == 26 || i == 27)
|
||||
if (i == 8 || i == 13 || i == 24 || i == 26 || i == 27) {
|
||||
continue;
|
||||
}
|
||||
cases.push_back({char(i), false});
|
||||
}
|
||||
cases.push_back({char(24), false});
|
||||
@@ -341,8 +346,9 @@ TEST(Event, Control) {
|
||||
TEST(Event, Special) {
|
||||
auto str = [](std::string input) {
|
||||
std::vector<unsigned char> output;
|
||||
for (auto it : input)
|
||||
for (auto it : input) {
|
||||
output.push_back(it);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
@@ -351,9 +357,12 @@ TEST(Event, Special) {
|
||||
Event expected;
|
||||
} kTestCase[] = {
|
||||
// Arrow (default cursor mode)
|
||||
{str("[A"), Event::ArrowUp}, {str("[B"), Event::ArrowDown},
|
||||
{str("[C"), Event::ArrowRight}, {str("[D"), Event::ArrowLeft},
|
||||
{str("[H"), Event::Home}, {str("[F"), Event::End},
|
||||
{str("[A"), Event::ArrowUp},
|
||||
{str("[B"), Event::ArrowDown},
|
||||
{str("[C"), Event::ArrowRight},
|
||||
{str("[D"), Event::ArrowLeft},
|
||||
{str("[H"), Event::Home},
|
||||
{str("[F"), Event::End},
|
||||
|
||||
// Arrow (application cursor mode)
|
||||
{str("\x1BOA"), Event::ArrowUp},
|
||||
|
@@ -47,8 +47,9 @@ namespace {
|
||||
#if defined(_WIN32)
|
||||
void WindowsEmulateVT100Terminal() {
|
||||
static bool done = false;
|
||||
if (done)
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
done = true;
|
||||
|
||||
// Enable VT processing on stdout and stdin
|
||||
|
@@ -1284,8 +1284,9 @@ bool IsCombining(uint32_t ucs) {
|
||||
}
|
||||
|
||||
bool IsFullWidth(uint32_t ucs) {
|
||||
if (ucs < 0x0300) // Quick path: // NOLINT
|
||||
if (ucs < 0x0300) { // Quick path: // NOLINT
|
||||
return false;
|
||||
}
|
||||
|
||||
return Bisearch(ucs, g_full_width_characters);
|
||||
}
|
||||
|
Reference in New Issue
Block a user