FINAL CUT
ftermxterminal.h
1 /***********************************************************************
2 * ftermxterminal.h - Contains all xterm-specific terminal functions *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2018-2024 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Standalone class
24  * ════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ FTermXTerminal ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FTERMXTERMINAL_H
32 #define FTERMXTERMINAL_H
33 
34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
35  #error "Only <final/final.h> can be included directly."
36 #endif
37 
38 #include "final/util/fstring.h"
39 
40 namespace finalcut
41 {
42 
43 // class forward declaration
44 class FSize;
45 
46 //----------------------------------------------------------------------
47 // class FTermXTerminal
48 //----------------------------------------------------------------------
49 
50 class FTermXTerminal final
51 {
52  public:
53  // Constructor
55 
56  // Mutators
57  void redefineDefaultColors (bool = true) noexcept;
58  void setCursorStyle (XTermCursorStyle);
59  void setFont (const FString&);
60  void setTitle (const FString&);
61  void setTermSize (const FSize&);
62  void setForeground (const FString&);
63  void setBackground (const FString&);
64  void setCursorColor (const FString&);
65  void setMouseForeground (const FString&);
66  void setMouseBackground (const FString&);
67  void setHighlightBackground (const FString&);
68  void setMouseSupport (bool = true);
69  void unsetMouseSupport();
70  void setFocusSupport (bool enable = true);
71  void unsetFocusSupport();
72  void metaSendsESC (bool = true);
73 
74  // Accessors
75  auto getClassName() const -> FString;
76  static auto getInstance() -> FTermXTerminal&;
77  auto getCursorStyle() const noexcept -> XTermCursorStyle;
78  auto getFont() const -> FString;
79  auto getTitle() const -> FString;
80  auto getForeground() const -> FString;
81  auto getBackground() const -> FString;
82  auto getCursorColor() const -> FString;
83  auto getMouseForeground() const -> FString;
84  auto getMouseBackground() const -> FString;
85  auto getHighlightBackground() const -> FString;
86 
87  // Inquiries
88  auto hasFont() const -> bool;
89  auto hasTitle() const -> bool;
90 
91  // Methods
92  void setDefaults();
93  void resetColorMap() const;
94  void resetForeground();
95  void resetBackground();
96  void resetCursorColor();
97  void resetMouseForeground();
98  void resetMouseBackground();
99  void resetHighlightBackground();
100  void resetDefaults();
101  void resetTitle();
102  void captureFontAndTitle();
103 
104  private:
105  // Methods
106  void warnNotInitialized() const;
107  auto canResetDefaults() const -> bool;
108  auto canCaptureFontAndTitle() const -> bool;
109  auto canSetXTermCursorStyle() const -> bool;
110  void setXTermCursorStyle();
111  auto canSetXTermTitle() const -> bool;
112  void setXTermTitle();
113  auto canSetXTermSize() const -> bool;
114  void setXTermSize() const;
115  auto canSetXTermFont() const -> bool;
116  void setXTermFont();
117  auto canSetXTermColor() const -> bool;
118  auto canSetXTermForeground() const -> bool;
119  void setXTermForeground();
120  auto canSetXTermBackground() const -> bool;
121  void setXTermBackground();
122  auto canSetXTermCursorColor() const -> bool;
123  void setXTermCursorColor();
124  auto canSetXTermMouseForeground() const -> bool;
125  void setXTermMouseForeground();
126  auto canSetXTermMouseBackground() const -> bool;
127  void setXTermMouseBackground();
128  auto canSetXTermHighlightBackground() const -> bool;
129  void setXTermHighlightBackground();
130  auto canSetXTermColors() const -> bool;
131  void setXTerm8ColorDefaults();
132  void setXTerm16ColorDefaults();
133  auto canSetXTermDefaultsMouseCursor() const -> bool;
134  void setXTermDefaultsMouseCursor();
135  auto needsFullReset() const -> bool;
136  auto canOnlyResetColorSeparately() const -> bool;
137  auto canResetColor() const -> bool;
138  void resetXTermColorMap() const;
139  void resetXTermForeground() const;
140  void resetXTermBackground() const;
141  void resetXTermCursorColor() const;
142  void resetXTermMouseForeground() const;
143  void resetXTermMouseBackground() const;
144  void resetXTermHighlightBackground() const;
145  void oscPrefix() const;
146  void oscPostfix() const;
147  auto canCaptureXTermFont() const -> bool;
148  auto captureXTermFont() const -> FString;
149  auto canCaptureXTermTitle() const -> bool;
150  auto captureXTermTitle() const -> FString;
151  void enableXTermMouse();
152  void disableXTermMouse();
153  void enableXTermFocus();
154  void disableXTermFocus();
155  auto canUseXTermMetaSendsESC() const -> bool;
156  void enableXTermMetaSendsESC();
157  void disableXTermMetaSendsESC();
158 
159  // Data members
160  bool mouse_support{false};
161  bool focus_support{false};
162  bool meta_sends_esc{false};
163  bool xterm_default_colors{false};
164  bool title_was_changed{false};
165  std::size_t term_width{80};
166  std::size_t term_height{24};
167  FString xterm_font{};
168  FString xterm_title{};
169  FString foreground_color{};
170  FString background_color{};
171  FString cursor_color{};
172  FString mouse_foreground_color{};
173  FString mouse_background_color{};
174  FString highlight_background_color{};
175  XTermCursorStyle cursor_style{XTermCursorStyle::UnknownCursorStyle};
176 };
177 
178 
179 // FTermXTerminal inline functions
180 //----------------------------------------------------------------------
181 inline auto FTermXTerminal::getClassName() const -> FString
182 { return "FTermXTerminal"; }
183 
184 //----------------------------------------------------------------------
185 inline void FTermXTerminal::redefineDefaultColors (bool enable) noexcept
186 { xterm_default_colors = enable; }
187 
188 //----------------------------------------------------------------------
189 inline auto FTermXTerminal::getCursorStyle() const noexcept -> XTermCursorStyle
190 { return cursor_style; }
191 
192 //----------------------------------------------------------------------
193 inline auto FTermXTerminal::getFont() const -> FString
194 { return xterm_font; }
195 
196 //----------------------------------------------------------------------
197 inline auto FTermXTerminal::getTitle() const -> FString
198 { return xterm_title; }
199 
200 //----------------------------------------------------------------------
201 inline auto FTermXTerminal::getForeground() const -> FString
202 { return foreground_color; }
203 
204 //----------------------------------------------------------------------
205 inline auto FTermXTerminal::getBackground() const -> FString
206 { return background_color; }
207 
208 //----------------------------------------------------------------------
209 inline auto FTermXTerminal::getCursorColor() const -> FString
210 { return cursor_color; }
211 
212 //----------------------------------------------------------------------
213 inline auto FTermXTerminal::getMouseForeground() const -> FString
214 { return mouse_foreground_color; }
215 
216 //----------------------------------------------------------------------
217 inline auto FTermXTerminal::getMouseBackground() const -> FString
218 { return mouse_background_color; }
219 
220 //----------------------------------------------------------------------
221 inline auto FTermXTerminal::getHighlightBackground() const -> FString
222 { return highlight_background_color; }
223 
224 //----------------------------------------------------------------------
225 inline auto FTermXTerminal::hasFont() const -> bool
226 { return xterm_font.getLength() > 2; }
227 
228 //----------------------------------------------------------------------
229 inline auto FTermXTerminal::hasTitle() const -> bool
230 { return xterm_title.getLength() > 0; }
231 
232 //----------------------------------------------------------------------
233 inline void FTermXTerminal::unsetMouseSupport()
234 { setMouseSupport (false); }
235 
236 //----------------------------------------------------------------------
237 inline void FTermXTerminal::unsetFocusSupport()
238 { setFocusSupport (false); }
239 
240 } // namespace finalcut
241 
242 #endif // FTERMXTERMINAL_H
Definition: class_template.cpp:25
Definition: fsize.h:55
Definition: ftermxterminal.h:50
Definition: fstring.h:79