Flatten the namespaces.

Remove:
* ftxui::screen
* ftxui::dom
* ftxui::component

Keep:
* ftxui
This commit is contained in:
Arthur Sonzogni 2019-01-12 15:00:08 +01:00
parent cf63aefa02
commit 21644eea6b
78 changed files with 219 additions and 274 deletions

View File

@ -7,8 +7,7 @@
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp"
using namespace ftxui::component;
using namespace ftxui::dom;
using namespace ftxui;
class MyComponent : ComponentVertical {
public:

View File

@ -6,8 +6,7 @@
#include "ftxui/component/screen_interactive.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui::component;
using namespace ftxui::screen;
using namespace ftxui;
auto screen = ScreenInteractive::FixedSize(30, 3);
Menu menu(screen.delegate());
menu.entries = {L"entry 1", L"entry 2", L"entry 3"};

View File

@ -8,8 +8,7 @@
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp"
using namespace ftxui::component;
using namespace ftxui::dom;
using namespace ftxui;
class MyComponent : ComponentHorizontal {
public:

View File

@ -6,8 +6,7 @@
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp"
using namespace ftxui::component;
using namespace ftxui::dom;
using namespace ftxui;
class MyComponent : ComponentHorizontal {
public:

View File

@ -7,8 +7,7 @@
#include "ftxui/component/toggle.hpp"
#include "ftxui/util/string.hpp"
using namespace ftxui::component;
using namespace ftxui::dom;
using namespace ftxui;
class MyComponent : ComponentVertical {
public:

View File

@ -8,8 +8,7 @@
#include "ftxui/component/toggle.hpp"
#include "ftxui/util/string.hpp"
using namespace ftxui::component;
using namespace ftxui::dom;
using namespace ftxui;
class MyComponent : ComponentVertical {
public:

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
hbox(
text(L"This text is "),

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
hbox(
text(L"This text is "),

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
hbox(
vbox(

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::dom;
using namespace ftxui::screen;
using namespace ftxui;
auto document =
dbox(
frame(

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
hbox(
text(L"This text is "),

View File

@ -7,8 +7,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::dom;
using namespace ftxui::screen;
using namespace ftxui;
auto document =
hbox(
window(text(L" main frame ") | hcenter,

View File

@ -7,8 +7,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::dom;
using namespace ftxui::screen;
using namespace ftxui;
using namespace std::chrono_literals;
std::string reset_position;

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
hbox(
text(L"This text is "),

View File

@ -10,8 +10,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
struct Task {
std::wstring name;

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::dom;
using namespace ftxui::screen;
using namespace ftxui;
auto document =
hbox(
text(L"left-column"),

View File

@ -9,8 +9,6 @@
int main(int argc, const char *argv[])
{
using namespace ftxui;
using namespace ftxui::dom;
using namespace ftxui::screen;
using namespace std::chrono_literals;
std::string reset_position;

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
hbox(
text(L"normal") , text(L" ") ,

View File

@ -4,8 +4,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
hbox(
text(L"This text is "),

View File

@ -5,8 +5,7 @@
int main(int argc, const char *argv[])
{
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
auto document =
vbox(
hbox(

View File

@ -6,15 +6,14 @@
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp"
using namespace ftxui::component;
using namespace ftxui;
class DrawKey : public Component {
public:
DrawKey(Delegate* delegate)
DrawKey(Component::Delegate* delegate)
: Component(delegate) {}
ftxui::dom::Element Render() override {
using namespace ftxui::dom;
Element Render() override {
Children children;
for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) {
std::string code = "";

View File

@ -1,27 +1,11 @@
cmake_minimum_required(VERSION 3.0)
####################
# ftxui::screen
####################
add_library(screen
src/ftxui/screen/screen.cpp
src/ftxui/terminal.cpp
src/ftxui/util/string.cpp
src/ftxui/screen/terminal.cpp
src/ftxui/screen/string.cpp
)
target_include_directories(screen
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE src
)
target_compile_features(screen PUBLIC cxx_std_17)
target_compile_options(screen PRIVATE -Wall)
####################
# ftxui::dom
####################
add_library(dom
src/ftxui/dom/blink.cpp
src/ftxui/dom/bold.cpp
@ -45,23 +29,6 @@ add_library(dom
src/ftxui/dom/vbox.cpp
)
target_include_directories(dom
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE src
)
target_link_libraries(dom
PUBLIC screen
)
target_compile_features(dom PUBLIC cxx_std_17)
target_compile_options(dom PRIVATE -Wall)
####################
# ftxui::component
####################
add_library(component
src/ftxui/component/component.cpp
src/ftxui/component/component_direction.cpp
@ -74,19 +41,20 @@ add_library(component
src/ftxui/component/toggle.cpp
)
target_include_directories(component
target_link_libraries(dom PUBLIC screen)
target_link_libraries(component PUBLIC dom)
foreach(lib screen dom component)
target_include_directories(${lib}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE src
)
target_link_libraries(component
PUBLIC dom
)
target_compile_features(component PUBLIC cxx_std_17)
target_compile_options(component PRIVATE -Wall)
target_compile_features(${lib} PUBLIC cxx_std_17)
target_compile_options(${lib} PRIVATE -Wall)
endforeach()
include(GNUInstallDirs)
install(TARGETS screen dom component

View File

@ -1,8 +1,8 @@
#
* Level 0: terminal output.
* Level 1: ftxui::Screen
* Level 2: ftxui::dom::Node
* Level 3: ftxui::component::Component
* Level 2: ftxui::Node
* Level 3: ftxui::Component
## Level 0: terminal output.
The terminal you know, you can append text on it. It is represented by
@ -12,16 +12,16 @@
A rectangular grid of characters.
Use Terminal::ToString() to append its content into the console.
## Level 2: ftxui::dom::Node
## Level 2: ftxui::Node
A hierarchical set of element.
They handle layout and Render themself on the screen.
See ftxui/dom/elements.hpp
You can make implement your own.
## Level 3: ftxui::component::Component
## Level 3: ftxui::Component
A hierarchical set of component. A component render itself by producing
ftxui::dom::Node in Component::Render().
ftxui::Node in Component::Render().
Some component can handle events:
* keyboard

View File

@ -5,19 +5,40 @@
#include "ftxui/component/event.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::component {
namespace ftxui {
class Delegate;
class Focus;
class Component {
public:
class Delegate {
public:
Delegate() {}
virtual ~Delegate() {}
// A Delegate shadows a component.
virtual void Register(Component* component) = 0;
virtual Component* component() = 0;
// Create new children.
virtual Delegate* NewChild() = 0;
virtual std::vector<Delegate*> children() = 0;
// Navigate in the tree.
virtual Delegate* PreviousSibling() = 0;
virtual Delegate* NextSibling() = 0;
virtual Delegate* Parent() = 0;
virtual Delegate* Root() = 0;
};
// Constructor/Destructor.
Component(Delegate* delegate);
virtual ~Component();
// Render the component.
virtual dom::Element Render();
virtual Element Render();
// Handle an event. By default, it calls this function on each children.
virtual bool OnEvent(Event even);
@ -38,6 +59,6 @@ class Component {
Delegate* delegate_;
};
} // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */

View File

@ -4,7 +4,6 @@
#include "ftxui/component/component.hpp"
namespace ftxui {
namespace component {
// A component where focus and events are automatically handled for you.
// Please use ComponentVertical or ComponentHorizontal.
@ -20,7 +19,6 @@ class ComponentDirection : public Component {
Component* active_child_;
};
} // namespace component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_DIRECTION_H_ */

View File

@ -3,7 +3,7 @@
#include "ftxui/component/component_direction.hpp"
namespace ftxui::component {
namespace ftxui {
// A component where focus and events are automatically handled for you.
// It assumes its children are put in the horizontal direction.
@ -13,6 +13,6 @@ class ComponentHorizontal : public ComponentDirection {
bool HandleDirection(Event) override;
};
} // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */

View File

@ -3,7 +3,7 @@
#include "ftxui/component/component_direction.hpp"
namespace ftxui::component {
namespace ftxui {
// A component where focus and events are automatically handled for you.
// It assumes its children are put in the vertical direction.
@ -13,6 +13,6 @@ class ComponentVertical : public ComponentDirection {
bool HandleDirection(Event) override;
};
} // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */

View File

@ -3,30 +3,11 @@
#include "ftxui/dom/elements.hpp"
namespace ftxui::component {
namespace ftxui {
class Component;
class Delegate {
public:
Delegate() {}
virtual ~Delegate() {}
// A Delegate shadows a component.
virtual void Register(Component* component) = 0;
virtual Component* component() = 0;
// Create new children.
virtual Delegate* NewChild() = 0;
virtual std::vector<Delegate*> children() = 0;
// Navigate in the tree.
virtual Delegate* PreviousSibling() = 0;
virtual Delegate* NextSibling() = 0;
virtual Delegate* Parent() = 0;
virtual Delegate* Root() = 0;
};
} // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */

View File

@ -4,7 +4,7 @@
#include <vector>
#include <array>
namespace ftxui::component {
namespace ftxui {
struct Event{
public:
@ -31,7 +31,7 @@ struct Event{
};
} // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */

View File

@ -4,7 +4,7 @@
#include "ftxui/component/component.hpp"
#include <functional>
namespace ftxui::component {
namespace ftxui {
class Input : public Component {
public:
@ -21,13 +21,13 @@ class Input : public Component {
std::function<void()> on_enter = [](){};
// Component implementation.
dom::Element Render() override;
Element Render() override;
bool OnEvent(Event) override;
private:
int cursor_position = 0;
};
} // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */

View File

@ -5,7 +5,7 @@
#include "ftxui/dom/elements.hpp"
#include <functional>
namespace ftxui::component {
namespace ftxui {
class Menu : public Component {
public:
@ -16,16 +16,16 @@ class Menu : public Component {
std::vector<std::wstring> entries = {};
int selected = 0;
dom::Decorator active_style = dom::inverted;
dom::Decorator selected_style = dom::bold;
dom::Decorator normal_style = dom::nothing;
Decorator active_style = inverted;
Decorator selected_style = bold;
Decorator normal_style = nothing;
// State update callback.
std::function<void()> on_change = [](){};
std::function<void()> on_enter = [](){};
// Component implementation.
dom::Element Render() override;
Element Render() override;
bool OnEvent(Event) override;
};

View File

@ -1,26 +1,26 @@
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#include "ftxui/component/component.hpp"
#include "ftxui/screen/screen.hpp"
#include <functional>
#include <memory>
namespace ftxui::component {
namespace ftxui {
class Delegate;
class Component;
class ScreenInteractive : public ftxui::screen::Screen {
class ScreenInteractive : public ftxui::Screen {
public:
static ScreenInteractive FixedSize(size_t dimx, size_t dimy);
static ScreenInteractive Fullscreen();
static ScreenInteractive TerminalOutput();
~ScreenInteractive();
component::Delegate* delegate();
void Loop();
std::function<void()> ExitLoopClosure();
Component::Delegate* delegate();
private:
class Delegate;
std::unique_ptr<Delegate> delegate_;
@ -38,6 +38,6 @@ class ScreenInteractive : public ftxui::screen::Screen {
ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension);
};
} // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */

View File

@ -5,7 +5,7 @@
#include <functional>
#include <string>
namespace ftxui::component {
namespace ftxui {
class Toggle : public Component {
public:
@ -20,7 +20,7 @@ class Toggle : public Component {
std::function<void()> on_change = [](){};
// Component implementation.
dom::Element Render() override;
Element Render() override;
bool OnEvent(Event) override;
};

View File

@ -1,7 +1,7 @@
#ifndef FTXUI_DOM_BOX_HPP
#define FTXUI_DOM_BOX_HPP
namespace ftxui::dom {
namespace ftxui {
struct Box {
int left;
@ -10,6 +10,6 @@ struct Box {
int bottom;
};
}; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_BOX_HPP */

View File

@ -6,13 +6,13 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/color.hpp"
namespace ftxui::dom {
namespace ftxui {
using Element = std::unique_ptr<Node>;
using Decorator = std::function<Element(Element)>;
using Child = std::unique_ptr<Node>;
using Children = std::vector<Child>;
using Color = ftxui::screen::Color;
using Color = ftxui::Color;
// --- Layout ----
Element vbox(Children);
@ -64,6 +64,6 @@ TAKE_ANY_ARGS(vbox)
TAKE_ANY_ARGS(hbox)
TAKE_ANY_ARGS(dbox)
}; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */

View File

@ -8,7 +8,7 @@
#include "ftxui/dom/requirement.hpp"
#include "ftxui/screen/screen.hpp"
namespace ftxui::dom {
namespace ftxui {
class Node {
public:
@ -27,7 +27,7 @@ class Node {
virtual void SetBox(Box box);
// Step 3: Draw this element.
virtual void Render(screen::Screen& screen);
virtual void Render(Screen& screen);
std::vector<std::unique_ptr<Node>> children;
protected:
@ -35,8 +35,8 @@ class Node {
Box box_;
};
void Render(screen::Screen& screen, Node* node);
void Render(Screen& screen, Node* node);
}; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_NODE_HPP */

View File

@ -1,7 +1,7 @@
#ifndef FTXUI_DOM_REQUIREMENT_HPP
#define FTXUI_DOM_REQUIREMENT_HPP
namespace ftxui::dom {
namespace ftxui {
struct Requirement {
// The required size to fully draw the element.
@ -11,6 +11,6 @@ struct Requirement {
struct { int x = 0; int y = 0; } flex;
};
}; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: FTXUI_REQUIREMENT_HPP */

View File

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

View File

@ -7,11 +7,11 @@
#include "ftxui/screen/color.hpp"
namespace ftxui::dom {
namespace ftxui {
class Node;
}
namespace ftxui::screen {
namespace ftxui {
struct Pixel {
wchar_t character = U' ';
@ -31,9 +31,9 @@ class Screen {
// Constructor using the terminal.
static Screen TerminalFullscreen();
static Screen TerminalOutput(std::unique_ptr<dom::Node>& element);
static Screen TerminalOutput(std::unique_ptr<Node>& element);
// dom::Node write into the screen using Screen::at.
// Node write into the screen using Screen::at.
wchar_t& at(size_t x, size_t y);
Pixel& PixelAt(size_t x, size_t y);
@ -56,6 +56,6 @@ class Screen {
std::vector<std::vector<Pixel>> pixels_;
};
}; // namespace ftxui::screen
}; // namespace ftxui
#endif /* end of include guard: FTXUI_SCREEN_SCREEN */

View File

@ -2,7 +2,7 @@
#include "ftxui/component/delegate.hpp"
#include <assert.h>
namespace ftxui::component {
namespace ftxui {
Component::Component(Delegate* delegate) {
delegate_ = delegate;
@ -11,8 +11,8 @@ Component::Component(Delegate* delegate) {
Component::~Component() {}
dom::Element Component::Render() {
using namespace ftxui::dom;
Element Component::Render() {
using namespace ftxui;
return text(L"Not implemented component");
}
@ -54,4 +54,4 @@ Component* Component::Parent() {
return parent_delegate->component();
}
} // namespace ftxui::component
} // namespace ftxui

View File

@ -1,6 +1,6 @@
#include "ftxui/component/component_direction.hpp"
namespace ftxui::component {
namespace ftxui {
ComponentDirection::ComponentDirection(Delegate* delegate)
: Component(delegate), active_child_(nullptr) {}
@ -16,6 +16,7 @@ bool ComponentDirection::OnEvent(Event event) {
return true;
return HandleDirection(event);
}
Component* ComponentDirection::GetActiveChild() {

View File

@ -1,6 +1,6 @@
#include "ftxui/component/component_horizontal.hpp"
namespace ftxui::component {
namespace ftxui {
ComponentHorizontal::ComponentHorizontal(Delegate* delegate)
: ComponentDirection(delegate) {}
@ -27,4 +27,4 @@ bool ComponentHorizontal::HandleDirection(Event event) {
return false;
}
} // namespace ftxui::component
} // namespace ftxui

View File

@ -1,6 +1,6 @@
#include "ftxui/component/component_vertical.hpp"
namespace ftxui::component {
namespace ftxui {
ComponentVertical::ComponentVertical(Delegate* delegate)
: ComponentDirection(delegate) {}
@ -27,4 +27,4 @@ bool ComponentVertical::HandleDirection(Event event) {
return false;
}
} // namespace ftxui::component
} // namespace ftxui

View File

@ -1,6 +1,6 @@
#include "ftxui/component/event.hpp"
namespace ftxui::component {
namespace ftxui {
constexpr int ESC = int(27);
@ -34,4 +34,4 @@ Event Event::F10{ESC, '[', '2', '1', '~'};
Event Event::F11{ESC, '[', '2', '1', '~'}; // Same as F10 ?
Event Event::F12{ESC, '[', '2', '4', '~'};
} // namespace ftxui::component
} // namespace ftxui

View File

@ -1,14 +1,13 @@
#include "ftxui/component/input.hpp"
#include "ftxui/util/string.hpp"
namespace ftxui::component {
namespace ftxui {
Input::Input(Delegate* delegate): Component(delegate) {}
Input::~Input() {}
// Component implementation.
dom::Element Input::Render() {
using namespace dom;
Element Input::Render() {
bool is_focused = Focused();
// Placeholder.
@ -75,4 +74,4 @@ bool Input::OnEvent(Event event) {
return false;
}
} // namespace ftxui::component
} // namespace ftxui

View File

@ -2,12 +2,11 @@
#include <algorithm>
#include <iostream>
namespace ftxui::component {
namespace ftxui {
Menu::Menu(Delegate* delegate) : Component(delegate) {}
dom::Element Menu::Render() {
using namespace dom;
Element Menu::Render() {
std::vector<Element> elements;
bool focused = Focused();
for (size_t i = 0; i < entries.size(); ++i) {
@ -49,4 +48,4 @@ bool Menu::OnEvent(Event event) {
return false;
}
} // namespace ftxui::component
} // namespace ftxui

View File

@ -6,9 +6,9 @@
#include <iostream>
#include "ftxui/component/component.hpp"
#include "ftxui/component/delegate.hpp"
#include "ftxui/terminal.hpp"
#include "ftxui/screen/terminal.hpp"
namespace ftxui::component {
namespace ftxui {
namespace {
constexpr int ESC = 27;
@ -42,13 +42,14 @@ Event GetEvent() {
return Event{v1};
};
}; // namespace
class ScreenInteractive::Delegate : public component::Delegate {
class ScreenInteractive::Delegate : public Component::Delegate {
public:
Delegate() : root_(this) {}
void Register(component::Component* c) override { component_ = c; }
void Register(Component* c) override { component_ = c; }
std::vector<std::unique_ptr<Delegate>> child_;
Delegate* NewChild() override {
@ -67,24 +68,24 @@ class ScreenInteractive::Delegate : public component::Delegate {
void OnEvent(Event event) { component_->OnEvent(event); }
std::vector<component::Delegate*> children() override {
std::vector<component::Delegate*> ret;
std::vector<Component::Delegate*> children() override {
std::vector<Component::Delegate*> ret;
for (auto& it : child_)
ret.push_back(it.get());
return ret;
}
Delegate* root_;
Delegate* parent_ = nullptr;
Delegate* previous_sibling_ = nullptr;
Delegate* next_sibling_ = nullptr;
component::Component* component_;
Component::Delegate* root_;
Component::Delegate* parent_ = nullptr;
Component::Delegate* previous_sibling_ = nullptr;
Component::Delegate* next_sibling_ = nullptr;
Component* component_;
Delegate* Root() override { return root_; }
Delegate* Parent() override { return parent_; }
Delegate* PreviousSibling() override { return previous_sibling_; }
Delegate* NextSibling() override { return next_sibling_; }
component::Component* component() override { return component_; }
Component::Delegate* Root() override { return root_; }
Component::Delegate* Parent() override { return parent_; }
Component::Delegate* PreviousSibling() override { return previous_sibling_; }
Component::Delegate* NextSibling() override { return next_sibling_; }
Component* component() override { return component_; }
};
ScreenInteractive::ScreenInteractive(size_t dimx,
@ -162,14 +163,14 @@ void ScreenInteractive::PrepareDraw() {
if (dimx != dimx_ || dimy != dimy_) {
dimx_ = dimx;
dimy_ = dimy;
pixels_ = std::vector<std::vector<screen::Pixel>>(
dimy, std::vector<screen::Pixel>(dimx));
pixels_ = std::vector<std::vector<Pixel>>(
dimy, std::vector<Pixel>(dimx));
}
Render(*this, document.get());
}
component::Delegate* ScreenInteractive::delegate() {
Component::Delegate* ScreenInteractive::delegate() {
return delegate_.get();
}
@ -177,4 +178,4 @@ std::function<void()> ScreenInteractive::ExitLoopClosure() {
return [this]() { quit_ = true; };
}
} // namespace ftxui::component.
} // namespace ftxui.

View File

@ -1,11 +1,10 @@
#include "ftxui/component/toggle.hpp"
namespace ftxui::component {
namespace ftxui {
Toggle::Toggle(Delegate* delegate) : Component(delegate) {}
dom::Element Toggle::Render() {
using namespace dom;
Element Toggle::Render() {
auto highlight = Focused() ? inverted : bold;
Children children;
@ -40,4 +39,4 @@ bool Toggle::OnEvent(Event event) {
return false;
}
} // namespace ftxui::component
} // namespace ftxui

View File

@ -1,14 +1,14 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class Blink : public NodeDecorator {
public:
Blink(Children children) : NodeDecorator(std::move(children)) {}
~Blink() override {}
void Render(screen::Screen& screen) override {
void Render(Screen& screen) override {
Node::Render(screen);
for (int y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) {
@ -22,4 +22,4 @@ std::unique_ptr<Node> blink(Child child) {
return std::make_unique<Blink>(unpack(std::move(child)));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,14 +1,14 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class Bold : public NodeDecorator {
public:
Bold(Children children) : NodeDecorator(std::move(children)) {}
~Bold() override {}
void Render(screen::Screen& screen) override {
void Render(Screen& screen) override {
for (int y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) {
screen.PixelAt(x,y).bold = true;
@ -22,4 +22,4 @@ std::unique_ptr<Node> bold(Child child) {
return std::make_unique<Bold>(unpack(std::move(child)));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,14 +1,14 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class BgColor : public NodeDecorator {
public:
BgColor(Children children, Color color)
: NodeDecorator(std::move(children)), color_(color) {}
void Render(screen::Screen& screen) override {
void Render(Screen& screen) override {
for (int y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) {
screen.PixelAt(x, y).background_color = color_;
@ -26,7 +26,7 @@ class FgColor : public NodeDecorator {
: NodeDecorator(std::move(children)), color_(color) {}
~FgColor() override {}
void Render(screen::Screen& screen) override {
void Render(Screen& screen) override {
for (int y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) {
screen.PixelAt(x, y).foreground_color = color_;
@ -58,4 +58,4 @@ Decorator bgcolor(Color c) {
};
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,7 +1,7 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
std::unique_ptr<Node> hcenter(Element child) {
return hbox(filler(), std::move(child), filler());
@ -19,4 +19,4 @@ std::unique_ptr<Node> align_right(Element child) {
return hbox(filler(), std::move(child));
}
} // namespace ftxui::dom
} // namespace ftxui

View File

@ -1,7 +1,7 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class DBox : public Node {
public:
@ -32,4 +32,4 @@ std::unique_ptr<Node> dbox(Children children) {
return std::make_unique<DBox>(std::move(children));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
using ftxui::screen::Screen;
using ftxui::Screen;
class Dim : public NodeDecorator {
public:
@ -24,4 +24,4 @@ std::unique_ptr<Node> dim(Child child) {
return std::make_unique<Dim>(unpack(std::move(child)));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,7 +1,7 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class Flex : public Node {
public:
@ -34,4 +34,4 @@ std::unique_ptr<Node> flex(Element child) {
return std::make_unique<Flex>(std::move(child));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
using namespace ftxui::screen;
using namespace ftxui;
static wchar_t charset[] = L"┌┐└┘─│┬┴┤├";
@ -95,4 +95,4 @@ Decorator boxed() {
};
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
using namespace ftxui::screen;
using namespace ftxui;
static wchar_t charset[] = L" ▏▎▍▌▋▊▉█";
@ -36,4 +36,4 @@ std::unique_ptr<Node> gauge(float progress) {
return std::make_unique<Gauge>(progress);
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -2,8 +2,8 @@
#include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h"
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
using namespace ftxui;
TEST(GaugeTest, zero) {
auto root = gauge(0);

View File

@ -1,7 +1,7 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class HBox : public Node {
public:
@ -63,4 +63,4 @@ std::unique_ptr<Node> hbox(Children children) {
return std::make_unique<HBox>(std::move(children));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -2,8 +2,8 @@
#include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h"
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
using namespace ftxui;
TEST(HBoxTest, ScreenSmaller1) {
auto root = hbox(

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
using ftxui::screen::Screen;
using ftxui::Screen;
class Inverted : public NodeDecorator {
public:
@ -24,4 +24,4 @@ std::unique_ptr<Node> inverted(Child child) {
return std::make_unique<Inverted>(unpack(std::move(child)));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,8 +1,8 @@
#include "ftxui/dom/node.hpp"
namespace ftxui::dom {
namespace ftxui {
using ftxui::screen::Screen;
using ftxui::Screen;
Node::Node() {}
Node::Node(std::vector<std::unique_ptr<Node>> children)
@ -40,4 +40,4 @@ void Render(Screen& screen, Node* node) {
node->Render(screen);
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,6 +1,6 @@
#include "ftxui/dom/node_decorator.hpp"
namespace ftxui::dom {
namespace ftxui {
void NodeDecorator::ComputeRequirement() {
Node::ComputeRequirement();
@ -12,4 +12,4 @@ void NodeDecorator::SetBox(Box box) {
children[0]->SetBox(box);
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -4,7 +4,7 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
// Helper class.
class NodeDecorator : public Node {
@ -15,6 +15,6 @@ class NodeDecorator : public Node {
void SetBox(Box box) override;
};
}; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_NODE_DECORATOR_H_ */

View File

@ -1,8 +1,8 @@
#include "ftxui/dom/node.hpp"
namespace ftxui::dom {
namespace ftxui {
using ftxui::screen::Screen;
using ftxui::Screen;
class Separator : public Node {
public:
@ -35,4 +35,4 @@ std::unique_ptr<Node> separator() {
return std::make_unique<Separator>();
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,7 +1,7 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class Size : public Node {
public:
@ -32,4 +32,4 @@ Decorator size(size_t width, size_t height) {
};
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
using namespace ftxui::screen;
using namespace ftxui;
static const std::vector<std::vector<std::vector<std::wstring>>> elements = {
{
@ -276,4 +276,4 @@ std::unique_ptr<Node> spinner(int c, size_t index) {
return vbox(std::move(lines));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,8 +1,8 @@
#include "ftxui/dom/node.hpp"
namespace ftxui::dom {
namespace ftxui {
using ftxui::screen::Screen;
using ftxui::Screen;
class Text : public Node {
public:
@ -34,4 +34,4 @@ std::unique_ptr<Node> text(std::wstring text) {
return std::make_unique<Text>(text);
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -2,8 +2,8 @@
#include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h"
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
using namespace ftxui;
TEST(TextTest, ScreenHeightSmaller) {
auto element = text(L"test");

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
using ftxui::screen::Screen;
using ftxui::Screen;
class Underlined : public NodeDecorator {
public:
@ -24,4 +24,4 @@ std::unique_ptr<Node> underlined(Child child) {
return std::make_unique<Underlined>(unpack(std::move(child)));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,6 +1,6 @@
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
Element nothing(Element element) {
return std::move(element);
@ -23,4 +23,4 @@ Element operator|(Element e, Decorator d) {
return d(std::move(e));
}
} // namespace ftxui::dom
} // namespace ftxui

View File

@ -1,7 +1,7 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
namespace ftxui {
class VBox : public Node {
public:
@ -63,4 +63,4 @@ std::unique_ptr<Node> vbox(Children children) {
return std::make_unique<VBox>(std::move(children));
}
}; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -2,8 +2,8 @@
#include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h"
using namespace ftxui::screen;
using namespace ftxui::dom;
using namespace ftxui;
using namespace ftxui;
TEST(VBoxTest, ScreenSmaller1) {
auto root = vbox(text(L"text_1"), text(L"text_2"));

View File

@ -1,11 +1,11 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/node.hpp"
#include "ftxui/terminal.hpp"
#include "ftxui/util/string.hpp"
#include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp"
#include <sstream>
namespace ftxui::screen {
namespace ftxui {
static const wchar_t* BOLD_SET = L"\e[1m";
static const wchar_t* BOLD_RESET = L"\e[22m"; // Can't use 21 here.
@ -86,7 +86,7 @@ Screen Screen::TerminalFullscreen() {
}
// static
Screen Screen::TerminalOutput(std::unique_ptr<dom::Node>& element) {
Screen Screen::TerminalOutput(std::unique_ptr<Node>& element) {
element->ComputeRequirement();
Terminal::Dimensions size = Terminal::Size();
return Screen(size.dimx, element->requirement().min.y);
@ -106,4 +106,4 @@ void Screen::Clear() {
std::vector<Pixel>(dimx_, Pixel()));
}
}; // namespace ftxui::screen
}; // namespace ftxui

View File

@ -2,7 +2,7 @@
#include <stdio.h>
#include <unistd.h>
#include "ftxui/terminal.hpp"
#include "ftxui/screen/terminal.hpp"
namespace ftxui {