mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-11-01 02:58:12 +08:00 
			
		
		
		
	Refactor directory structure.
The goal is to increase the separation in between: * ftxui::screen * ftxui::dom * ftxui::component
This commit is contained in:
		| @@ -5,8 +5,10 @@ add_library(ftxui | ||||
|   src/ftxui/component/component_direction.cpp | ||||
|   src/ftxui/component/component_horizontal.cpp | ||||
|   src/ftxui/component/component_vertical.cpp | ||||
|   src/ftxui/component/event.cpp | ||||
|   src/ftxui/component/input.cpp | ||||
|   src/ftxui/component/menu.cpp | ||||
|   src/ftxui/component/screen_interactive.cpp | ||||
|   src/ftxui/component/toggle.cpp | ||||
|   src/ftxui/dom/blink.cpp | ||||
|   src/ftxui/dom/bold.cpp | ||||
| @@ -26,9 +28,7 @@ add_library(ftxui | ||||
|   src/ftxui/dom/underlined.cpp | ||||
|   src/ftxui/dom/util.cpp | ||||
|   src/ftxui/dom/vbox.cpp | ||||
|   src/ftxui/event.cpp | ||||
|   src/ftxui/screen.cpp | ||||
|   src/ftxui/screen_interactive.cpp | ||||
|   src/ftxui/screen/screen.cpp | ||||
|   src/ftxui/terminal.cpp | ||||
|   src/ftxui/util/string.cpp | ||||
| ) | ||||
|   | ||||
| @@ -1,11 +0,0 @@ | ||||
| #ifndef FTX_UI_CORE_BOX | ||||
| #define FTX_UI_CORE_BOX | ||||
|  | ||||
| struct Box { | ||||
|   int left; | ||||
|   int right; | ||||
|   int top; | ||||
|   int bottom; | ||||
| }; | ||||
|  | ||||
| #endif /* end of include guard: FTX_UI_CORE_BOX */ | ||||
| @@ -2,11 +2,10 @@ | ||||
| #define FTXUI_COMPONENT_COMPONENT_HPP | ||||
|  | ||||
| #include "ftxui/component/delegate.hpp" | ||||
| #include "ftxui/component/event.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
| #include "ftxui/event.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| class Delegate; | ||||
| class Focus; | ||||
| @@ -39,7 +38,6 @@ class Component { | ||||
|   Delegate* delegate_; | ||||
| }; | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */ | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
|  | ||||
| #include "ftxui/component/component_direction.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| // A component where focus and events are automatically handled for you. | ||||
| // It assumes its children are put in the horizontal direction. | ||||
| @@ -14,7 +13,6 @@ class ComponentHorizontal : public ComponentDirection { | ||||
|   bool HandleDirection(Event) override; | ||||
| }; | ||||
|  | ||||
| } // namespace component | ||||
| } // namespace ftxui | ||||
| } // namespace ftxui::component | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */ | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
|  | ||||
| #include "ftxui/component/component_direction.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| // A component where focus and events are automatically handled for you. | ||||
| // It assumes its children are put in the vertical direction. | ||||
| @@ -14,7 +13,6 @@ class ComponentVertical : public ComponentDirection { | ||||
|   bool HandleDirection(Event) override; | ||||
| }; | ||||
|  | ||||
| } // namespace component | ||||
| } // namespace ftxui | ||||
| } // namespace ftxui::component | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */ | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
|  | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| class Component; | ||||
|  | ||||
| @@ -28,7 +27,6 @@ class Delegate { | ||||
|   virtual Delegate* Root() = 0; | ||||
| }; | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */ | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| #ifndef FTXUI_EVENT_H_ | ||||
| #define FTXUI_EVENT_H_ | ||||
| #ifndef FTXUI_COMPONENT_EVENT_HPP | ||||
| #define FTXUI_COMPONENT_EVENT_HPP | ||||
| 
 | ||||
| #include <vector> | ||||
| #include <array> | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace ftxui::component { | ||||
| 
 | ||||
| struct Event{ | ||||
|  public: | ||||
| @@ -31,7 +31,7 @@ struct Event{ | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| } // namespace ftxui
 | ||||
| } // namespace ftxui::component
 | ||||
| 
 | ||||
| 
 | ||||
