46 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)    47   #error "Only <final/final.h> can be included directly."    60 #include "final/output/tty/fterm_functions.h"    61 #include "final/util/fdata.h"    62 #include "final/util/fpoint.h"    63 #include "final/util/frect.h"    64 #include "final/util/fsize.h"    65 #include "final/util/fstringstream.h"    66 #include "final/vterm/fvtermattribute.h"    67 #include "final/vterm/fvtermbuffer.h"    69 #define F_PREPROC_HANDLER(i,h) \    70     reinterpret_cast<FVTerm*>((i)), \    71     std::bind ( reinterpret_cast<FVTerm::FPreprocessingHandler>((h)) \    72               , reinterpret_cast<FVTerm*>((i)) )    86 template <
typename FOutputType>
    89   using type = std::remove_cv_t<FOutputType>;
   110     using FVTermAttribute::print;
   111     using FCharVector = std::vector<FChar>;
   112     using FPreprocessingHandler = void (
FVTerm::*)();
   113     using FPreprocessingFunction = std::function<void()>;
   114     using FPreprocVector = std::vector<std::unique_ptr<FVTermPreprocessing>>;
   115     using FVTermList = std::vector<FVTerm*>;
   118     enum class TerminalUpdate
   134     template <
typename FOutputType>
   141     auto operator = (
FVTerm&&) noexcept -> 
FVTerm& = 
delete;
   147     template <
typename NumT
   148             , enable_if_arithmetic_without_char_t<NumT> = 
nullptr>
   149     auto operator << (
const NumT&) noexcept -> 
FVTerm&;
   151     template <
typename CharT
   152             , enable_if_CString_t<CharT> = 
nullptr>
   153     auto operator << (
const CharT&) noexcept -> 
FVTerm&;
   154     auto operator << (
char) noexcept -> 
FVTerm&;
   155     auto operator << (
wchar_t) noexcept -> 
FVTerm&;
   156     auto operator << (
const wchar_t*) noexcept -> 
FVTerm&;
   157     auto operator << (
const UniChar&) noexcept -> 
FVTerm&;
   158     auto operator << (
const std::string&) noexcept -> 
FVTerm&;
   159     auto operator << (
const std::wstring&) noexcept -> 
FVTerm&;
   163     auto operator << (
const FChar&) noexcept -> 
FVTerm&;
   164     auto operator << (
const FCharVector&) noexcept -> 
FVTerm&;
   170     auto  getClassName() 
const -> 
FString override;
   171     static auto  getFOutput() -> std::shared_ptr<FOutput>;
   173     auto  getVWin() 
const noexcept -> 
const FTermArea*;
   174     auto  getPrintCursor() -> 
FPoint;
   175     static auto  getWindowList() -> FVTermList*;
   178     void  setTerminalUpdates (TerminalUpdate) 
const;
   179     void  setCursor (
const FPoint&) noexcept;
   180     void  setVWin (std::unique_ptr<FTermArea>&&) noexcept;
   181     static void  setNonBlockingRead (
bool = 
true);
   182     static void  unsetNonBlockingRead();
   185     static auto  isDrawingFinished() noexcept -> bool;
   186     static auto  isTerminalUpdateForced() noexcept -> bool;
   187     static auto  areTerminalUpdatesPaused() noexcept -> bool;
   188     static auto  hasPendingTerminalUpdates() noexcept -> bool;
   189     auto hasPreprocessingHandler (
const FVTerm*) noexcept -> bool;
   192     virtual void clearArea (
wchar_t = L
' ');
   193     void  createVDesktop (
const FSize& size) noexcept;
   194     void  createVTerm (
const FSize&) noexcept;
   195     void  resizeVTerm (
const FSize&) 
const noexcept;
   196     void  putVTerm() 
const;
   197     auto  updateTerminal() 
