Run clang-format.

This commit is contained in:
ArthurSonzogni 2020-03-27 01:42:46 +01:00
parent 1703552235
commit fce29a03b3
21 changed files with 104 additions and 151 deletions

View File

@ -10,7 +10,6 @@
#include "ftxui/component/toggle.hpp" #include "ftxui/component/toggle.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
using namespace ftxui; using namespace ftxui;
int shift = 0; int shift = 0;

View File

@ -9,55 +9,50 @@
using namespace ftxui; using namespace ftxui;
class MyComponent : public Component { class MyComponent : public Component {
public: public:
MyComponent() { MyComponent() {
Add(&container_); Add(&container_);
container_.Add(&menu_); container_.Add(&menu_);
menu_.entries = { menu_.entries = {
L"menu_1", L"menu_1",
L"menu_2", L"menu_2",
L"menu_3", L"menu_3",
}; };
container_.Add(&tab_container_); container_.Add(&tab_container_);
menu_1_.entries = {
L"Forest",
L"Water",
L"I don't know"
};
tab_container_.Add(&menu_1_);
menu_2_.entries = { menu_1_.entries = {L"Forest", L"Water", L"I don't know"};
L"Hello", tab_container_.Add(&menu_1_);
L"Hi",
L"Hay",
};
tab_container_.Add(&menu_2_);
menu_3_.entries = { menu_2_.entries = {
L"Table", L"Hello",
L"Nothing", L"Hi",
L"Is", L"Hay",
L"Empty", };
}; tab_container_.Add(&menu_2_);
tab_container_.Add(&menu_3_);
}
std::function<void()> on_enter = [](){}; menu_3_.entries = {
private: L"Table",
Menu menu_; L"Nothing",
Container container_ = Container::Horizontal(); L"Is",
Container tab_container_ = Container::Tab(&(menu_.selected)); L"Empty",
Menu menu_1_; };
Menu menu_2_; tab_container_.Add(&menu_3_);
Menu menu_3_; }
std::function<void()> on_enter = []() {};
private:
Menu menu_;
Container container_ = Container::Horizontal();
Container tab_container_ = Container::Tab(&(menu_.selected));
Menu menu_1_;
Menu menu_2_;
Menu menu_3_;
}; };
int main(int argc, const char* argv[]) {
int main(int argc, const char *argv[])
{
auto screen = ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component; MyComponent component;
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();

View File

@ -5,7 +5,6 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp" #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
using namespace std::chrono_literals; using namespace std::chrono_literals;

View File

@ -7,7 +7,6 @@
#include "ftxui/screen/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
class Graph { class Graph {
public: public:
std::vector<int> operator()(int width, int height) { std::vector<int> operator()(int width, int height) {

View File

@ -2,21 +2,20 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{
using namespace ftxui; using namespace ftxui;
using namespace std::chrono_literals; using namespace std::chrono_literals;
std::string reset_position; std::string reset_position;
for(int index = 0; index < 200; ++index) { for (int index = 0; index < 200; ++index) {
std::vector<Element> entries; std::vector<Element> entries;
for(int i = 0; i<22; ++i) { for (int i = 0; i < 22; ++i) {
if (i != 0) if (i != 0)
entries.push_back(separator()); entries.push_back(separator());
// clang-format off // clang-format off
entries.push_back( entries.push_back(
hbox( hbox(

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off // clang-format off
auto document = auto document =

View File

@ -1,9 +1,9 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off // clang-format off
auto document = auto document =

View File

@ -1,9 +1,9 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off // clang-format off
auto document = auto document =

View File

@ -1,9 +1,9 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off // clang-format off
auto document = auto document =

View File

@ -1,10 +1,9 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
#include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{
using namespace ftxui; using namespace ftxui;
// clang-format off // clang-format off
auto document = auto document =

View File

@ -16,14 +16,14 @@ class DrawKey : public Component {
Elements children; Elements children;
for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) { for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) {
std::wstring code; std::wstring code;
for(auto& it : keys[i].input()) for (auto& it : keys[i].input())
code += L" " + std::to_wstring((unsigned int)it); code += L" " + std::to_wstring((unsigned int)it);
code = L"(" + code + L" ) -> "; code = L"(" + code + L" ) -> ";
if (keys[i].is_character()) if (keys[i].is_character())
code += keys[i].character(); code += keys[i].character();
else else
code += L"(special)"; code += L"(special)";
children.push_back(text(code)); children.push_back(text(code));
} }
return vbox(std::move(children)); return vbox(std::move(children));

View File

@ -1,11 +1,10 @@
#ifndef FTXUI_COMPONENT_RECEIVER_HPP_ #ifndef FTXUI_COMPONENT_RECEIVER_HPP_
#define FTXUI_COMPONENT_RECEIVER_HPP_ #define FTXUI_COMPONENT_RECEIVER_HPP_
#include <iostream>
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <functional> #include <functional>
#include <iostream>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <queue> #include <queue>
@ -50,7 +49,7 @@ template <class T>
class SenderImpl { class SenderImpl {
public: public:
void Send(T t) { receiver_->Receive(std::move(t)); } void Send(T t) { receiver_->Receive(std::move(t)); }
~SenderImpl() { receiver_->ReleaseSender();} ~SenderImpl() { receiver_->ReleaseSender(); }
private: private:
friend class ReceiverImpl<T>; friend class ReceiverImpl<T>;

View File

@ -75,5 +75,4 @@ TEST(RadioboxTest, Navigation) {
radiobox.OnEvent(Event::TabReverse); radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 1); EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::TabReverse); radiobox.OnEvent(Event::TabReverse);
} }

View File

@ -58,10 +58,14 @@ TEST(Receiver, BasicWithThread) {
s1_bis.reset(); s1_bis.reset();
char c; char c;
EXPECT_TRUE(r3->Receive(&c));EXPECT_EQ(c, '1'); EXPECT_TRUE(r3->Receive(&c));
EXPECT_TRUE(r3->Receive(&c)); EXPECT_EQ(c, '2'); EXPECT_EQ(c, '1');
EXPECT_TRUE(r3->Receive(&c)); EXPECT_EQ(c, '3'); EXPECT_TRUE(r3->Receive(&c));
EXPECT_TRUE(r3->Receive(&c)); EXPECT_EQ(c, '4'); EXPECT_EQ(c, '2');
EXPECT_TRUE(r3->Receive(&c));
EXPECT_EQ(c, '3');
EXPECT_TRUE(r3->Receive(&c));
EXPECT_EQ(c, '4');
EXPECT_FALSE(r3->Receive(&c)); EXPECT_FALSE(r3->Receive(&c));
// Thread will end at the end of the stream. // Thread will end at the end of the stream.

View File

@ -70,5 +70,4 @@ TEST(ToggleTest, Tab) {
toggle.OnEvent(Event::TabReverse); toggle.OnEvent(Event::TabReverse);
EXPECT_EQ(toggle.selected, 1); EXPECT_EQ(toggle.selected, 1);
toggle.OnEvent(Event::TabReverse); toggle.OnEvent(Event::TabReverse);
} }

View File

@ -6,114 +6,79 @@ using namespace ftxui;
using namespace ftxui; using namespace ftxui;
TEST(HBoxTest, ScreenSmaller1) { TEST(HBoxTest, ScreenSmaller1) {
auto root = hbox( auto root = hbox(text(L"text_1"), text(L"text_2"));
text(L"text_1"), Screen screen(11, 1);
text(L"text_2")
);
Screen screen(11,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text_", screen.ToString()); EXPECT_EQ("text_1text_", screen.ToString());
} }
TEST(HBoxTest, ScreenSmaller2) { TEST(HBoxTest, ScreenSmaller2) {
auto root = hbox( auto root = hbox(text(L"text_1"), text(L"text_2"));
text(L"text_1"), Screen screen(10, 1);
text(L"text_2")
);
Screen screen(10,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text", screen.ToString()); EXPECT_EQ("text_1text", screen.ToString());
} }
TEST(HBoxTest, ScreenFit) { TEST(HBoxTest, ScreenFit) {
auto root = hbox( auto root = hbox(text(L"text_1"), text(L"text_2"));
text(L"text_1"), Screen screen(12, 1);
text(L"text_2")
);
Screen screen(12,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text_2", screen.ToString()); EXPECT_EQ("text_1text_2", screen.ToString());
} }
TEST(HBoxTest, ScreenBigger1) { TEST(HBoxTest, ScreenBigger1) {
auto root = hbox( auto root = hbox(text(L"text_1"), text(L"text_2"));
text(L"text_1"), Screen screen(13, 1);
text(L"text_2")
);
Screen screen(13,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text_2 ", screen.ToString()); EXPECT_EQ("text_1text_2 ", screen.ToString());
} }
TEST(HBoxTest, ScreenBigger2) { TEST(HBoxTest, ScreenBigger2) {
auto root = hbox( auto root = hbox(text(L"text_1"), text(L"text_2"));
text(L"text_1"), Screen screen(14, 1);
text(L"text_2")
);
Screen screen(14,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text_2 ", screen.ToString()); EXPECT_EQ("text_1text_2 ", screen.ToString());
} }
TEST(HBoxTest, ScreenSmaller1Flex) { TEST(HBoxTest, ScreenSmaller1Flex) {
auto root = hbox( auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
text(L"text_1"), Screen screen(11, 1);
filler(),
text(L"text_2")
);
Screen screen(11,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text_", screen.ToString()); EXPECT_EQ("text_1text_", screen.ToString());
} }
TEST(HBoxTest, ScreenSmaller2Flex) { TEST(HBoxTest, ScreenSmaller2Flex) {
auto root = hbox( auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
text(L"text_1"), Screen screen(10, 1);
filler(),
text(L"text_2")
);
Screen screen(10,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text", screen.ToString()); EXPECT_EQ("text_1text", screen.ToString());
} }
TEST(HBoxTest, ScreenFitFlex) { TEST(HBoxTest, ScreenFitFlex) {
auto root = hbox( auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
text(L"text_1"), Screen screen(12, 1);
filler(),
text(L"text_2")
);
Screen screen(12,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1text_2", screen.ToString()); EXPECT_EQ("text_1text_2", screen.ToString());
} }
TEST(HBoxTest, ScreenBigger1Flex) { TEST(HBoxTest, ScreenBigger1Flex) {
auto root = hbox( auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
text(L"text_1"), Screen screen(13, 1);
filler(),
text(L"text_2")
);
Screen screen(13,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1 text_2", screen.ToString()); EXPECT_EQ("text_1 text_2", screen.ToString());
} }
TEST(HBoxTest, ScreenBigger2Flex) { TEST(HBoxTest, ScreenBigger2Flex) {
auto root = hbox( auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
text(L"text_1"), Screen screen(14, 1);
filler(),
text(L"text_2")
);
Screen screen(14,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1 text_2", screen.ToString()); EXPECT_EQ("text_1 text_2", screen.ToString());

View File

@ -1,5 +1,5 @@
#include <iostream>
#include <algorithm> #include <algorithm>
#include <iostream>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"

View File

@ -50,12 +50,12 @@ TEST(VBoxTest, ScreenFitFlex) {
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ( EXPECT_EQ(
"text_1 \n" "text_1 \n"
" \n" " \n"
" \n" " \n"
" \n" " \n"
"text_2 " "text_2 ",
,screen.ToString()); screen.ToString());
} }
TEST(VBoxTest, ScreenBigger1Flex) { TEST(VBoxTest, ScreenBigger1Flex) {

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"
#if defined(_WIN32) #if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #define NOMINMAX

View File

@ -3,10 +3,9 @@
#include <codecvt> #include <codecvt>
#include <locale> #include <locale>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4996) // codecvt_utf8_utf16 is deprecated #pragma warning(disable : 4996) // codecvt_utf8_utf16 is deprecated
#endif #endif
std::string to_string(const std::wstring& s) { std::string to_string(const std::wstring& s) {
@ -20,5 +19,5 @@ std::wstring to_wstring(const std::string& s) {
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif

View File

@ -2,7 +2,6 @@
#include <stdio.h> #include <stdio.h>
#if defined(_WIN32) #if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #define NOMINMAX