| #endif /* end of include guard: FTXUI_EVENT_H_ */ | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */ | ||||
| @@ -4,8 +4,7 @@ | ||||
| #include "ftxui/component/component.hpp" | ||||
| #include <functional> | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| class Input : public Component { | ||||
|  public: | ||||
| @@ -29,7 +28,6 @@ class Input : public Component { | ||||
|   int cursor_position = 0; | ||||
| }; | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */ | ||||
|   | ||||
| @@ -5,8 +5,7 @@ | ||||
| #include "ftxui/dom/elements.hpp" | ||||
| #include <functional> | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| class Menu : public Component { | ||||
|  public: | ||||
| @@ -30,7 +29,6 @@ class Menu : public Component { | ||||
|   bool OnEvent(Event) override; | ||||
| }; | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::Component | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_MENU */ | ||||
|   | ||||
| @@ -1,18 +1,16 @@ | ||||
| #ifndef FTXUI_SCREEN_INTERACTIVE | ||||
| #define FTXUI_SCREEN_INTERACTIVE | ||||
| #ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP | ||||
| #define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP | ||||
| 
 | ||||
| #include "ftxui/screen.hpp" | ||||
| #include "ftxui/screen/screen.hpp" | ||||
| #include <functional> | ||||
| #include <memory> | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace ftxui::component { | ||||
| 
 | ||||
| namespace component { | ||||
|   class Delegate; | ||||
|   class Component; | ||||
| } // namespace component
 | ||||
| class Delegate; | ||||
| class Component; | ||||
| 
 | ||||
| class ScreenInteractive : public Screen { | ||||
| class ScreenInteractive : public ftxui::screen::Screen { | ||||
|   public: | ||||
|     static ScreenInteractive FixedSize(size_t dimx, size_t dimy); | ||||
|     static ScreenInteractive Fullscreen(); | ||||
| @@ -21,15 +19,15 @@ class ScreenInteractive : public Screen { | ||||
|     ~ScreenInteractive(); | ||||
|     component::Delegate* delegate(); | ||||
|     void Loop(); | ||||
| 		std::function<void()> ExitLoopClosure(); | ||||
|     std::function<void()> ExitLoopClosure(); | ||||
| 
 | ||||
|   private: | ||||
|    class Delegate; | ||||
|    std::unique_ptr<Delegate> delegate_; | ||||
| 
 | ||||
| 	 void Clear(); | ||||
| 	 void Draw(); | ||||
| 	 bool quit_ = false; | ||||
|    void Clear(); | ||||
|    void Draw(); | ||||
|    bool quit_ = false; | ||||
| 
 | ||||
|    enum class Dimension { | ||||
|      Fixed, | ||||
| @@ -41,6 +39,6 @@ class ScreenInteractive : public Screen { | ||||
|    ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension); | ||||
| }; | ||||
| 
 | ||||
| }  // namespace ftxui
 | ||||
| }  // namespace ftxui::component
 | ||||
| 
 | ||||
| #endif /* end of include guard: FTXUI_SCREEN_INTERACTIVE */ | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */ | ||||
| @@ -5,8 +5,7 @@ | ||||
| #include <functional> | ||||
| #include <string> | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| class Toggle : public Component { | ||||
|  public: | ||||
| @@ -25,7 +24,6 @@ class Toggle : public Component { | ||||
|   bool OnEvent(Event) override; | ||||
| }; | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::Component | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */ | ||||
|   | ||||
							
								
								
									
										15
									
								
								ftxui/include/ftxui/dom/box.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								ftxui/include/ftxui/dom/box.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| #ifndef FTXUI_DOM_BOX_HPP | ||||
| #define FTXUI_DOM_BOX_HPP | ||||
|  | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| struct Box { | ||||
|   int left; | ||||
|   int right; | ||||
|   int top; | ||||
|   int bottom; | ||||
| }; | ||||
|  | ||||
| }; // namespace ftxui::dom | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_DOM_BOX_HPP */ | ||||
| @@ -3,16 +3,16 @@ | ||||
|  | ||||
| #include <functional> | ||||
|  | ||||
| #include "ftxui/color.hpp" | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/screen/color.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| 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; | ||||
|  | ||||
| // --- Layout ---- | ||||
| Element vbox(Children); | ||||
| @@ -58,7 +58,6 @@ TAKE_ANY_ARGS(vbox) | ||||
| TAKE_ANY_ARGS(hbox) | ||||
| TAKE_ANY_ARGS(dbox) | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */ | ||||
|   | ||||
| @@ -1,15 +1,14 @@ | ||||
| #ifndef DOM_NODE_HPP | ||||
| #define DOM_NODE_HPP | ||||
| #ifndef FTXUI_DOM_NODE_HPP | ||||
| #define FTXUI_DOM_NODE_HPP | ||||
|  | ||||
| #include <memory> | ||||
| #include <vector> | ||||
|  | ||||
| #include "ftxui/requirement.hpp" | ||||
| #include "ftxui/screen.hpp" | ||||
| #include "ftxui/box.hpp" | ||||
| #include "ftxui/dom/box.hpp" | ||||
| #include "ftxui/dom/requirement.hpp" | ||||
| #include "ftxui/screen/screen.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class Node { | ||||
|  public: | ||||
| @@ -28,7 +27,7 @@ class Node { | ||||
|   virtual void SetBox(Box box); | ||||
|  | ||||
|   // Step 3: Draw this element. | ||||
|   virtual void Render(Screen& screen); | ||||
|   virtual void Render(screen::Screen& screen); | ||||
|  | ||||
|   std::vector<std::unique_ptr<Node>> children; | ||||
|  protected: | ||||
| @@ -36,9 +35,8 @@ class Node { | ||||
|   Box box_; | ||||
| }; | ||||
|  | ||||
| void Render(Screen& screen, Node* node); | ||||
| void Render(screen::Screen& screen, Node* node); | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|  | ||||
| #endif /* end of include guard: DOM_NODE_HPP */ | ||||
| #endif /* end of include guard: FTXUI_DOM_NODE_HPP */ | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| #ifndef FTXUI_REQUIREMENT_HPP | ||||
| #define FTXUI_REQUIREMENT_HPP | ||||
| #ifndef FTXUI_DOM_REQUIREMENT_HPP | ||||
| #define FTXUI_DOM_REQUIREMENT_HPP | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace ftxui::dom { | ||||
| 
 | ||||
| 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
 | ||||
| }; // namespace ftxui::dom
 | ||||
