| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  | #ifndef FTXUI_SCREEN_SCREEN_HPP
 | 
					
						
							|  |  |  | #define FTXUI_SCREEN_SCREEN_HPP
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-23 21:26:00 +01:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2023-02-12 14:09:47 +01:00
										 |  |  | #include <string>  // for string, allocator, basic_string
 | 
					
						
							| 
									
										
										
										
											2021-08-06 20:32:33 +02:00
										 |  |  | #include <vector>  // for vector
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-06 20:32:33 +02:00
										 |  |  | #include "ftxui/screen/box.hpp"       // for Box
 | 
					
						
							|  |  |  | #include "ftxui/screen/color.hpp"     // for Color, Color::Default
 | 
					
						
							|  |  |  | #include "ftxui/screen/terminal.hpp"  // for Dimensions
 | 
					
						
							| 
									
										
										
										
											2018-10-12 09:23:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-12 15:00:08 +01:00
										 |  |  | namespace ftxui { | 
					
						
							| 
									
										
										
										
											2019-01-06 17:10:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 01:34:13 +02:00
										 |  |  | /// @brief A unicode character and its associated style.
 | 
					
						
							|  |  |  | /// @ingroup screen
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | struct Pixel { | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  |   bool operator==(const Pixel& other) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 01:32:27 +02:00
										 |  |  |   // The graphemes stored into the pixel. To support combining characters,
 | 
					
						
							|  |  |  |   // like: a⃦, this can potentially contains multiple codepoitns.
 | 
					
						
							| 
									
										
										
										
											2021-08-08 23:25:20 +02:00
										 |  |  |   std::string character = " "; | 
					
						
							| 
									
										
										
										
											2021-06-26 01:32:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Colors:
 | 
					
						
							| 
									
										
										
										
											2018-10-12 09:23:37 +02:00
										 |  |  |   Color background_color = Color::Default; | 
					
						
							|  |  |  |   Color foreground_color = Color::Default; | 
					
						
							| 
									
										
										
										
											2021-06-26 01:32:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // A bit field representing the style:
 | 
					
						
							| 
									
										
										
										
											2021-06-12 20:33:02 +02:00
										 |  |  |   bool blink : 1; | 
					
						
							|  |  |  |   bool bold : 1; | 
					
						
							|  |  |  |   bool dim : 1; | 
					
						
							|  |  |  |   bool inverted : 1; | 
					
						
							|  |  |  |   bool underlined : 1; | 
					
						
							| 
									
										
										
										
											2023-01-22 11:02:27 +01:00
										 |  |  |   bool underlined_double : 1; | 
					
						
							|  |  |  |   bool strikethrough : 1; | 
					
						
							| 
									
										
										
										
											2022-01-22 15:38:01 +01:00
										 |  |  |   bool automerge : 1; | 
					
						
							| 
									
										
										
										
											2021-06-12 20:33:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Pixel() | 
					
						
							|  |  |  |       : blink(false), | 
					
						
							|  |  |  |         bold(false), | 
					
						
							|  |  |  |         dim(false), | 
					
						
							|  |  |  |         inverted(false), | 
					
						
							| 
									
										
										
										
											2022-01-22 15:38:01 +01:00
										 |  |  |         underlined(false), | 
					
						
							| 
									
										
										
										
											2023-01-22 11:02:27 +01:00
										 |  |  |         underlined_double(false), | 
					
						
							|  |  |  |         strikethrough(false), | 
					
						
							| 
									
										
										
										
											2022-01-22 15:38:01 +01:00
										 |  |  |         automerge(false) {} | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 01:34:13 +02:00
										 |  |  | /// @brief Define how the Screen's dimensions should look like.
 | 
					
						
							|  |  |  | /// @ingroup screen
 | 
					
						
							| 
									
										
										
										
											2021-08-03 02:49:29 +05:30
										 |  |  | namespace Dimension { | 
					
						
							|  |  |  | Dimensions Fixed(int); | 
					
						
							|  |  |  | Dimensions Full(); | 
					
						
							|  |  |  | }  // namespace Dimension
 | 
					
						
							| 
									
										
										
										
											2019-01-26 21:52:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 01:34:13 +02:00
										 |  |  | /// @brief A rectangular grid of Pixel.
 | 
					
						
							|  |  |  | /// @ingroup screen
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | class Screen { | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2020-05-25 01:34:13 +02:00
										 |  |  |   // Constructors:
 | 
					
						
							| 
									
										
										
										
											2019-01-26 21:52:55 +01:00
										 |  |  |   Screen(int dimx, int dimy); | 
					
						
							| 
									
										
										
										
											2021-08-03 02:49:29 +05:30
										 |  |  |   static Screen Create(Dimensions dimension); | 
					
						
							|  |  |  |   static Screen Create(Dimensions width, Dimensions height); | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-12 15:00:08 +01:00
										 |  |  |   // Node write into the screen using Screen::at.
 | 
					
						
							| 
									
										
										
										
											2021-08-08 23:25:20 +02:00
										 |  |  |   std::string& at(int x, int y); | 
					
						
							| 
									
										
										
										
											2019-01-26 21:52:55 +01:00
										 |  |  |   Pixel& PixelAt(int x, int y); | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Convert the screen into a printable string in the terminal.
 | 
					
						
							|  |  |  |   std::string ToString(); | 
					
						
							| 
									
										
										
										
											2021-03-22 00:26:52 +01:00
										 |  |  |   void Print(); | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Get screen dimensions.
 | 
					
						
							| 
									
										
										
										
											2022-01-18 22:48:58 +04:00
										 |  |  |   int dimx() const { return dimx_; } | 
					
						
							|  |  |  |   int dimy() const { return dimy_; } | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Move the terminal cursor n-lines up with n = dimy().
 | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  |   std::string ResetPosition(bool clear = false) const; | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Fill with space.
 | 
					
						
							|  |  |  |   void Clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 00:20:29 +01:00
										 |  |  |   void ApplyShader(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-29 18:52:58 +02:00
										 |  |  |   struct Cursor { | 
					
						
							| 
									
										
										
										
											2019-07-01 00:43:00 +02:00
										 |  |  |     int x = 0; | 
					
						
							|  |  |  |     int y = 0; | 
					
						
							| 
									
										
										
										
											2022-11-11 14:09:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     enum Shape { | 
					
						
							|  |  |  |       Hidden = 0, | 
					
						
							|  |  |  |       BlockBlinking = 1, | 
					
						
							|  |  |  |       Block = 2, | 
					
						
							|  |  |  |       UnderlineBlinking = 3, | 
					
						
							|  |  |  |       Underline = 4, | 
					
						
							| 
									
										
										
										
											2022-12-28 13:17:56 +01:00
										 |  |  |       BarBlinking = 5, | 
					
						
							|  |  |  |       Bar = 6, | 
					
						
							| 
									
										
										
										
											2022-11-11 14:09:53 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  |     Shape shape; | 
					
						
							| 
									
										
										
										
											2019-06-29 18:52:58 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  |   Cursor cursor() const { return cursor_; } | 
					
						
							|  |  |  |   void SetCursor(Cursor cursor) { cursor_ = cursor; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  |   Box stencil; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:03:49 +01:00
										 |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2019-01-26 21:52:55 +01:00
										 |  |  |   int dimx_; | 
					
						
							|  |  |  |   int dimy_; | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  |   std::vector<std::vector<Pixel>> pixels_; | 
					
						
							| 
									
										
										
										
											2019-06-29 18:52:58 +02:00
										 |  |  |   Cursor cursor_; | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:44:55 +01:00
										 |  |  | }  // namespace ftxui
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  | #endif  // FTXUI_SCREEN_SCREEN_HPP
 | 
					
						
							| 
									
										
										
										
											2020-08-16 00:24:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Copyright 2020 Arthur Sonzogni. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be found in
 | 
					
						
							|  |  |  | // the LICENSE file.
 |