const -> bool;
   198     static void reduceTerminalLineUpdates (uInt);
   199     virtual void addPreprocessingHandler ( 
const FVTerm*
   200                                          , FPreprocessingFunction&& );
   201     virtual void delPreprocessingHandler (
const FVTerm*);
   202     auto  interpretControlCodes (
FTermArea*, 
const FChar&) 
const noexcept -> bool;
   203     template <
typename... Args>
   204     auto  printf (
const FString&, Args&&...) noexcept -> int;
   205     auto  print (
const FString&) noexcept -> int;
   207     auto  print (
const std::vector<FChar>&) noexcept -> int;
   208     auto  print (
FTermArea*, 
const std::vector<FChar>&) noexcept -> int;
   213     auto  print (
wchar_t) noexcept -> int;
   214     auto  print (
FTermArea*, 
wchar_t) noexcept -> int;
   215     auto  print (
const FChar&) noexcept -> int;
   217     virtual void print (
const FPoint&);
   218     auto  print() & -> 
FVTerm&;
   229     virtual auto getPrintArea() -> 
FTermArea*;
   230     auto  getChildPrintArea() 
const -> 
FTermArea*;
   231     auto  getCurrentPrintArea() 
const -> 
FTermArea*;
   232     auto  getVirtualDesktop() 
const -> 
FTermArea*;
   233     auto  getVirtualTerminal() 
const -> 
FTermArea*;
   241     auto  isActive (
const FTermArea*) 
const -> bool;
   242     auto  hasPrintArea() 
const -> bool;
   243     auto  hasChildPrintArea() 
const -> bool;
   244     auto  isVirtualWindow() 
const -> bool;
   245     auto  isCursorHideable() 
const -> bool;
   248     auto  createArea (
const FShadowBox&) -> std::unique_ptr<FTermArea>;
   249     auto  createArea (
const FRect&) -> std::unique_ptr<FTermArea>;
   252     void  restoreVTerm (
const FRect&) 
const noexcept;
   253     auto  updateVTermCursor (
const FTermArea*) 
const noexcept -> bool;
   254     void  hideVTermCursor() 
const;
   258     void  addLayer (
FTermArea*) 
const noexcept;
   261     static auto  getLayer (
FVTerm&) noexcept -> int;
   262     static void  determineWindowLayers() noexcept;
   265     void  clearArea (
FTermArea*, 
wchar_t = L
' ') noexcept;
   266     void  forceTerminalUpdate() 
const;
   267     auto  processTerminalUpdate() 
const -> bool;
   268     static void  startDrawing() noexcept;
   269     static void  finishDrawing() noexcept;
   270     virtual void initTerminal();
   274     static constexpr 
int DEFAULT_MINIMIZED_HEIGHT = 1;
   277     enum class CoveredState
   285     static void setGlobalFVTermInstance (
FVTerm* ptr);
   286     static auto getGlobalFVTermInstance() -> 
FVTerm*&;
   287     static auto isInitialized() -> bool;
   288     void  resetAreaEncoding() 
const;
   289     void  resetTextAreaToDefault (
FTermArea*, 
const FSize&) 
const noexcept;
   290     auto  resizeTextArea (
FTermArea*, std::size_t, std::size_t ) 
const -> bool;
   291     auto  resizeTextArea (
FTermArea*, std::size_t) 
const -> bool;
   292     auto  isCovered (
const FPoint&, 
const FTermArea*) 
const noexcept -> CoveredState;
   293     auto  isAreaValid (
const FShadowBox&) 
const -> bool;
   295     constexpr 
auto  needsHeightResize (
const FTermArea*, 
const std::size_t) 
const noexcept -> bool;
   296     constexpr 
auto  needsWidthResize (
const FTermArea*, 
const std::size_t) 
const noexcept -> bool;
   297     auto  tryResizeArea (
FTermArea*, 
const std::size_t, 
const std::size_t) 
const -> bool;
   299     constexpr 
auto  getFullAreaWidth (
const FTermArea*) 
const noexcept -> int;
   300     constexpr 
