mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-11-01 02:58:12 +08:00 
			
		
		
		
	Enable raw keyboard input (#832)
In order for applications to receive all keyboard inputs, including the Ctrl-C and Ctrl-Z, the raw input mode has been enabled. As result the SIGINT will no longer be used, instead the keyboard Ctrl-C event is used for exiting the framework, but only if no components has made use of it. Co-authored-by: Jørn Gustav Larsen <jgl@fasttracksoftware.com> Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
		 Jørn Gustav Larsen
					Jørn Gustav Larsen
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							d38b14ffb6
						
					
				
				
					commit
					d386df6f94
				
			| @@ -54,21 +54,52 @@ struct Event { | ||||
|   static const Event Escape; | ||||
|   static const Event Tab; | ||||
|   static const Event TabReverse; | ||||
|   static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12; | ||||
|  | ||||
|   // --- Navigation keys --- | ||||
|   static const Event Insert; | ||||
|   static const Event Home; | ||||
|   static const Event End; | ||||
|  | ||||
|   static const Event PageUp; | ||||
|   static const Event PageDown; | ||||
|  | ||||
|   // --- Function keys --- | ||||
|   static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12; | ||||
|  | ||||
|   // --- Control keys --- | ||||
|   static const Event a, A, CtrlA, AltA, CtrlAltA; | ||||
|   static const Event b, B, CtrlB, AltB, CtrlAltB; | ||||
|   static const Event c, C, CtrlC, AltC, CtrlAltC; | ||||
|   static const Event d, D, CtrlD, AltD, CtrlAltD; | ||||
|   static const Event e, E, CtrlE, AltE, CtrlAltE; | ||||
|   static const Event f, F, CtrlF, AltF, CtrlAltF; | ||||
|   static const Event g, G, CtrlG, AltG, CtrlAltG; | ||||
|   static const Event h, H, CtrlH, AltH, CtrlAltH; | ||||
|   static const Event i, I, CtrlI, AltI, CtrlAltI; | ||||
|   static const Event j, J, CtrlJ, AltJ, CtrlAltJ; | ||||
|   static const Event k, K, CtrlK, AltK, CtrlAltK; | ||||
|   static const Event l, L, CtrlL, AltL, CtrlAltL; | ||||
|   static const Event m, M, CtrlM, AltM, CtrlAltM; | ||||
|   static const Event n, N, CtrlN, AltN, CtrlAltN; | ||||
|   static const Event o, O, CtrlO, AltO, CtrlAltO; | ||||
|   static const Event p, P, CtrlP, AltP, CtrlAltP; | ||||
|   static const Event q, Q, CtrlQ, AltQ, CtrlAltQ; | ||||
|   static const Event r, R, CtrlR, AltR, CtrlAltR; | ||||
|   static const Event s, S, CtrlS, AltS, CtrlAltS; | ||||
|   static const Event t, T, CtrlT, AltT, CtrlAltT; | ||||
|   static const Event u, U, CtrlU, AltU, CtrlAltU; | ||||
|   static const Event v, V, CtrlV, AltV, CtrlAltV; | ||||
|   static const Event w, W, CtrlW, AltW, CtrlAltW; | ||||
|   static const Event x, X, CtrlX, AltX, CtrlAltX; | ||||
|   static const Event y, Y, CtrlY, AltY, CtrlAltY; | ||||
|   static const Event z, Z, CtrlZ, AltZ, CtrlAltZ; | ||||
|  | ||||
|   // --- Custom --- | ||||
|   static const Event Custom; | ||||
|  | ||||
|   //--- Method section --------------------------------------------------------- | ||||
|   bool operator==(const Event& other) const { return input_ == other.input_; } | ||||
|   bool operator!=(const Event& other) const { return !operator==(other); } | ||||
|   bool operator<(const Event& other) const { return input_ < other.input_; } | ||||
|  | ||||
|   const std::string& input() const { return input_; } | ||||
|  | ||||
| @@ -86,6 +117,9 @@ struct Event { | ||||
|   bool is_cursor_shape() const { return type_ == Type::CursorShape; } | ||||
|   int cursor_shape() const { return data_.cursor_shape; } | ||||
|  | ||||
|   // Debug | ||||
|   std::string DebugString() const; | ||||
|  | ||||
|   //--- State section ---------------------------------------------------------- | ||||
|   ScreenInteractive* screen_ = nullptr; | ||||
|  | ||||
|   | ||||
| @@ -16,6 +16,8 @@ struct Mouse { | ||||
|     None = 3, | ||||
|     WheelUp = 4, | ||||
|     WheelDown = 5, | ||||
|     WheelLeft = 6,   /// Supported terminal only. | ||||
|     WheelRight = 7,  /// Supported terminal only. | ||||
|   }; | ||||
|  | ||||
|   enum Motion { | ||||
|   | ||||
| @@ -59,6 +59,15 @@ class ScreenInteractive : public Screen { | ||||
|   // temporarily uninstalled. | ||||
|   Closure WithRestoredIO(Closure); | ||||
|  | ||||
|   // FTXUI implements handlers for Ctrl-C and Ctrl-Z. By default, these handlers | ||||
|   // are executed, even if the component catches the event. This avoid users | ||||
|   // handling every event to be trapped in the application. However, in some | ||||
|   // cases, the application may want to handle these events itself. In this | ||||
|   // case, the application can force FTXUI to not handle these events by calling | ||||
|   // the following functions with force=true. | ||||
|   void ForceHandleCtrlC(bool force); | ||||
|   void ForceHandleCtrlZ(bool force); | ||||
|  | ||||
|  private: | ||||
|   void ExitNow(); | ||||
|  | ||||
| @@ -114,6 +123,9 @@ class ScreenInteractive : public Screen { | ||||
|  | ||||
|   bool frame_valid_ = false; | ||||
|  | ||||
|   bool force_handle_ctrl_c_ = true; | ||||
|   bool force_handle_ctrl_z_ = true; | ||||
|  | ||||
|   // The style of the cursor to restore on exit. | ||||
|   int cursor_reset_shape_ = 1; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user