| 
									
										
										
										
											2024-12-27 15:45:13 +07:00
										 |  |  | // Copyright 2024 Arthur Sonzogni. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be found in
 | 
					
						
							|  |  |  | // the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef FTXUI_DOM_SELECTION_HPP
 | 
					
						
							|  |  |  | #define FTXUI_DOM_SELECTION_HPP
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <functional>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <sstream>
 | 
					
						
							|  |  |  | #include "ftxui/screen/box.hpp"    // for Box
 | 
					
						
							|  |  |  | #include "ftxui/screen/pixel.hpp"  // for Pixel
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace ftxui { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-05 11:35:14 +02:00
										 |  |  | /// @brief Represents a selection in a terminal user interface.
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// Selection is a class that represents the two endpoints of a selection in a
 | 
					
						
							|  |  |  | /// terminal user interface.
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// @ingroup dom
 | 
					
						
							| 
									
										
										
										
											2024-12-27 15:45:13 +07:00
										 |  |  | class Selection { | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   Selection();  // Empty selection.
 | 
					
						
							|  |  |  |   Selection(int start_x, int start_y, int end_x, int end_y); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const Box& GetBox() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Selection SaturateHorizontal(Box box); | 
					
						
							|  |  |  |   Selection SaturateVertical(Box box); | 
					
						
							|  |  |  |   bool IsEmpty() const { return empty_; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void AddPart(const std::string& part, int y, int left, int right); | 
					
						
							|  |  |  |   std::string GetParts() { return parts_.str(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   Selection(int start_x, int start_y, int end_x, int end_y, Selection* parent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const int start_x_ = 0; | 
					
						
							|  |  |  |   const int start_y_ = 0; | 
					
						
							|  |  |  |   const int end_x_ = 0; | 
					
						
							|  |  |  |   const int end_y_ = 0; | 
					
						
							|  |  |  |   const Box box_ = {}; | 
					
						
							| 
									
										
										
										
											2024-12-29 10:24:17 +01:00
										 |  |  |   Selection* const parent_ = this; | 
					
						
							|  |  |  |   const bool empty_ = true; | 
					
						
							| 
									
										
										
										
											2024-12-27 15:45:13 +07:00
										 |  |  |   std::stringstream parts_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // The position of the last inserted part.
 | 
					
						
							|  |  |  |   int x_ = 0; | 
					
						
							|  |  |  |   int y_ = 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace ftxui
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* end of include guard: FTXUI_DOM_SELECTION_HPP */
 |