auto  getFullAreaHeight (
const FTermArea*) 
const noexcept -> int;
   301     void  passChangesToOverlap (
const FTermArea*) 
const;
   304     int   calculateStartCoordinate (
int, 
int) 
const noexcept;
   305     int   calculateEndCoordinate (
int, 
int, 
int, 
int) 
const noexcept;
   306     void  restoreOverlaidWindows (
const FTermArea* area) 
const noexcept;
   307     void  updateVTerm() 
const;
   308     void  scrollTerminalForward() 
const;
   309     void  scrollTerminalReverse() 
const;
   310     void  callPreprocessingHandler (
const FTermArea*) 
const;
   311     auto  hasChildAreaChanges (
const FTermArea*) 
const -> bool;
   312     void  clearChildAreaChanges (
const FTermArea*) 
const;
   314     auto  isFCharTransparent (
const FChar&) 
const -> bool;
   315     auto  isTransparentInvisible (
const FChar&) 
const -> bool;
   316     static void defineByte1TransparentMask();
   317     template <
typename FOutputType>
   321     void  saveCurrentVTerm() 
const;
   322     void  putAreaLine (
const FChar&, 
FChar&, 
const std::size_t) 
const;
   323     void  putAreaLineWithTransparency (
const FChar*, 
FChar*, 
const int, 
FPoint) 
const;
   324     void  putTransparentAreaLine (
const FPoint&, 
const std::size_t) 
const;
   325     void  addAreaLineWithTransparency (
const FChar*, 
FChar*, 
const std::size_t) 
const;
   326     void  addTransparentAreaLine (
const FChar&, 
FChar&, 
const std::size_t) 
const;
   327     void  addTransparentAreaChar (
const FChar&, 
FChar&) 
const;
   329     void  clearAreaWithShadow (
FTermArea*, 
const FChar&) 
const noexcept;
   330     auto  printWrap (
FTermArea*) 
const -> bool;
   331     auto  getByte1PrintTransMask() 
const -> uInt8;
   332     auto  changedToTransparency (
const FChar&, 
const FChar&) 
const -> bool;
   333     auto  changedFromTransparency (
const FChar&, 
const FChar&) 
const -> bool;
   334     auto  printCharacterOnCoordinate ( 
FTermArea*
   335                                      , 
const FChar&) 
const noexcept -> std::size_t;
   337     void  putNonTransparent (std::size_t&, 
const FChar*, 
FChar*&) 
const;
   338     void  addTransparent (std::size_t&, 
const FChar*, 
FChar*&) 
const;
   339     void  putTransparent (std::size_t&, 
const FPoint&, 
FChar*&) 
const;
   340     auto  isInsideTerminal (
const FPoint&) 
const noexcept -> bool;
   341     auto  canUpdateTerminalNow() 
const -> bool;
   342     static auto hasPendingUpdates (
const FTermArea*) noexcept -> bool;
   349     std::unique_ptr<FTermArea>   vwin{};                     
   350     std::shared_ptr<FOutput>     foutput{};                  
   351     std::shared_ptr<FVTermList>  window_list{};              
   352     std::shared_ptr<FTermArea>   vterm{};                    
   353     std::shared_ptr<FTermArea>   vterm_old{};                
   354     std::shared_ptr<FTermArea>   vdesktop{};                 
   356     static uInt8                 b1_print_trans_mask;        
   358     static bool                  draw_completed;
   359     static bool                  skip_one_vterm_update;
   360     static bool                  no_terminal_updates;
   361     static bool                  force_terminal_update;
   365     friend auto getColumnWidth (
const wchar_t wchar) -> std::size_t;
   376   using FDataAccessPtr  = std::shared_ptr<FDataAccess>;
   377   using FLineChangesPtr = std::vector<FLineChanges>;
   378   using FCharPtr        = std::vector<FChar>;
   392   template <
typename T>
   393   inline auto getOwner() 
const -> clean_fdata_t<T>&
   398   template <
typename T>
   399   inline void setOwner (T&& obj)
   401     owner.reset(makeFData(std::forward<T>(obj)));
   404   inline auto hasOwner() 
