FINAL CUT
foutput.h
1 /***********************************************************************
2 * foutput.h - Abstract Virtual terminal output class *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2021-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  * ▕ FOutput ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FOUTPUT_H
32 #define FOUTPUT_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 <memory>
39 
40 #include "final/fc.h"
41 #include "final/ftypes.h"
42 #include "final/output/fcolorpalette.h"
43 #include "final/vterm/fvterm.h"
44 
45 // Fixes problem with -Weffc++, because the base class
46 // std::enable_shared_from_this has a non-virtual destructor
47 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
48 
49 namespace finalcut
50 {
51 
52 //----------------------------------------------------------------------
53 // class FOutput
54 //----------------------------------------------------------------------
55 
56 class FOutput : public std::enable_shared_from_this<FOutput>
57 {
58  public:
59  // Using-declarations
60  using FSetPalette = FColorPalette::FSetPalette;
61 
62  // Constructor
63  FOutput() = default;
64 
65  explicit FOutput (const FVTerm& t)
66  : fvterm{t}
67  { }
68 
69  // Destructor
70  virtual ~FOutput() noexcept;
71 
72  // Accessors
73  virtual auto getClassName() const -> FString;
74  auto getInstance() -> std::shared_ptr<FOutput>;
75  auto getFVTerm() const & -> const FVTerm&;
76  virtual auto getColumnNumber() const -> std::size_t = 0;
77  virtual auto getLineNumber() const -> std::size_t = 0;
78  virtual auto getTabstop() const -> int = 0;
79  virtual auto getMaxColor() const -> int = 0;
80  virtual auto getEncoding() const -> Encoding = 0;
81  virtual auto getKeyName (FKey) const -> FString = 0;
82 
83  // Mutators
84  virtual void setCursor (FPoint) = 0;
85  virtual void setCursor (CursorMode) = 0;
86  virtual void hideCursor (bool = true) = 0;
87  virtual void showCursor() = 0;
88  virtual void setTerminalSize (FSize) = 0;
89  virtual auto setVGAFont() -> bool = 0;
90  virtual auto setNewFont() -> bool = 0;
91  virtual void setNonBlockingRead (bool = true) = 0;
92  template <typename ClassT>
93  void setColorPaletteTheme() const;
94  template <typename ClassT>
95  void setColorPaletteTheme (const FSetPalette&) const;
96 
97  // Inquiries
98  virtual auto isCursorHideable() const -> bool = 0;
99  virtual auto isMonochron() const -> bool = 0;
100  virtual auto isNewFont() const -> bool = 0;
101  virtual auto isEncodable (const wchar_t&) const -> bool = 0;
102  virtual auto isFlushTimeout() const -> bool = 0;
103  virtual auto hasTerminalResized() const -> bool = 0;
104  virtual auto allowsTerminalSizeManipulation() const -> bool = 0;
105  virtual auto canChangeColorPalette() const -> bool = 0;
106  virtual auto hasHalfBlockCharacter() const -> bool = 0;
107  virtual auto hasShadowCharacter() const -> bool = 0;
108  virtual auto areMetaAndArrowKeysSupported() const -> bool = 0;
109 
110  // Methods
111  virtual void initTerminal (FVTerm::FTermArea*) = 0;
112  virtual void finishTerminal() = 0;
113  virtual auto updateTerminal() -> bool = 0;
114  virtual void detectTerminalSize() = 0;
115  virtual void commitTerminalResize() = 0;
116  virtual void initScreenSettings() = 0;
117  virtual auto scrollTerminalForward() -> bool = 0;
118  virtual auto scrollTerminalReverse() -> bool = 0;
119  virtual void clearTerminalAttributes() = 0;
120  virtual void clearTerminalState() = 0;
121  virtual auto clearTerminal (wchar_t = L' ') -> bool = 0;
122  virtual void flush() = 0;
123  virtual void beep() const = 0;
124 
125  private:
126  // Accessors
127  virtual auto getFSetPaletteRef() const & -> const FSetPalette& = 0;
128 
129  // Methods
130  virtual auto isDefaultPaletteTheme() const -> bool = 0;
131  virtual void redefineColorPalette() = 0;
132  virtual void restoreColorPalette() = 0;
133 
134  // Data members
135  const FVTerm& fvterm{};
136 };
137 
138 // FOutput inline functions
139 //----------------------------------------------------------------------
140 inline auto FOutput::getClassName() const -> FString
141 { return "FOutput"; }
142 
143 //----------------------------------------------------------------------
144 inline auto FOutput::getFVTerm() const & -> const FVTerm&
145 { return fvterm; }
146 
147 //----------------------------------------------------------------------
148 template <typename ClassT>
149 inline void FOutput::setColorPaletteTheme() const
150 {
151  const auto& set_Palette = getFSetPaletteRef();
152  setColorPaletteTheme<ClassT>(set_Palette);
153 }
154 
155 //----------------------------------------------------------------------
156 template <typename ClassT>
157 inline void FOutput::setColorPaletteTheme (const FSetPalette& f) const
158 {
159  // Set instance
160  FColorPalette::getInstance() = std::make_shared<ClassT>(f);
161  // Set palette
162  FColorPalette::getInstance()->setColorPalette();
163 }
164 
165 } // namespace finalcut
166 
167 #endif // FOUTPUT_H
168 
Definition: foutput.h:56
Definition: fvterm.h:96
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fsize.h:55
Definition: fstring.h:79
Definition: fvterm.h:373