| 
 | ||||
| #endif /* end of include guard: FTXUI_REQUIREMENT_HPP */ | ||||
| @@ -1,9 +1,9 @@ | ||||
| #ifndef FTXUI_COLOR_H_ | ||||
| #define FTXUI_COLOR_H_ | ||||
| #ifndef FTXUI_SCREEN_COLOR | ||||
| #define FTXUI_SCREEN_COLOR | ||||
| 
 | ||||
| #include <cstdint> | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace ftxui::screen { | ||||
| 
 | ||||
| enum class Color : uint8_t { | ||||
|   // --- Transparent -----
 | ||||
| @@ -35,6 +35,6 @@ enum class Color : uint8_t { | ||||
|   YellowLight = 93, | ||||
| }; | ||||
| 
 | ||||
| };  // namespace ftxui
 | ||||
| }; // namespace ftxui::screen
 | ||||
| 
 | ||||
| #endif /* end of include guard: FTXUI_COLOR_H_ */ | ||||
| @@ -1,17 +1,18 @@ | ||||
| #ifndef FTXUI_SCREEN | ||||
| #define FTXUI_SCREEN | ||||
| #ifndef FTXUI_SCREEN_SCREEN | ||||
| #define FTXUI_SCREEN_SCREEN | ||||
| 
 | ||||
| #include <string> | ||||
| #include <vector> | ||||
| #include <memory> | ||||
| 
 | ||||
| #include <ftxui/color.hpp> | ||||
| #include "ftxui/screen/color.hpp" | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|   class Node; | ||||
| } | ||||
| 
 | ||||
| namespace ftxui::screen { | ||||
| 
 | ||||
| struct Pixel { | ||||
|   wchar_t character = U' '; | ||||
|   bool blink = false; | ||||
| @@ -55,6 +56,6 @@ class Screen { | ||||
|   std::vector<std::vector<Pixel>> pixels_; | ||||
| }; | ||||
| 
 | ||||
| };  // namespace ftxui
 | ||||
| };  // namespace ftxui::screen
 | ||||
| 
 | ||||