const -> 
bool   406     return owner.get() != 
nullptr;
   409   auto contains (
const FPoint&) 
const noexcept -> bool;
   410   auto isOverlapped (
const FRect&) 
const noexcept -> bool;
   411   auto isOverlapped (
const FTermArea*) 
const noexcept -> bool;
   412   auto checkPrintPos() 
const noexcept -> bool;
   413   auto reprint (
const FRect&, 
const FSize&) noexcept -> bool;
   415   inline auto getFChar (
int x, 
int y) 
const noexcept -> 
const FChar&
   417     return data[unsigned(y) * unsigned(size.width + shadow.width) + unsigned(x)];
   420   inline auto getFChar (
int x, 
int y) noexcept -> 
FChar&
   422     return data[unsigned(y) * unsigned(size.width + shadow.width) + unsigned(x)];
   425   inline auto getFChar (
const FPoint& pos) 
const noexcept -> 
const FChar&
   427     return getFChar(pos.getX(), pos.getY());
   430   inline auto getFChar (
const FPoint& pos) noexcept -> 
FChar&
   432     return getFChar(pos.getX(), pos.getY());
   435   inline void setCursorPos (
int x, 
int y) noexcept
   441   inline void setInputCursorPos (
int x, 
int y) noexcept
   447   template <
typename T>
   448   inline auto print (T&& term_data) -> 
int   451       return getOwner<FVTerm*>()->print (
this, std::forward<T>(term_data));
   476   Encoding        encoding{Encoding::Unknown};
   477   bool            input_cursor_visible{
false};
   478   bool            has_changes{
false};
   480   bool            minimized{
false};
   481   FDataAccessPtr  owner{
nullptr};        
   482   FPreprocVector  preproc_list{};
   483   FLineChangesPtr changes{};
   488 inline auto FVTerm::FTermArea::contains (
const FPoint& pos) 
const noexcept -> 
bool   492   const int current_height = minimized ? min_size.height : size.height + shadow.height;
   493   const int x = pos.getX();
   494   const int y = pos.getY();
   495   return x >= position.x
   496       && x < position.x + size.width + shadow.width
   498       && y < position.y + current_height;
   502 inline auto FVTerm::FTermArea::isOverlapped (
const FRect& box) 
const noexcept -> 
bool   504   const int current_height = minimized ? min_size.height
   505                                        : size.height + shadow.height;
   506   const int x1 = position.x;
   507   const int x2 = position.x + size.width + shadow.width - 1;
   508   const int y1 = position.y;
   509   const int y2 = position.y + current_height - 1;
   511   return ( std::max(x1, box.getX1() - 1) <= std::min(x2, box.getX2() - 1)
   512         && std::max(y1, box.getY1() - 1) <= std::min(y2, box.getY2() - 1) );
   516 inline auto FVTerm::FTermArea::isOverlapped (
const FTermArea* area) 
const noexcept -> 
bool   518   const int current_height = minimized ? min_size.height
   519                                        : size.height + shadow.height;
   520   const int x1 = position.x;
   521   const int x2 = position.x + size.width + shadow.width - 1;
   522   const int y1 = position.y;
   523   const int y2 = position.y + current_height - 1;
   525   const int area_current_height = area->minimized ? area->min_size.height
   526                                                   : area->size.height + area->shadow.height;
   527   const int area_x1 = area->position.x;
   528   const int area_x2 = area->position.x + area->size.width + area->shadow.width - 1;
   529   const int area_y1 = area->position.y;
   530   const int area_y2 = area->position.y + area_current_height - 1;
   532   return ( std::max(x1, area_x1) <= std::min(x2, area_x2)
   533         && std::max(y1, area_y1) <= std::min(y2, area_y2) );
   537 inline auto FVTerm::FTermArea::checkPrintPos() 
