Set clang-format macro indent.

1) Set clang-format macro indent.
2) Run clang-format on every files.
This commit is contained in:
ArthurSonzogni 2020-03-23 21:26:00 +01:00
parent 9e71c467f6
commit 493e734680
30 changed files with 110 additions and 104 deletions

View File

@ -2,3 +2,4 @@
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html # http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Chromium BasedOnStyle: Chromium
Standard: Cpp11 Standard: Cpp11
IndentPPDirectives: BeforeHash

View File

@ -1,9 +1,10 @@
#ifndef FTXUI_COMPONENT_CHECKBOX_HPP #ifndef FTXUI_COMPONENT_CHECKBOX_HPP
#define FTXUI_COMPONENT_CHECKBOX_HPP #define FTXUI_COMPONENT_CHECKBOX_HPP
#include "ftxui/component/component.hpp"
#include <functional> #include <functional>
#include "ftxui/component/component.hpp"
namespace ftxui { namespace ftxui {
class CheckBox : public Component { class CheckBox : public Component {
@ -15,8 +16,8 @@ class CheckBox : public Component {
bool state = false; bool state = false;
std::wstring label = L"label"; std::wstring label = L"label";
//std::wstring checked = L"[X] "; // std::wstring checked = L"[X] ";
//std::wstring unchecked = L"[ ] "; // std::wstring unchecked = L"[ ] ";
std::wstring checked = L""; std::wstring checked = L"";
std::wstring unchecked = L""; std::wstring unchecked = L"";
@ -24,7 +25,7 @@ class CheckBox : public Component {
Decorator unfocused_style = nothing; Decorator unfocused_style = nothing;
// State update callback. // State update callback.
std::function<void()> on_change = [](){}; std::function<void()> on_change = []() {};
// Component implementation. // Component implementation.
Element Render() override; Element Render() override;

View File

@ -11,7 +11,6 @@ class Focus;
class Component { class Component {
public: public:
// Constructor/Destructor. // Constructor/Destructor.
Component() = default; Component() = default;
virtual ~Component(); virtual ~Component();

View File

@ -1,9 +1,10 @@
#ifndef FTXUI_COMPONENT_INPUT_H_ #ifndef FTXUI_COMPONENT_INPUT_H_
#define FTXUI_COMPONENT_INPUT_H_ #define FTXUI_COMPONENT_INPUT_H_
#include "ftxui/component/component.hpp"
#include <functional> #include <functional>
#include "ftxui/component/component.hpp"
namespace ftxui { namespace ftxui {
class Input : public Component { class Input : public Component {
@ -17,8 +18,8 @@ class Input : public Component {
std::wstring placeholder; std::wstring placeholder;
// State update callback. // State update callback.
std::function<void()> on_change = [](){}; std::function<void()> on_change = []() {};
std::function<void()> on_enter = [](){}; std::function<void()> on_enter = []() {};
// Component implementation. // Component implementation.
Element Render() override; Element Render() override;

View File

@ -1,9 +1,10 @@
#ifndef FTXUI_COMPONENT_MENU #ifndef FTXUI_COMPONENT_MENU
#define FTXUI_COMPONENT_MENU #define FTXUI_COMPONENT_MENU
#include <functional>
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <functional>
namespace ftxui { namespace ftxui {
@ -22,14 +23,14 @@ class Menu : public Component {
Decorator normal_style = nothing; Decorator normal_style = nothing;
// State update callback. // State update callback.
std::function<void()> on_change = [](){}; std::function<void()> on_change = []() {};
std::function<void()> on_enter = [](){}; std::function<void()> on_enter = []() {};
// Component implementation. // Component implementation.
Element Render() override; Element Render() override;
bool OnEvent(Event) override; bool OnEvent(Event) override;
}; };
} // namespace ftxui::Component } // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_MENU */ #endif /* end of include guard: FTXUI_COMPONENT_MENU */

View File

@ -1,9 +1,10 @@
#ifndef FTXUI_COMPONENT_RADIOBOX_HPP #ifndef FTXUI_COMPONENT_RADIOBOX_HPP
#define FTXUI_COMPONENT_RADIOBOX_HPP #define FTXUI_COMPONENT_RADIOBOX_HPP
#include "ftxui/component/component.hpp"
#include <functional> #include <functional>
#include "ftxui/component/component.hpp"
namespace ftxui { namespace ftxui {
class RadioBox : public Component { class RadioBox : public Component {
@ -23,7 +24,7 @@ class RadioBox : public Component {
Decorator unfocused_style = nothing; Decorator unfocused_style = nothing;
// State update callback. // State update callback.
std::function<void()> on_change = [](){}; std::function<void()> on_change = []() {};
// Component implementation. // Component implementation.
Element Render() override; Element Render() override;

View File

@ -1,12 +1,12 @@
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP #ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP #define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#include <atomic>
#include <condition_variable> #include <condition_variable>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <queue> #include <queue>
#include <atomic>
#include "ftxui/component/event.hpp" #include "ftxui/component/event.hpp"
#include "ftxui/screen/screen.hpp" #include "ftxui/screen/screen.hpp"
@ -15,38 +15,38 @@ namespace ftxui {
class Component; class Component;
class ScreenInteractive : public Screen { class ScreenInteractive : public Screen {
public: public:
static ScreenInteractive FixedSize(int dimx, int dimy); static ScreenInteractive FixedSize(int dimx, int dimy);
static ScreenInteractive Fullscreen(); static ScreenInteractive Fullscreen();
static ScreenInteractive FitComponent(); static ScreenInteractive FitComponent();
static ScreenInteractive TerminalOutput(); static ScreenInteractive TerminalOutput();
~ScreenInteractive(); ~ScreenInteractive();
void Loop(Component*); void Loop(Component*);
std::function<void()> ExitLoopClosure(); std::function<void()> ExitLoopClosure();
void PostEvent(Event event); void PostEvent(Event event);
private: private:
void Draw(Component* component); void Draw(Component* component);
void EventLoop(Component* component); void EventLoop(Component* component);
enum class Dimension { enum class Dimension {
FitComponent, FitComponent,
Fixed, Fixed,
Fullscreen, Fullscreen,
TerminalOutput, TerminalOutput,
}; };
Dimension dimension_ = Dimension::Fixed; Dimension dimension_ = Dimension::Fixed;
ScreenInteractive(int dimx, int dimy, Dimension dimension); ScreenInteractive(int dimx, int dimy, Dimension dimension);
std::condition_variable events_queue_cv; std::condition_variable events_queue_cv;
std::mutex events_queue_mutex; std::mutex events_queue_mutex;
std::queue<Event> events_queue; std::queue<Event> events_queue;
std::atomic<bool> quit_ = false; std::atomic<bool> quit_ = false;
std::string set_cursor_position; std::string set_cursor_position;
std::string reset_cursor_position; std::string reset_cursor_position;
}; };
} // namespace ftxui } // namespace ftxui

View File

@ -1,10 +1,11 @@
#ifndef FTXUI_COMPONENT_TOGGLE_H_ #ifndef FTXUI_COMPONENT_TOGGLE_H_
#define FTXUI_COMPONENT_TOGGLE_H_ #define FTXUI_COMPONENT_TOGGLE_H_
#include "ftxui/component/component.hpp"
#include <functional> #include <functional>
#include <string> #include <string>
#include "ftxui/component/component.hpp"
namespace ftxui { namespace ftxui {
class Toggle : public Component { class Toggle : public Component {
@ -21,13 +22,13 @@ class Toggle : public Component {
Decorator normal_style = dim; Decorator normal_style = dim;
// Callback. // Callback.
std::function<void()> on_change = [](){}; std::function<void()> on_change = []() {};
// Component implementation. // Component implementation.
Element Render() override; Element Render() override;
bool OnEvent(Event) override; bool OnEvent(Event) override;
}; };
} // namespace ftxui::Component } // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */ #endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */

View File

@ -29,7 +29,8 @@ class Node {
// Step 3: Draw this element. // Step 3: Draw this element.
virtual void Render(Screen& screen); virtual void Render(Screen& screen);
std::vector<std::unique_ptr<Node>> children; std::vector<std::unique_ptr<Node>> children;
protected: protected:
Requirement requirement_; Requirement requirement_;
Box box_; Box box_;

View File

@ -7,10 +7,16 @@ namespace ftxui {
struct Requirement { struct Requirement {
// The required size to fully draw the element. // The required size to fully draw the element.
struct { int x = 0; int y = 0; } min; struct {
int x = 0;
int y = 0;
} min;
// How much flexibility is given to the component. // How much flexibility is given to the component.
struct { int x = 0; int y = 0; } flex; struct {
int x = 0;
int y = 0;
} flex;
// Frame. // Frame.
enum Selection { enum Selection {
@ -21,6 +27,6 @@ struct Requirement {
Box selected_box; Box selected_box;
}; };
} // namespace ftxui } // namespace ftxui
#endif /* end of include guard: FTXUI_REQUIREMENT_HPP */ #endif /* end of include guard: FTXUI_REQUIREMENT_HPP */

View File

@ -10,7 +10,7 @@ inline void Merge(Elements& container, Element element) {
template <> template <>
inline void Merge(Elements& container, Elements elements) { inline void Merge(Elements& container, Elements elements) {
for(auto& element : elements) for (auto& element : elements)
container.push_back(std::move(element)); container.push_back(std::move(element));
} }
@ -23,8 +23,8 @@ Elements unpack(Args... args) {
} }
// Make |container| able to take any number of argments. // Make |container| able to take any number of argments.
#define TAKE_ANY_ARGS(container) \ #define TAKE_ANY_ARGS(container) \
template <class... Args> \ template <class... Args> \
Element container(Args... children) { \ Element container(Args... children) { \
return container(unpack(std::forward<Args>(children)...)); \ return container(unpack(std::forward<Args>(children)...)); \
} }

View File

@ -35,6 +35,6 @@ enum class Color : uint8_t {
YellowLight = 93, YellowLight = 93,
}; };
} // namespace ftxui } // namespace ftxui
#endif /* end of include guard: FTXUI_COLOR_H_ */ #endif /* end of include guard: FTXUI_COLOR_H_ */

View File

@ -1,15 +1,15 @@
#ifndef FTXUI_SCREEN_SCREEN #ifndef FTXUI_SCREEN_SCREEN
#define FTXUI_SCREEN_SCREEN #define FTXUI_SCREEN_SCREEN
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include "ftxui/screen/color.hpp"
#include "ftxui/screen/box.hpp" #include "ftxui/screen/box.hpp"
#include "ftxui/screen/color.hpp"
namespace ftxui { namespace ftxui {
class Node; class Node;
} }
namespace ftxui { namespace ftxui {
@ -49,8 +49,8 @@ class Screen {
std::string ToString(); std::string ToString();
// Get screen dimensions. // Get screen dimensions.
int dimx() { return dimx_;} int dimx() { return dimx_; }
int dimy() { return dimy_;} int dimy() { return dimy_; }
// Move the terminal cursor n-lines up with n = dimy(). // Move the terminal cursor n-lines up with n = dimy().
std::string ResetPosition(); std::string ResetPosition();

View File

@ -6,7 +6,7 @@
std::string to_string(const std::wstring& s); std::string to_string(const std::wstring& s);
std::wstring to_wstring(const std::string& s); std::wstring to_wstring(const std::string& s);
template<typename T> template <typename T>
std::wstring to_wstring(T s) { std::wstring to_wstring(T s) {
return to_wstring(std::to_string(s)); return to_wstring(std::to_string(s));
} }

View File

@ -3,20 +3,20 @@
namespace ftxui { namespace ftxui {
template<typename T> template <typename T>
class AutoReset { class AutoReset {
public: public:
AutoReset(T* variable, T new_value) AutoReset(T* variable, T new_value)
: variable_(variable), : variable_(variable), previous_value_(std::move(*variable)) {
previous_value_(std::move(*variable)) {
*variable_ = std::move(new_value); *variable_ = std::move(new_value);
} }
~AutoReset() { *variable_ = std::move(previous_value_); } ~AutoReset() { *variable_ = std::move(previous_value_); }
private: private:
T* variable_; T* variable_;
T previous_value_; T previous_value_;
}; };
} // namespace ftxui } // namespace ftxui
#endif /* end of include guard: FTXUI_UTIL_AUTORESET_HPP */ #endif /* end of include guard: FTXUI_UTIL_AUTORESET_HPP */

View File

@ -1,7 +1,9 @@
#include "ftxui/component/input.hpp" #include "ftxui/component/input.hpp"
#include "ftxui/screen/string.hpp"
#include <algorithm> #include <algorithm>
#include "ftxui/screen/string.hpp"
namespace ftxui { namespace ftxui {
// Component implementation. // Component implementation.
@ -22,15 +24,14 @@ Element Input::Render() {
if (!is_focused) if (!is_focused)
return text(content) | main_decorator; return text(content) | main_decorator;
std::wstring part_before_cursor = content.substr(0,cursor_position); std::wstring part_before_cursor = content.substr(0, cursor_position);
std::wstring part_at_cursor = cursor_position < (int)content.size() std::wstring part_at_cursor = cursor_position < (int)content.size()
? content.substr(cursor_position, 1) ? content.substr(cursor_position, 1)
: L" "; : L" ";
std::wstring part_after_cursor = cursor_position < (int)content.size() - 1 std::wstring part_after_cursor = cursor_position < (int)content.size() - 1
? content.substr(cursor_position + 1) ? content.substr(cursor_position + 1)
: L""; : L"";
auto focused = auto focused = is_focused ? focus : select;
is_focused ? focus : select;
// clang-format off // clang-format off
return return

View File

@ -1,7 +1,7 @@
#include "ftxui/component/menu.hpp" #include "ftxui/component/menu.hpp"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <algorithm>
namespace ftxui { namespace ftxui {

View File

@ -1,6 +1,7 @@
#include "ftxui/component/radiobox.hpp" #include "ftxui/component/radiobox.hpp"
#include <functional>
#include <algorithm> #include <algorithm>
#include <functional>
namespace ftxui { namespace ftxui {
@ -41,7 +42,7 @@ bool RadioBox::OnEvent(Event event) {
return true; return true;
} }
if (event == Event::Character(' ') || event==Event::Return) { if (event == Event::Character(' ') || event == Event::Return) {
selected = focused; selected = focused;
on_change(); on_change();
} }

View File

@ -3,18 +3,20 @@
#include <stdio.h> #include <stdio.h>
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
#include <algorithm>
#include <csignal> #include <csignal>
#include <iostream> #include <iostream>
#include <stack> #include <stack>
#include <thread> #include <thread>
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp" #include "ftxui/screen/terminal.hpp"
#include <algorithm>
#if defined(__clang__) && defined (__APPLE__) #if defined(__clang__) && defined(__APPLE__)
// Quick exit is missing in standard CLang headers // Quick exit is missing in standard CLang headers
#define quick_exit(a) exit(a) #define quick_exit(a) exit(a)
#endif #endif
namespace ftxui { namespace ftxui {
@ -42,14 +44,12 @@ auto install_signal_handler = [](int sig, SignalHandler handler) {
on_exit_functions.push([&]() { std::signal(sig, old_signal_handler); }); on_exit_functions.push([&]() { std::signal(sig, old_signal_handler); });
}; };
std::function<void()> on_resize = []{}; std::function<void()> on_resize = [] {};
void OnResize(int /* signal */) { void OnResize(int /* signal */) {
on_resize(); on_resize();
} }
ScreenInteractive::ScreenInteractive(int dimx, ScreenInteractive::ScreenInteractive(int dimx, int dimy, Dimension dimension)
int dimy,
Dimension dimension)
: Screen(dimx, dimy), dimension_(dimension) {} : Screen(dimx, dimy), dimension_(dimension) {}
ScreenInteractive::~ScreenInteractive() {} ScreenInteractive::~ScreenInteractive() {}
@ -176,8 +176,7 @@ void ScreenInteractive::Draw(Component* component) {
if (dimx != dimx_ || dimy != dimy_) { if (dimx != dimx_ || dimy != dimy_) {
dimx_ = dimx; dimx_ = dimx;
dimy_ = dimy; dimy_ = dimy;
pixels_ = std::vector<std::vector<Pixel>>( pixels_ = std::vector<std::vector<Pixel>>(dimy, std::vector<Pixel>(dimx));
dimy, std::vector<Pixel>(dimx));
cursor_.x = dimx_ - 1; cursor_.x = dimx_ - 1;
cursor_.y = dimy_ - 1; cursor_.y = dimy_ - 1;
} }
@ -196,7 +195,7 @@ void ScreenInteractive::Draw(Component* component) {
reset_cursor_position += "\x1B[" + std::to_string(dx) + "C"; reset_cursor_position += "\x1B[" + std::to_string(dx) + "C";
} }
if (dy != 0) { if (dy != 0) {
set_cursor_position += "\x1B[" + std::to_string(dy) + "A"; set_cursor_position += "\x1B[" + std::to_string(dy) + "A";
reset_cursor_position += "\x1B[" + std::to_string(dy) + "B"; reset_cursor_position += "\x1B[" + std::to_string(dy) + "B";
} }
} }

View File

@ -1,4 +1,5 @@
#include "ftxui/component/toggle.hpp" #include "ftxui/component/toggle.hpp"
#include <algorithm> #include <algorithm>
namespace ftxui { namespace ftxui {

View File

@ -1,8 +1,8 @@
#include <algorithm>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
using namespace ftxui; using namespace ftxui;

View File

@ -1,8 +1,8 @@
#include <algorithm>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
class DBox : public Node { class DBox : public Node {

View File

@ -4,8 +4,6 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/util/autoreset.hpp" #include "ftxui/util/autoreset.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
using namespace ftxui; using namespace ftxui;

View File

@ -3,8 +3,6 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
class HBox : public Node { class HBox : public Node {

View File

@ -1,8 +1,8 @@
#include <algorithm>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
class HFlow : public Node { class HFlow : public Node {

View File

@ -3,8 +3,6 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
class Size : public Node { class Size : public Node {

View File

@ -3,8 +3,6 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
class VBox : public Node { class VBox : public Node {

View File

@ -7,7 +7,6 @@
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp" #include "ftxui/screen/terminal.hpp"
namespace ftxui { namespace ftxui {
namespace { namespace {

View File

@ -3,12 +3,12 @@
#include <stdio.h> #include <stdio.h>
#ifdef WIN32 #ifdef WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
#else #else
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <iostream> #include <iostream>

View File

@ -59,9 +59,10 @@
* Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
*/ */
#include "ftxui/screen/string.hpp"
#include <wchar.h> #include <wchar.h>
#include "ftxui/screen/string.hpp"
namespace { namespace {
struct interval { struct interval {
int first; int first;