| #endif /* end of include guard: FTXUI_SCREEN */ | ||||
| #endif /* end of include guard: FTXUI_SCREEN_SCREEN */ | ||||
| @@ -2,8 +2,7 @@ | ||||
| #include "ftxui/component/delegate.hpp" | ||||
| #include <assert.h> | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| Component::Component(Delegate* delegate) { | ||||
|   delegate_ = delegate; | ||||
| @@ -55,5 +54,4 @@ Component* Component::Parent() { | ||||
|   return parent_delegate->component(); | ||||
| } | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| #include "ftxui/component/component_direction.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| ComponentDirection::ComponentDirection(Delegate* delegate) | ||||
|     : Component(delegate), active_child_(nullptr) {} | ||||
| @@ -27,5 +26,4 @@ void ComponentDirection::Focus(Component* child) { | ||||
|   active_child_ = child; | ||||
| } | ||||
|  | ||||
| } // namespace component | ||||
| } // namespace ftxui | ||||
| } // namespace ftxui::Component | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| #include "ftxui/component/component_horizontal.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| ComponentHorizontal::ComponentHorizontal(Delegate* delegate) | ||||
|     : ComponentDirection(delegate) {} | ||||
| @@ -28,5 +27,4 @@ bool ComponentHorizontal::HandleDirection(Event event) { | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| #include "ftxui/component/component_vertical.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| ComponentVertical::ComponentVertical(Delegate* delegate) | ||||
|     : ComponentDirection(delegate) {} | ||||
| @@ -28,5 +27,4 @@ bool ComponentVertical::HandleDirection(Event event) { | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| #include "ftxui/event.hpp" | ||||
| #include "ftxui/component/event.hpp" | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace ftxui::component { | ||||
| 
 | ||||
| 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
 | ||||
| } // namespace ftxui::component
 | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "ftxui/component/input.hpp" | ||||
| #include "ftxui/util/string.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| Input::Input(Delegate* delegate): Component(delegate) {} | ||||
| Input::~Input() {} | ||||
| @@ -76,5 +75,4 @@ bool Input::OnEvent(Event event) { | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|   | ||||
| @@ -2,8 +2,7 @@ | ||||
| #include <algorithm> | ||||
| #include <iostream> | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| Menu::Menu(Delegate* delegate) : Component(delegate) {} | ||||
|  | ||||
| @@ -50,5 +49,4 @@ bool Menu::OnEvent(Event event) { | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|   | ||||
| @@ -1,48 +1,48 @@ | ||||
| #include "ftxui/screen_interactive.hpp" | ||||
| #include "ftxui/component/screen_interactive.hpp" | ||||
| 
 | ||||
| #include "ftxui/component/component.hpp" | ||||
| #include "ftxui/component/delegate.hpp" | ||||
| #include "ftxui/terminal.hpp" | ||||
| #include <iostream> | ||||
| #include <stdio.h> | ||||
| #include <termios.h> | ||||
| #include <unistd.h> | ||||
| #include <iostream> | ||||
| #include "ftxui/component/component.hpp" | ||||
| #include "ftxui/component/delegate.hpp" | ||||
| #include "ftxui/terminal.hpp" | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace ftxui::component { | ||||
| 
 | ||||
| namespace { | ||||
|   constexpr int ESC = 27; | ||||
|   constexpr int WAT = 195; | ||||
|   constexpr int WAT2 = 194; | ||||
|   constexpr int WATWAIT = 91; | ||||
| constexpr int ESC = 27; | ||||
| constexpr int WAT = 195; | ||||
| constexpr int WAT2 = 194; | ||||
| constexpr int WATWAIT = 91; | ||||
| 
 | ||||
|   Event GetEvent() { | ||||
|     int v1 = getchar(); | ||||
|     if (v1 == ESC) { | ||||
|       int v2 = getchar(); | ||||
|       int v3 = getchar(); | ||||
| Event GetEvent() { | ||||
|   int v1 = getchar(); | ||||
|   if (v1 == ESC) { | ||||
|     int v2 = getchar(); | ||||
|     int v3 = getchar(); | ||||
| 
 | ||||
|       //if (v2 == WATWAIT) {
 | ||||
|         //int v4 = getchar();
 | ||||
|         //int v5 = getchar();
 | ||||
|         //return Event{v1, v2, v3, v4, v5};
 | ||||
|       //}
 | ||||
|       return Event{v1, v2, v3}; | ||||
|     } | ||||
|     // if (v2 == WATWAIT) {
 | ||||
|     // int v4 = getchar();
 | ||||
|     // int v5 = getchar();
 | ||||
|     // return Event{v1, v2, v3, v4, v5};
 | ||||
|     //}
 | ||||
|     return Event{v1, v2, v3}; | ||||
|   } | ||||
| 
 | ||||
|     if (v1 == WAT) { | ||||
|       int v2 = getchar(); | ||||
|       return Event{v1, v2}; | ||||
|     } | ||||
|   if (v1 == WAT) { | ||||
|     int v2 = getchar(); | ||||
|     return Event{v1, v2}; | ||||
|   } | ||||
| 
 | ||||
|     if (v1 == WAT2) { | ||||
|       int v2 = getchar(); | ||||
|       return Event{v1, v2}; | ||||
|     } | ||||
|   if (v1 == WAT2) { | ||||
|     int v2 = getchar(); | ||||
|     return Event{v1, v2}; | ||||
|   } | ||||
| 
 | ||||
|     return Event{v1}; | ||||
|   }; | ||||
|   return Event{v1}; | ||||
| }; | ||||
| };  // namespace
 | ||||
| 
 | ||||
| class ScreenInteractive::Delegate : public component::Delegate { | ||||
|  public: | ||||
| @@ -67,7 +67,6 @@ class ScreenInteractive::Delegate : public component::Delegate { | ||||
| 
 | ||||
|   void OnEvent(Event event) { component_->OnEvent(event); } | ||||
| 
 | ||||
| 
 | ||||
|   std::vector<component::Delegate*> children() override { | ||||
|     std::vector<component::Delegate*> ret; | ||||
|     for (auto& it : child_) | ||||
| @@ -129,12 +128,14 @@ void ScreenInteractive::Loop() { | ||||
|   tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_new); | ||||
| 
 | ||||
|   Draw(); | ||||
|   while(!quit_) { | ||||
|   while (!quit_) { | ||||
|     delegate_->OnEvent(GetEvent()); | ||||
|     Clear(); | ||||
|     Draw(); | ||||
|   } while(!quit_); | ||||
|   //std::cout << std::endl;
 | ||||
|   } | ||||
|   while (!quit_) | ||||
|     ; | ||||
|   // std::cout << std::endl;
 | ||||
| 
 | ||||
|   // Restore the old terminal configuration.
 | ||||
|   tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_old); | ||||
| @@ -144,7 +145,7 @@ void ScreenInteractive::Draw() { | ||||
|   auto document = delegate_->component()->Render(); | ||||
|   size_t dimx; | ||||
|   size_t dimy; | ||||
|   switch(dimension_) { | ||||
|   switch (dimension_) { | ||||
|     case Dimension::Fixed: | ||||
|       break; | ||||
|     case Dimension::TerminalOutput: | ||||
| @@ -162,7 +163,8 @@ void ScreenInteractive::Draw() { | ||||
|   if (dimx != dimx_ || dimy != dimy_) { | ||||
|     dimx_ = dimx; | ||||
|     dimy_ = dimy; | ||||
|     pixels_ = std::vector<std::vector<Pixel>>(dimy, std::vector<Pixel>(dimx)); | ||||
|     pixels_ = std::vector<std::vector<screen::Pixel>>( | ||||
|         dimy, std::vector<screen::Pixel>(dimx)); | ||||
|   } | ||||
| 
 | ||||
|   Render(*this, document.get()); | ||||
| @@ -182,4 +184,4 @@ std::function<void()> ScreenInteractive::ExitLoopClosure() { | ||||
|   return [this]() { quit_ = true; }; | ||||
| } | ||||
| 
 | ||||
| }  // namespace ftxui
 | ||||
| }  // namespace ftxui::component.
 | ||||
| @@ -1,7 +1,6 @@ | ||||
| #include "ftxui/component/toggle.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace component { | ||||
| namespace ftxui::component { | ||||
|  | ||||
| Toggle::Toggle(Delegate* delegate) : Component(delegate) {} | ||||
|  | ||||
| @@ -41,5 +40,4 @@ bool Toggle::OnEvent(Event event) { | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| }  // namespace component | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::component | ||||
|   | ||||
| @@ -1,15 +1,14 @@ | ||||
| #include "ftxui/dom/node_decorator.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class Blink : public NodeDecorator { | ||||
|  public: | ||||
|   Blink(Children children) : NodeDecorator(std::move(children)) {} | ||||
|   ~Blink() override {} | ||||
|  | ||||
|   void Render(Screen& screen) override { | ||||
|   void Render(screen::Screen& screen) override { | ||||
|     Node::Render(screen); | ||||
|     for (int y = box_.top; y <= box_.bottom; ++y) { | ||||
|       for (int x = box_.left; x <= box_.right; ++x) { | ||||
| @@ -23,5 +22,4 @@ std::unique_ptr<Node> blink(Child child) { | ||||
|   return std::make_unique<Blink>(unpack(std::move(child))); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,15 +1,14 @@ | ||||
| #include "ftxui/dom/node_decorator.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class Bold : public NodeDecorator { | ||||
|  public: | ||||
|   Bold(Children children) : NodeDecorator(std::move(children)) {} | ||||
|   ~Bold() override {} | ||||
|  | ||||
|   void Render(Screen& screen) override { | ||||
|   void Render(screen::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;  | ||||
| @@ -23,5 +22,4 @@ std::unique_ptr<Node> bold(Child child) { | ||||
|   return std::make_unique<Bold>(unpack(std::move(child))); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,15 +1,14 @@ | ||||
| #include "ftxui/dom/node_decorator.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class BgColor : public NodeDecorator { | ||||
|  public: | ||||
|   BgColor(Children children, Color color) | ||||
|       : NodeDecorator(std::move(children)), color_(color) {} | ||||
|  | ||||
|   void Render(Screen& screen) override { | ||||
|   void Render(screen::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_; | ||||
| @@ -27,7 +26,7 @@ class FgColor : public NodeDecorator { | ||||
|       : NodeDecorator(std::move(children)), color_(color) {} | ||||
|   ~FgColor() override {} | ||||
|  | ||||
|   void Render(Screen& screen) override { | ||||
|   void Render(screen::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_; | ||||
| @@ -59,5 +58,4 @@ Decorator bgcolor(Color c) { | ||||
|   }; | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| std::unique_ptr<Node> hcenter(Element child) { | ||||
|   return hbox(filler(), std::move(child), filler()); | ||||
| @@ -16,5 +15,4 @@ std::unique_ptr<Node> center(Element child) { | ||||
|   return hcenter(vcenter(std::move(child))); | ||||
| } | ||||
|  | ||||
| } // namespace dom | ||||
| } // namespace ftxui | ||||
| } // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class DBox : public Node { | ||||
|  public: | ||||
| @@ -33,5 +32,4 @@ std::unique_ptr<Node> dbox(Children children) { | ||||
|   return std::make_unique<DBox>(std::move(children)); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| #include "ftxui/dom/node_decorator.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using ftxui::screen::Screen; | ||||
|  | ||||
| class Dim : public NodeDecorator { | ||||
|  public: | ||||
| @@ -23,5 +24,4 @@ std::unique_ptr<Node> dim(Child child) { | ||||
|   return std::make_unique<Dim>(unpack(std::move(child))); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class Flex : public Node { | ||||
|  public: | ||||
| @@ -35,5 +34,4 @@ std::unique_ptr<Node> flex(Element child) { | ||||
|   return std::make_unique<Flex>(std::move(child)); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using namespace ftxui::screen; | ||||
|  | ||||
| static wchar_t charset[] = L"┌┐└┘─│┬┴┤├"; | ||||
|  | ||||
| @@ -94,5 +95,4 @@ Decorator boxed() { | ||||
|   }; | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using namespace ftxui::screen; | ||||
|  | ||||
| static wchar_t charset[] = L"  ▏▎▍▌▋▊▉█"; | ||||
|  | ||||
| @@ -35,5 +36,4 @@ std::unique_ptr<Node> gauge(float progress) { | ||||
|   return std::make_unique<Gauge>(progress); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| #include "ftxui/dom/elements.hpp" | ||||
| #include "ftxui/screen.hpp" | ||||
| #include "ftxui/screen/screen.hpp" | ||||
| #include "gtest/gtest.h" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| using namespace ftxui::screen; | ||||
| using namespace ftxui::dom; | ||||
|  | ||||
| TEST(GaugeTest, zero) { | ||||
|   auto root = gauge(0); | ||||
| @@ -29,6 +29,3 @@ TEST(GaugeTest, one) { | ||||
|  | ||||
|   EXPECT_EQ("███████████", screen.ToString()); | ||||
| } | ||||
|  | ||||
| } // namespace dom | ||||
| } // namespace ftxui | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class HBox : public Node { | ||||
|  public: | ||||
| @@ -64,5 +63,4 @@ std::unique_ptr<Node> hbox(Children children) { | ||||
|   return std::make_unique<HBox>(std::move(children)); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| #include "ftxui/dom/elements.hpp" | ||||
| #include "ftxui/screen.hpp" | ||||
| #include "ftxui/screen/screen.hpp" | ||||
| #include "gtest/gtest.h" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| using namespace ftxui::screen; | ||||
| using namespace ftxui::dom; | ||||
|  | ||||
| TEST(HBoxTest, ScreenSmaller1) { | ||||
|   auto root = hbox( | ||||
| @@ -118,6 +118,3 @@ TEST(HBoxTest, ScreenBigger2Flex) { | ||||
|  | ||||
|   EXPECT_EQ("text_1  text_2", screen.ToString()); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| #include "ftxui/dom/node_decorator.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using ftxui::screen::Screen; | ||||
|  | ||||
| class Inverted : public NodeDecorator { | ||||
|  public: | ||||
| @@ -23,5 +24,4 @@ std::unique_ptr<Node> inverted(Child child) { | ||||
|   return std::make_unique<Inverted>(unpack(std::move(child))); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using ftxui::screen::Screen; | ||||
|  | ||||
| Node::Node() {} | ||||
| Node::Node(std::vector<std::unique_ptr<Node>> children) | ||||
| @@ -39,5 +40,4 @@ void Render(Screen& screen, Node* node) { | ||||
|   node->Render(screen); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| #include "ftxui/dom/node_decorator.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| void NodeDecorator::ComputeRequirement() { | ||||
|   Node::ComputeRequirement(); | ||||
| @@ -13,5 +12,4 @@ void NodeDecorator::SetBox(Box box) { | ||||
|   children[0]->SetBox(box); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| // Helper class. | ||||
| class NodeDecorator : public Node { | ||||
| @@ -16,7 +15,6 @@ class NodeDecorator : public Node { | ||||
|   void SetBox(Box box) override; | ||||
| }; | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|  | ||||
| #endif /* end of include guard: FTXUI_DOM_NODE_DECORATOR_H_ */ | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using ftxui::screen::Screen; | ||||
|  | ||||
| class Separator : public Node { | ||||
|  public: | ||||
| @@ -34,5 +35,4 @@ std::unique_ptr<Node> separator() { | ||||
|   return std::make_unique<Separator>(); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using ftxui::screen::Screen; | ||||
|  | ||||
| class Text : public Node { | ||||
|  public: | ||||
| @@ -33,5 +34,4 @@ std::unique_ptr<Node> text(std::wstring text) { | ||||
|   return std::make_unique<Text>(text); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| #include "ftxui/dom/elements.hpp" | ||||
| #include "ftxui/screen.hpp" | ||||
| #include "ftxui/screen/screen.hpp" | ||||
| #include "gtest/gtest.h" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| using namespace ftxui::screen; | ||||
| using namespace ftxui::dom; | ||||
|  | ||||
| TEST(TextTest, ScreenHeightSmaller) { | ||||
|   auto element = text(L"test"); | ||||
| @@ -44,6 +44,3 @@ TEST(TextTest, ScreenBigger2) { | ||||
|  | ||||
|   EXPECT_EQ("test  \n      ", screen.ToString()); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| #include "ftxui/dom/node_decorator.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| using ftxui::screen::Screen; | ||||
|  | ||||
| class Underlined : public NodeDecorator { | ||||
|  public: | ||||
| @@ -23,5 +24,4 @@ std::unique_ptr<Node> underlined(Child child) { | ||||
|   return std::make_unique<Underlined>(unpack(std::move(child))); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| Element nothing(Element element) { | ||||
|   return std::move(element); | ||||
| @@ -24,5 +23,4 @@ Element operator|(Element e, Decorator d) { | ||||
|   return d(std::move(e)); | ||||
| } | ||||
|  | ||||
| }  // namespace dom | ||||
| }  // namespace ftxui | ||||
| }  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/dom/elements.hpp" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| namespace ftxui::dom { | ||||
|  | ||||
| class VBox : public Node { | ||||
|  public: | ||||
| @@ -64,5 +63,4 @@ std::unique_ptr<Node> vbox(Children children) { | ||||
|   return std::make_unique<VBox>(std::move(children)); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
| };  // namespace ftxui::dom | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| #include "ftxui/dom/elements.hpp" | ||||
| #include "ftxui/screen.hpp" | ||||
| #include "ftxui/screen/screen.hpp" | ||||
| #include "gtest/gtest.h" | ||||
|  | ||||
| namespace ftxui { | ||||
| namespace dom { | ||||
| using namespace ftxui::screen; | ||||
| using namespace ftxui::dom; | ||||
|  | ||||
| TEST(VBoxTest, ScreenSmaller1) { | ||||
|   auto root = vbox(text(L"text_1"), text(L"text_2")); | ||||
| @@ -66,6 +66,3 @@ TEST(VBoxTest, ScreenBigger2Flex) { | ||||
|  | ||||
|   EXPECT_EQ("text_1\n      \n      \ntext_2", screen.ToString()); | ||||
| } | ||||
|  | ||||
| };  // namespace dom | ||||
| };  // namespace ftxui | ||||
|   | ||||
| @@ -1,26 +1,46 @@ | ||||
| #include "ftxui/screen.hpp" | ||||
| #include "ftxui/screen/screen.hpp" | ||||
| #include "ftxui/dom/node.hpp" | ||||
| #include "ftxui/terminal.hpp" | ||||
| #include "ftxui/util/string.hpp" | ||||
| 
 | ||||
| #include <sstream> | ||||
| 
 | ||||
| namespace ftxui { | ||||
| namespace ftxui::screen { | ||||
| 
 | ||||
| static const wchar_t* BOLD_SET = L"\e[1m"; | ||||
| static const wchar_t* BOLD_RESET = L"\e[22m"; // Can't use 21 here.
 | ||||
| 
 | ||||
| static const wchar_t* DIM_SET = L"\e[2m"; | ||||
| static const wchar_t* DIM_RESET = L"\e[22m"; | ||||
| 
 | ||||
| static const wchar_t* UNDERLINED_SET = L"\e[4m"; | ||||
| static const wchar_t* UNDERLINED_RESET = L"\e[24m"; | ||||
| 
 | ||||
| static const wchar_t* BLINK_SET = L"\e[5m"; | ||||
| static const wchar_t* BLINK_RESET = L"\e[25m"; | ||||
| 
 | ||||
| static const wchar_t* INVERTED_SET = L"\e[7m"; | ||||
| static const wchar_t* INVERTED_RESET = L"\e[27m"; | ||||
| 
 | ||||
| Screen::Screen(size_t dimx, size_t dimy) | ||||
|     : dimx_(dimx), dimy_(dimy), pixels_(dimy, std::vector<Pixel>(dimx)) {} | ||||
| 
 | ||||
| void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) { | ||||
|   if (next.bold != previous.bold) | ||||
|     ss << (next.bold ? L"\e[1m" : L"\e[22m"); // Can't use 21 here.
 | ||||
|     ss << (next.bold ? BOLD_SET : BOLD_RESET); | ||||
| 
 | ||||
|   if (next.dim != previous.dim) | ||||
|     ss << (next.dim ? L"\e[2m" : L"\e[22m"); | ||||
|     ss << (next.dim ? DIM_SET : DIM_RESET); | ||||
| 
 | ||||
|   if (next.underlined != previous.underlined) | ||||
|     ss << (next.underlined ? L"\e[4m" : L"\e[24m"); | ||||
|     ss << (next.underlined ? UNDERLINED_SET : UNDERLINED_RESET); | ||||
| 
 | ||||
|   if (next.blink != previous.blink) | ||||
|     ss << (next.blink ? L"\e[5m" : L"\e[25m"); | ||||
|     ss << (next.blink ? BLINK_SET : BLINK_RESET); | ||||
| 
 | ||||
|   if (next.inverted != previous.inverted) | ||||
|     ss << (next.inverted ? L"\e[7m" : L"\e[27m"); | ||||
|     ss << (next.inverted ? INVERTED_SET : INVERTED_RESET); | ||||
| 
 | ||||
|   if (next.foreground_color != previous.foreground_color || | ||||
|       next.background_color != previous.background_color) { | ||||
|     ss << L"\e[" + to_wstring(std::to_string((uint8_t)next.foreground_color)) + L"m"; | ||||
| @@ -84,4 +104,4 @@ void Screen::Clear() { | ||||
|                                             std::vector<Pixel>(dimx_, Pixel())); | ||||
| } | ||||
| 
 | ||||
| };  // namespace ftxui
 | ||||
| };  // namespace ftxui::screen
 | ||||
		Reference in New Issue
	
	Block a user
	 Arthur Sonzogni
					Arthur Sonzogni