const noexcept -> 
bool   541       && cursor.x <= size.width + shadow.width
   542       && cursor.y <= size.height + shadow.height;
   547 inline auto FVTerm::FTermArea::reprint (
const FRect& box, 
const FSize& term_size) noexcept -> 
bool   549   if ( ! isOverlapped(box) )
   552   const int x_pos = box.getX() - 1;
   553   const int y_pos = box.getY() - 1;
   554   const auto w = int(box.getWidth());
   555   const auto h = int(box.getHeight());
   557   if ( w == 0 || h == 0 )
   561   const int y_start = std::max(0, std::max(y_pos, position.y)) - position.y;
   562   const int box_y2 = y_pos + h - 1;
   563   const int current_height = minimized ? min_size.height : size.height + shadow.height;
   564   const int y2 = position.y + current_height - 1;
   565   const int y_end = std::min(
int(term_size.getHeight()) - 1, std::min(box_y2, y2)) - position.y;
   567   for (
auto y{y_start}; y <= y_end; y++)  
   569     const int x_start = std::max(0, std::max(x_pos, position.x)) - position.x;
   570     const int box_x2 = x_pos + w - 1;
   571     const int x2 = position.x + size.width + shadow.width - 1;
   572     const int x_end = std::min(
int(term_size.getWidth()) - 1 , std::min(box_x2, x2)) - position.x;
   573     auto& line_changes = changes[std::size_t(y)];
   574     line_changes.xmin = uInt(std::min(
int(line_changes.xmin), x_start));
   575     line_changes.xmax = uInt(std::max(
int(line_changes.xmax), x_end));
   587   void operator () (
const FVTerm*) 
const noexcept
   597     : instance(std::unique_ptr<const FVTerm, D>(i))
   598     , 
function(std::move(f))
   607   std::unique_ptr<const FVTerm, D> instance{};
   608   FPreprocessingFunction 
function{};
   614 template <
typename FOutputType>
   617   init<typename outputClass<FOutputType>::type>();
   621 template <
typename NumT
   622         , enable_if_arithmetic_without_char_t<NumT>>
   623 inline auto FVTerm::operator << (
const NumT& n) noexcept -> 
FVTerm&
   625   print (
FString(std::to_string(n)));
   630 template <
typename CharT
   631         , enable_if_CString_t<CharT>>
   632 inline auto FVTerm::operator << (
const CharT& s) noexcept -> 
FVTerm&
   639 inline auto FVTerm::operator << (
char c) noexcept -> 
FVTerm&
   641   print (
wchar_t(uChar(c)));
   646 inline auto FVTerm::operator << (
wchar_t c) noexcept -> 
FVTerm&
   653 inline auto FVTerm::operator << (
const wchar_t* wide_string) noexcept -> 
FVTerm&
   660 inline auto FVTerm::operator << (
const UniChar& c) noexcept -> 
FVTerm&
   662   print (static_cast<wchar_t>(c));  
   667 inline auto FVTerm::operator << (
const std::string& 
string) noexcept -> 
FVTerm&
   674 inline auto FVTerm::operator << (
const std::wstring& wide_string) noexcept -> 
FVTerm&
   681 inline auto FVTerm::operator << (
const FString& fstring) noexcept -> 
FVTerm&
   688 inline auto FVTerm::operator << (
const FChar& fchar) noexcept -> 
FVTerm&
   695 inline auto FVTerm::operator << (
const FCharVector& term_string) noexcept -> 
FVTerm&
   702 inline auto FVTerm::operator << (
const FPoint& pos) noexcept -> 
FVTerm&
   709 inline auto FVTerm::operator << (
const FStyle& t_style) noexcept -> 
FVTerm&
   716 inline auto FVTerm::operator << (
const FColorPair& pair) noexcept -> 
FVTerm&
   723 inline auto FVTerm::getClassName() 
const -> 
FString   727 inline auto FVTerm::getVWin() noexcept -> 
FTermArea*
   728 { 
return vwin.get(); }
   731 inline auto FVTerm::getVWin() 
