Use IWYU.

This commit is contained in:
ArthurSonzogni
2021-05-01 20:40:35 +02:00
parent eb399d20c5
commit 155758c073
119 changed files with 770 additions and 342 deletions

View File

@@ -1,7 +1,11 @@
#include "ftxui/component/button.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include <functional> // for function
#include <memory> // for shared_ptr
#include <functional>
#include "ftxui/component/button.hpp"
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
#include "ftxui/component/event.hpp" // for Event, Event::Return
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
namespace ftxui {
@@ -12,7 +16,7 @@ Element Button::Render() {
bool Button::OnEvent(Event event) {
if (event.is_mouse() && box_.Contain(event.mouse().x, event.mouse().y)) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
TakeFocus();

View File

@@ -1,7 +1,11 @@
#include "ftxui/component/checkbox.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include <functional> // for function
#include <memory> // for shared_ptr
#include <functional>
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
#include "ftxui/component/checkbox.hpp"
#include "ftxui/component/event.hpp" // for Event, Event::Return
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
namespace ftxui {
@@ -27,7 +31,7 @@ bool CheckBox::OnEvent(Event event) {
}
bool CheckBox::OnMouseEvent(Event event) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
if (!box_.Contain(event.mouse().x, event.mouse().y))
return false;

View File

@@ -1,11 +1,20 @@
#include "ftxui/component/component.hpp"
#include <assert.h>
#include <algorithm>
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/event.hpp"
#include "ftxui/component/screen_interactive.hpp"
namespace ftxui {
namespace {
class CaptureMouseImpl : public CapturedMouseInterface {
public:
~CaptureMouseImpl() override {}
};
}
Component::~Component() {
Detach();
}
@@ -97,6 +106,16 @@ void Component::TakeFocus() {
}
}
/// @brief Take the CapturedMouse if available. There is only one component of
/// them. It represents a component taking priority over others.
/// @argument event
/// @ingroup component
CapturedMouse Component::CaptureMouse(const Event& event) {
if (!event.screen_)
return std::make_unique<CaptureMouseImpl>();
return event.screen_->CaptureMouse();
}
/// @brief Detach this children from its parent.
/// @see Attach
/// @see Detach

View File

@@ -1,6 +1,8 @@
#include "ftxui/component/container.hpp"
#include <stddef.h>
#include <algorithm>
#include <vector>
namespace ftxui {

View File

@@ -1,6 +1,10 @@
#include "ftxui/component/container.hpp"
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
#include <memory> // for allocator
#include "gtest/gtest.h"
#include "ftxui/component/container.hpp"
#include "ftxui/screen/box.hpp" // for ftxui
#include "gtest/gtest_pred_impl.h" // for AssertionResult, EXPECT_EQ, EXPEC...
using namespace ftxui;

View File

@@ -1,6 +1,6 @@
#include "ftxui/component/event.hpp"
#include <iostream>
#include "ftxui/component/mouse.hpp"
#include "ftxui/screen/string.hpp"
namespace ftxui {

View File

@@ -1,9 +1,11 @@
#include "ftxui/component/input.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include <algorithm>
#include <memory>
#include "ftxui/screen/string.hpp"
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/mouse.hpp"
#include "ftxui/component/screen_interactive.hpp"
namespace ftxui {
@@ -103,7 +105,7 @@ bool Input::OnEvent(Event event) {
}
bool Input::OnMouseEvent(Event event) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
if (!input_box_.Contain(event.mouse().x, event.mouse().y))
return false;

View File

@@ -1,8 +1,13 @@
#include "ftxui/component/menu.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include <stddef.h>
#include <algorithm>
#include <iostream>
#include <memory>
#include <utility>
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/mouse.hpp"
#include "ftxui/component/screen_interactive.hpp"
namespace ftxui {
@@ -28,7 +33,7 @@ Element Menu::Render() {
}
bool Menu::OnEvent(Event event) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
if (event.is_mouse())
return OnMouseEvent(event);
@@ -63,7 +68,7 @@ bool Menu::OnEvent(Event event) {
}
bool Menu::OnMouseEvent(Event event) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
for (int i = 0; i < boxes_.size(); ++i) {
if (!boxes_[i].Contain(event.mouse().x, event.mouse().y))

View File

@@ -1,8 +1,14 @@
#include "ftxui/component/radiobox.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include <stddef.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <utility>
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/mouse.hpp"
#include "ftxui/component/screen_interactive.hpp"
namespace ftxui {
@@ -13,8 +19,9 @@ Element RadioBox::Render() {
for (size_t i = 0; i < entries.size(); ++i) {
auto style =
(focused == int(i) && is_focused) ? focused_style : unfocused_style;
auto focus_management =
(focused != int(i)) ? nothing : is_focused ? focus : select;
auto focus_management = (focused != int(i)) ? nothing
: is_focused ? focus
: select;
const std::wstring& symbol = selected == int(i) ? checked : unchecked;
elements.push_back(hbox(text(symbol), text(entries[i]) | style) |
@@ -24,7 +31,7 @@ Element RadioBox::Render() {
}
bool RadioBox::OnEvent(Event event) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
if (event.is_mouse())
return OnMouseEvent(event);
@@ -58,7 +65,7 @@ bool RadioBox::OnEvent(Event event) {
}
bool RadioBox::OnMouseEvent(Event event) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
for (int i = 0; i < boxes_.size(); ++i) {
if (!boxes_[i].Contain(event.mouse().x, event.mouse().y))

View File

@@ -1,6 +1,10 @@
#include "ftxui/component/radiobox.hpp"
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver, TestFactoryImpl
#include "gtest/gtest.h"
#include "ftxui/component/event.hpp" // for Event, Event::ArrowDown, Event::ArrowUp, Event::Tab, Event::TabReverse
#include "ftxui/component/mouse.hpp" // for ftxui
#include "ftxui/component/radiobox.hpp"
#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, TEST
using namespace ftxui;

View File

@@ -1,8 +1,10 @@
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <thread> // for thread
#include <utility> // for move
#include "ftxui/component/receiver.hpp"
#include <thread>
#include "gtest/gtest.h"
#include "gtest/gtest_pred_impl.h" // for AssertionResult, Test, EXPECT_EQ
using namespace ftxui;

View File

@@ -1,19 +1,24 @@
#include "ftxui/component/screen_interactive.hpp"
#include <stdio.h>
#include <stdio.h> // for fileno, stdin
#include <algorithm> // for copy, max, min
#include <csignal> // for signal, SIGINT
#include <cstdlib> // for exit, NULL
#include <iostream> // for cout, ostream
#include <stack> // for stack
#include <thread> // for thread
#include <utility> // for move
#include <vector> // for vector
#include <algorithm>
#include <csignal>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <thread>
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/component.hpp"
#include "ftxui/component/terminal_input_parser.hpp"
#include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp"
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
#include "ftxui/component/component.hpp" // for Component
#include "ftxui/component/event.hpp" // for Event
#include "ftxui/component/mouse.hpp" // for Mouse
#include "ftxui/component/receiver.hpp" // for ReceiverImpl
#include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputPa...
#include "ftxui/dom/node.hpp" // for Node, Render
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/screen/terminal.hpp" // for Terminal::Dimen...
#if defined(_WIN32)
#define DEFINE_CONSOLEV2_PROPERTIES
@@ -26,8 +31,9 @@
#error Must be compiled in UNICODE mode
#endif
#else
#include <termios.h>
#include <unistd.h>
#include <sys/select.h> // for select, FD_ISSET
#include <termios.h> // for tcsetattr, tcge...
#include <unistd.h> // for STDIN_FILENO, read
#endif
// Quick exit is missing in standard CLang headers
@@ -48,8 +54,7 @@ constexpr int timeout_milliseconds = 20;
constexpr int timeout_microseconds = timeout_milliseconds * 1000;
#if defined(_WIN32)
void EventListener(std::atomic<bool>* quit,
Sender<Event> out) {
void EventListener(std::atomic<bool>* quit, Sender<Event> out) {
auto console = GetStdHandle(STD_INPUT_HANDLE);
auto parser = TerminalInputParser(out->Clone());
while (!*quit) {
@@ -69,8 +74,7 @@ void EventListener(std::atomic<bool>* quit,
std::vector<INPUT_RECORD> records{number_of_events};
DWORD number_of_events_read = 0;
ReadConsoleInput(console, records.data(),
(DWORD)records.size(),
ReadConsoleInput(console, records.data(), (DWORD)records.size(),
&number_of_events_read);
records.resize(number_of_events_read);
@@ -106,7 +110,7 @@ void EventListener(std::atomic<bool>* quit, Sender<Event> out) {
char c;
while (!*quit) {
while(read(STDIN_FILENO, &c, 1), c)
while (read(STDIN_FILENO, &c, 1), c)
parser.Add(c);
emscripten_sleep(1);
@@ -115,7 +119,7 @@ void EventListener(std::atomic<bool>* quit, Sender<Event> out) {
}
#else
#include <sys/time.h>
#include <sys/time.h> // for timeval
int CheckStdinReady(int usec_timeout) {
timeval tv = {0, usec_timeout};
@@ -219,8 +223,7 @@ void OnResize(int /* signal */) {
class CapturedMouseImpl : public CapturedMouseInterface {
public:
CapturedMouseImpl(std::function<void(void)> callback)
: callback_(callback) {}
CapturedMouseImpl(std::function<void(void)> callback) : callback_(callback) {}
~CapturedMouseImpl() override { callback_(); }
private:
@@ -366,7 +369,7 @@ void ScreenInteractive::Loop(Component* component) {
});
enable({
//DECMode::kMouseVt200,
// DECMode::kMouseVt200,
DECMode::kMouseAnyEvent,
DECMode::kMouseUtf8,
DECMode::kMouseSgrExtMode,
@@ -406,7 +409,7 @@ void ScreenInteractive::Loop(Component* component) {
event.mouse().y -= cursor_y_;
}
event.SetScreen(this);
event.screen_ = this;
component->OnEvent(event);
}

View File

@@ -1,10 +1,18 @@
#include "ftxui/component/slider.hpp"
#include <memory>
#include <utility>
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/mouse.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/dom/elements.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/color.hpp"
namespace ftxui {
template<class T>
template <class T>
class SliderImpl : public Component {
public:
SliderImpl(std::wstring label, T* value, T min, T max, T increment)
@@ -55,7 +63,7 @@ class SliderImpl : public Component {
}
if (box_.Contain(event.mouse().x, event.mouse().y) &&
event.screen()->CaptureMouse()) {
CaptureMouse(event)) {
TakeFocus();
}
@@ -63,7 +71,7 @@ class SliderImpl : public Component {
event.mouse().motion == Mouse::Pressed &&
gauge_box_.Contain(event.mouse().x, event.mouse().y) &&
!captured_mouse_) {
captured_mouse_ = event.screen()->CaptureMouse();
captured_mouse_ = CaptureMouse(event);
}
if (captured_mouse_) {
@@ -105,3 +113,7 @@ template ComponentPtr Slider(std::wstring label,
float increment);
} // namespace ftxui
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.

View File

@@ -1,5 +1,8 @@
#include "ftxui/component/terminal_input_parser.hpp"
#include <utility>
#include "ftxui/component/event.hpp"
namespace ftxui {
TerminalInputParser::TerminalInputParser(Sender<Event> out)
@@ -61,7 +64,6 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
return;
}
// NOT_REACHED().
}
TerminalInputParser::Output TerminalInputParser::Parse() {
@@ -227,3 +229,7 @@ TerminalInputParser::Output TerminalInputParser::ParseCursorReporting(
}
} // namespace ftxui
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.

View File

@@ -1,10 +1,13 @@
#ifndef FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
#define FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
#include "ftxui/component/event.hpp"
#include "ftxui/component/receiver.hpp"
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
#include <string>
#include "ftxui/component/event.hpp" // IWYU pragma: keep
#include "ftxui/component/mouse.hpp" // for Mouse
#include "ftxui/component/receiver.hpp" // for SenderImpl
namespace ftxui {

View File

@@ -1,7 +1,9 @@
#include "ftxui/component/terminal_input_parser.hpp"
#include "ftxui/component/receiver.hpp"
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult
#include "gtest/gtest.h"
#include "ftxui/component/receiver.hpp" // for MakeReceiver, ReceiverImpl
#include "ftxui/component/terminal_input_parser.hpp"
#include "gtest/gtest_pred_impl.h" // for AssertionResult, Test, Suite...
using namespace ftxui;

View File

@@ -1,7 +1,12 @@
#include "ftxui/component/toggle.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include <stddef.h> // for size_t
#include <algorithm> // for max, min
#include <memory> // for shared_ptr, alloca...
#include <utility> // for move
#include <algorithm>
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/component/toggle.hpp"
namespace ftxui {
@@ -60,7 +65,7 @@ bool Toggle::OnEvent(Event event) {
}
bool Toggle::OnMouseEvent(Event event) {
if (!event.screen()->CaptureMouse())
if (!CaptureMouse(event))
return false;
for (int i = 0; i < boxes_.size(); ++i) {
if (!boxes_[i].Contain(event.mouse().x, event.mouse().y))

View File

@@ -1,6 +1,10 @@
#include "ftxui/component/toggle.hpp"
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver, TestFactoryImpl
#include "gtest/gtest.h"
#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Return, Event::Tab, Event::TabReverse
#include "ftxui/component/mouse.hpp" // for ftxui
#include "ftxui/component/toggle.hpp"
#include "gtest/gtest_pred_impl.h" // for AssertionResult, EXPECT_EQ, Test, EXPECT_TRUE, EXPECT_FALSE, TEST
using namespace ftxui;