39 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 40 #error "Only <final/final.h> can be included directly." 48 #include "final/output/foutput.h" 49 #include "final/output/tty/fterm.h" 50 #include "final/util/char_ringbuffer.h" 60 static Encoding encoding;
68 template <
typename T, std::
size_t Capacity>
77 explicit FCharBuffer (std::size_t initial_cap = 4096)
79 buffer.reserve(initial_cap);
82 inline void append (
const char* data, std::size_t len)
84 buffer.insert(buffer.end(), data, data + len);
87 inline auto appendUnicode (
wchar_t ucs) -> uInt32
89 return UTF8::encode(ucs, buffer);
92 inline auto data()
const noexcept ->
const char*
97 inline auto size()
const noexcept -> std::size_t
102 inline void expand (std::size_t addend)
104 buffer.resize(buffer.size() + addend);
107 inline void clear() noexcept
113 std::vector<char> buffer;
124 static constexpr std::size_t BUFFER_SIZE = 32
'768; // 32 KB 127 enum class OutputType : uInt8 // Output data type of the terminal 135 OutputType type{OutputType::String}; 138 TypeSlice() = default; 140 TypeSlice (OutputType t, uInt32 len) 147 using TypeSliceBuffer = FRingBuffer<TypeSlice, BUFFER_SIZE>; 149 FOutputBuffer() = default; 151 inline auto isEmpty() const noexcept -> bool 153 return slices.isEmpty(); 157 TypeSliceBuffer slices{}; 158 FCharBuffer data{2 * BUFFER_SIZE}; 162 //---------------------------------------------------------------------- 164 //---------------------------------------------------------------------- 166 class FTermOutput final : public FOutput 170 FTermOutput() = default; 172 explicit FTermOutput (const FVTerm&); 175 ~FTermOutput() noexcept override; 178 auto getClassName() const -> FString override; 179 auto getFTerm() noexcept -> FTerm&; 180 auto getColumnNumber() const -> std::size_t override; 181 auto getLineNumber() const -> std::size_t override; 182 auto getTabstop() const -> int override; 183 auto getMaxColor() const -> int override; 184 auto getEncoding() const -> Encoding override; 185 auto getKeyName (FKey) const -> FString override; 188 void setCursor (FPoint) override; 189 void setCursor (CursorMode) override; 190 void hideCursor (bool = true) override; 191 void showCursor() noexcept override; 192 void setTerminalSize (FSize) override; 193 auto setVGAFont() -> bool override; 194 auto setNewFont() -> bool override; 195 void setNonBlockingRead (bool = true) override; 198 auto isCursorHideable() const noexcept -> bool override; 199 auto isMonochron() const -> bool override; 200 auto isNewFont() const -> bool override; 201 auto isEncodable (const wchar_t&) const -> bool override; 202 auto isFlushTimeout() const noexcept -> bool override; 203 auto hasTerminalResized() const -> bool override; 204 auto allowsTerminalSizeManipulation() const -> bool override; 205 auto canChangeColorPalette() const -> bool override; 206 auto hasHalfBlockCharacter() const -> bool override; 207 auto hasShadowCharacter() const -> bool override; 208 auto areMetaAndArrowKeysSupported() const -> bool override; 211 void initTerminal (FVTerm::FTermRegion*) override; 212 void finishTerminal() override; 213 auto updateTerminal() -> bool override; 214 void detectTerminalSize() override; 215 void commitTerminalResize() override; 216 void initScreenSettings() override; 217 auto scrollTerminalForward() -> bool override; 218 auto scrollTerminalReverse() -> bool override; 219 void clearTerminalAttributes() override; 220 void clearTerminalState() override; 221 auto clearTerminal (wchar_t = L' ') -> bool override; 222 void flush() override; 223 void beep() const override; 229 FTermcap::TermcapString termcap; 233 enum class PrintState : uInt8 236 RepeatCharacterPrinted, 238 LineCompletelyPrinted 241 enum class Repetition : uInt8 248 enum class CursorMoved : bool { No, Yes }; 251 // Upper and lower flush limit 252 static constexpr uInt64 MIN_FLUSH_WAIT = 16'667;
253 static constexpr uInt64 MAX_FLUSH_WAIT = 200
'000; // 200.0 ms = 5 Hz 254 static constexpr uInt64 RESET_THRESHOLD = 400'000;
257 using clock = std::chrono::steady_clock;
258 using FChar_iterator = FVTerm::FTermRegion::FCharVec::iterator;
259 using FChar_const_iterator = FVTerm::FTermRegion::FCharVec::const_iterator;
262 auto getFSetPaletteRef() const & -> const FSetPalette& override;
266 auto isInputCursorInsideTerminal() const noexcept ->
bool;
267 auto isDefaultPaletteTheme() const ->
bool override;
268 void redefineColorPalette() override;
269 void restoreColorPalette() override;
270 void init_characterLengths();
271 void init_combined_character();
272 auto canClearToEOL (uInt, uInt) const ->
bool;
273 auto canClearLeadingWS (uInt&, uInt) const ->
bool;
274 auto canClearTrailingWS (uInt&, uInt) const ->
bool;
275 auto skipUnchangedCharacters (uInt&, uInt, uInt, FChar_iterator) ->
bool;
276 void printRange (uInt, uInt, uInt);
277 void replaceNonPrintableFullwidth (uInt, uInt,
FChar&) const noexcept;
278 void printCharacter (uInt&, uInt,
bool, const FChar_iterator&);
279 void printFullWidthCharacter (uInt&, uInt, const FChar_iterator&);
280 void printFullWidthPaddingCharacter (uInt&, uInt, const FChar_iterator&);
281 void printHalfCovertFullWidthCharacter (uInt, uInt, const FChar_iterator&);
282 void printEllipsis (uInt, uInt,
FChar&);
283 void skipPaddingCharacter (uInt&, uInt, const FChar&) const noexcept;
284 auto eraseCharacters (uInt&, uInt, uInt, const FChar_iterator&) -> PrintState;
285 auto repeatCharacter (uInt&, uInt, uInt, const FChar_iterator&) -> PrintState;
286 auto countRepetitions (FChar_const_iterator, uInt, uInt) const noexcept -> uInt;
287 auto canUseEraseCharacters (const FChar&, uInt) const noexcept ->
bool;
288 auto canUseCharacterRepetitions (const FChar&, uInt) const noexcept ->
bool;
289 auto getRepetitionType (const FChar&, uInt) const noexcept -> Repetition;
290 auto isFullWidthChar (const FChar&) const noexcept ->
bool;
291 auto isFullWidthPaddingChar (const FChar&) const noexcept ->
bool;
292 void cursorWrap() const noexcept;
293 void adjustCursorPosition (
FPoint&) const noexcept;
294 auto updateTerminalLine (uInt) ->
bool;
295 auto updateTerminalCursor() ->
bool;
296 void flushTimeAdjustment() noexcept;
297 void markAsPrinted (uInt, uInt) const noexcept;
298 void markAsPrinted (uInt, uInt, uInt) const noexcept;
299 void newFontChanges (FChar&) const;
300 void charsetChanges (FChar&) const;
301 void appendCharacter (const FChar_iterator&);
302 void appendCharacter_n (const FChar_iterator&, uInt);
303 void appendChar (FChar&);
304 void appendAttributes (FChar&);
305 void appendLowerRight (const FChar_iterator&);
306 void characterFilter (FChar&);
307 auto moveCursorLeft() -> CursorMoved;
308 void checkFreeBufferSize();
309 void appendOutputBuffer (const FTermControl&);
310 void appendOutputBuffer (
wchar_t);
311 void appendOutputBuffer (const UniChar&);
312 void appendOutputBuffer (
FOutputBuffer::OutputType, const
char*, uInt32);
318 std::shared_ptr<FOutputBuffer> output_buffer{};
319 std::shared_ptr<FPoint> term_pos{};
320 FChar term_attribute{};
321 bool cursor_hideable{
false};
322 bool combined_char_support{
false};
323 uInt erase_char_length{};
324 uInt repeat_char_length{};
325 uInt clr_bol_length{};
326 uInt clr_eol_length{};
327 uInt cursor_address_length{};
328 uInt64 time_last_flush_us{};
329 uInt64 flush_wait{MIN_FLUSH_WAIT};
330 uInt64 flush_average{MIN_FLUSH_WAIT};
331 uInt64 flush_median{MIN_FLUSH_WAIT};
336 inline auto FTermOutput::getClassName()
const ->
FString 337 {
return "FTermOutput"; }
340 inline auto FTermOutput::getFTerm() noexcept ->
FTerm&
344 inline auto FTermOutput::getColumnNumber()
const -> std::size_t
345 {
return FTerm::getColumnNumber(); }
348 inline auto FTermOutput::getLineNumber()
const -> std::size_t
349 {
return FTerm::getLineNumber(); }
352 inline auto FTermOutput::getTabstop()
const ->
int 353 {
return FTerm::getTabstop(); }
356 inline auto FTermOutput::getMaxColor()
const ->
int 357 {
return FTerm::getMaxColor(); }
360 inline auto FTermOutput::getEncoding()
const -> Encoding
361 {
return internal::terminal::encoding; }
364 inline auto FTermOutput::getKeyName (FKey keynum)
const ->
FString 365 {
return FTerm::getKeyName(keynum); }
368 inline void FTermOutput::showCursor() noexcept
369 {
return hideCursor(
false); }
372 inline void FTermOutput::setTerminalSize (
FSize size)
373 { FTerm::setTermSize(size); }
376 inline auto FTermOutput::setVGAFont() ->
bool 377 {
return FTerm::setVGAFont(); }
380 inline auto FTermOutput::setNewFont() ->
bool 381 {
return FTerm::setNewFont(); }
384 inline auto FTermOutput::isCursorHideable()
const noexcept ->
bool 385 {
return cursor_hideable; }
387 inline auto FTermOutput::isMonochron()
const ->
bool 388 {
return FTerm::isMonochron(); }
391 inline auto FTermOutput::isNewFont()
const ->
bool 392 {
return FTerm::isNewFont(); }
395 inline auto FTermOutput::isEncodable (
const wchar_t& wide_char)
const ->
bool 396 {
return FTerm::isEncodable(wide_char); }
399 inline auto FTermOutput::hasTerminalResized()
const ->
bool 400 {
return FTerm::hasChangedTermSize(); }
403 inline auto FTermOutput::allowsTerminalSizeManipulation()
const ->
bool 404 {
return fterm_data->isTermType(FTermType::xterm); }
407 inline auto FTermOutput::canChangeColorPalette()
const ->
bool 408 {
return FTerm::canChangeColorPalette(); }
411 inline auto FTermOutput::hasHalfBlockCharacter()
const ->
bool 412 {
return FTerm::hasHalfBlockCharacter(); }
415 inline auto FTermOutput::hasShadowCharacter()
const ->
bool 416 {
return FTerm::hasShadowCharacter(); }
419 inline auto FTermOutput::areMetaAndArrowKeysSupported()
const ->
bool 420 {
return ! fterm_data->isTermType(FTermType::linux_con); }
423 inline void FTermOutput::detectTerminalSize()
424 { FTerm::detectTermSize(); }
427 inline void FTermOutput::commitTerminalResize()
428 { FTerm::changeTermSizeFinished(); }
431 inline void FTermOutput::initScreenSettings()
432 { FTerm::initScreenSettings(); }
435 inline void FTermOutput::clearTerminalAttributes()
436 { FTerm::clearTerminalAttributes(); }
439 inline void FTermOutput::beep()
const 440 {
return FTerm::beep(); }
443 inline auto FTermOutput::getFSetPaletteRef()
const & ->
const FSetPalette&
445 static const FSetPalette& f = &FTerm::setPalette;
451 #endif // FTERMOUTPUT_H
Definition: class_template.cpp:25
Definition: ftypes.h:1081
Definition: ftermoutput.h:121
Definition: fstartoptions.h:52
Definition: ftermoutput.h:74
Definition: ftermdata.h:140
Definition: ftermoutput.h:69
Definition: ftermoutput.h:58