const noexcept -> 
const FTermArea*
   732 { 
return vwin.get(); }
   735 inline auto FVTerm::getWindowList() -> FVTermList*
   737   static const auto& init_object = getGlobalFVTermInstance();
   738   return (isInitialized() && init_object->window_list)
   739         ? init_object->window_list.get()
   744 inline void FVTerm::setVWin (std::unique_ptr<FTermArea>&& area) noexcept
   745 { vwin = std::move(area); }
   748 inline void FVTerm::unsetNonBlockingRead()
   749 { setNonBlockingRead(
false); }
   752 inline auto FVTerm::isDrawingFinished() noexcept -> 
bool   753 { 
return draw_completed; }
   756 inline auto FVTerm::isTerminalUpdateForced() noexcept -> 
bool   757 { 
return force_terminal_update; }
   760 inline auto FVTerm::areTerminalUpdatesPaused() noexcept -> 
bool   761 { 
return no_terminal_updates; }
   764 inline auto FVTerm::hasPendingTerminalUpdates() noexcept -> 
bool   765 { 
return hasPendingUpdates(getGlobalFVTermInstance()->vterm.get()); }
   768 template <
typename... Args>
   769 auto FVTerm::printf (
const FString& format, Args&&... args) noexcept -> 
int   772   str.sprintf (format, std::forward<Args>(args)...);
   777 inline auto FVTerm::print() & -> 
FVTerm&
   781 inline void FVTerm::print (
const FPoint& p)
   787 inline auto FVTerm::getChildPrintArea() 
const -> 
FTermArea*
   788 { 
return child_print_area; }
   791 inline auto FVTerm::getCurrentPrintArea() 
const -> 
FTermArea*
   792 { 
return print_area; }
   795 inline auto FVTerm::getVirtualDesktop() 
const -> 
FTermArea*
   796 { 
return vdesktop.get(); }
   799 inline auto FVTerm::getVirtualTerminal() 
const -> 
FTermArea*
   800 { 
return vterm.get(); }
   803 inline void FVTerm::setPrintArea (
FTermArea* area)
   804 { print_area = area; }
   807 inline void FVTerm::setChildPrintArea (
FTermArea* area)
   808 { child_print_area = area; }
   811 inline void FVTerm::setActiveArea (
FTermArea* area)
 const   812 { active_area = area; }
   815 inline auto FVTerm::isActive (
const FTermArea* area) 
const -> 
bool   816 { 
return area == active_area; }
   819 inline auto FVTerm::hasPrintArea() 
const -> 
bool   820 { 
return print_area; }
   823 inline auto FVTerm::hasChildPrintArea() 
const -> 
bool   824 { 
return child_print_area; }
   827 inline auto FVTerm::isVirtualWindow() 
const -> 
bool   828 { 
return vwin.get(); }
   831 inline void FVTerm::hideVTermCursor()
 const   832 { vterm->input_cursor_visible = 
false; }
   835 inline auto FVTerm::getLayer (
FVTerm& obj) noexcept -> 
int   838   return obj.FVTerm::getPrintArea()->layer;
   842 template <
typename FOutputType>
   843 inline void FVTerm::init()
   845   if ( ! isInitialized() )
   847     setGlobalFVTermInstance(
this);
   848     defineByte1TransparentMask();
   849     b1_print_trans_mask = getByte1PrintTransMask();
   850     foutput     = std::make_shared<FOutputType>(*this);
   851     window_list = std::make_shared<FVTermList>();
   856     static const auto& init_object = getGlobalFVTermInstance();
   857     foutput     = std::shared_ptr<FOutput>(init_object->foutput);
   858     window_list = std::shared_ptr<FVTermList>(init_object->window_list);
   859     vterm       = std::shared_ptr<FTermArea>(init_object->vterm);
   860     vterm_old   = std::shared_ptr<FTermArea>(init_object->vterm_old);
   861     vdesktop    = std::shared_ptr<FTermArea>(init_object->vdesktop);
 
Definition: fvtermbuffer.h:56
 
Definition: class_template.cpp:25
 
Definition: fcolorpair.h:49
 
Definition: fvtermattribute.h:53