Skip to content

Commit

Permalink
Reorganize the data structure of FVTerm::FTermArea
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Oct 25, 2023
1 parent b5b232a commit a2bf66e
Show file tree
Hide file tree
Showing 13 changed files with 569 additions and 566 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2023-10-25 Markus Gans <guru.mail@muenster.de>
* Reorganize the data structure of FVTerm::FTermArea

2023-10-23 Markus Gans <guru.mail@muenster.de>
* Reorganize the data structure of FOptiAttr

Expand Down
20 changes: 10 additions & 10 deletions examples/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2017-2022 Markus Gans *
* Copyright 2017-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -385,11 +385,11 @@ void MouseDraw::setGeometry ( const FPoint& p, const FSize& s, bool adjust)
return;

const FSize no_shadow{0, 0};
const int old_w = canvas->width;
const int old_h = canvas->height;
const int old_w = canvas->size.width;
const int old_h = canvas->size.height;
resizeArea (scroll_geometry, no_shadow, canvas.get());

if ( old_w != canvas->width || old_h != canvas->height )
if ( old_w != canvas->size.width || old_h != canvas->size.height )
{
setColor(getForegroundColor(), getBackgroundColor());
clearArea (canvas.get(), ' ');
Expand Down Expand Up @@ -466,8 +466,8 @@ void MouseDraw::drawBrush (int x, int y, bool swap_color)
setColor (c_chooser.getForeground(), c_chooser.getBackground());

// set canvas print cursor position
canvas->setCursorPos ( x - canvas->offset_left - 10
, y - canvas->offset_top - 2 );
canvas->setCursorPos ( x - canvas->position.x - 10
, y - canvas->position.y - 2 );
// print on canvas
canvas->print (brush.getBrush());

Expand All @@ -490,10 +490,10 @@ void MouseDraw::drawCanvas()
return;

auto printarea = getCurrentPrintArea();
const int ax = 9 + getTermX() - printarea->offset_left;
const int ay = 1 + getTermY() - printarea->offset_top;
const int y_end = canvas->height;
const int x_end = canvas->width;
const int ax = 9 + getTermX() - printarea->position.x;
const int ay = 1 + getTermY() - printarea->position.y;
const int y_end = canvas->size.height;
const int x_end = canvas->size.width;

for (auto y{0}; y < y_end; y++) // line loop
{
Expand Down
1 change: 1 addition & 0 deletions final/ftimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ std::shared_timed_mutex timer_var::mutex{};
// Static class attribute
FTimer<FObject>* FObjectTimer::timer{nullptr};


//----------------------------------------------------------------------
// class FObjectTimer
//----------------------------------------------------------------------
Expand Down
24 changes: 12 additions & 12 deletions final/fwidget_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ void drawTransparentShadow (FWidget* w)
return;

auto& area = *w->getPrintArea();
const auto width = uInt(area.width);
const auto height = uInt(area.height);
const auto shadow_width = uInt(area.right_shadow);
const auto shadow_height = uInt(area.bottom_shadow);
const auto width = uInt(area.size.width);
const auto height = uInt(area.size.height);
const auto shadow_width = uInt(area.shadow.width);
const auto shadow_height = uInt(area.shadow.height);
const auto& wc = FWidget::getColorTheme();

const FChar transparent_char
Expand Down Expand Up @@ -517,12 +517,12 @@ void drawGenericBlockShadow ( FWidget* w

auto& area = *w->getPrintArea();
const bool is_window = w->isWindowWidget();
const auto width = is_window ? uInt(area.width) : uInt(w->getWidth());
const auto height = is_window ? uInt(area.height) : uInt(w->getHeight());
const auto shadow_width = uInt(area.right_shadow);
const auto shadow_height = uInt(area.bottom_shadow);
const auto x_offset = uInt(w->woffset.getX1() + w->getX() - area.offset_left - 1);
const auto y_offset = uInt(w->woffset.getY1() + w->getY() - area.offset_top - 1);
const auto width = is_window ? uInt(area.size.width) : uInt(w->getWidth());
const auto height = is_window ? uInt(area.size.height) : uInt(w->getHeight());
const auto shadow_width = uInt(area.shadow.width);
const auto shadow_height = uInt(area.shadow.height);
const auto x_offset = uInt(w->woffset.getX1() + w->getX() - area.position.x - 1);
const auto y_offset = uInt(w->woffset.getY1() + w->getY() - area.position.y - 1);

if ( is_window && (shadow_width < 1 || shadow_height < 1) )
return;
Expand Down Expand Up @@ -815,8 +815,8 @@ void drawGenericBox ( FWidget* w, const FRect& r
// Adjust box position to match print area
auto box = r;
box.move (-1, -1);
const auto x_offset = uInt(w->woffset.getX1() + w->getX() - area.offset_left - 1);
const auto y_offset = uInt(w->woffset.getY1() + w->getY() - area.offset_top - 1);
const auto x_offset = uInt(w->woffset.getX1() + w->getX() - area.position.x - 1);
const auto y_offset = uInt(w->woffset.getY1() + w->getY() - area.position.y - 1);

// Draw the top line of the box
auto* area_pos = &area.getFChar(int(x_offset) + box.getX1(), int(y_offset) + box.getY1());
Expand Down
134 changes: 59 additions & 75 deletions final/output/tty/ftermdetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,84 +238,68 @@ auto FTermDetection::getTTYSFileEntry() -> bool
void FTermDetection::termtypeAnalysis()
{
static auto& fterm_data = FTermData::getInstance();

// Cygwin console
if ( termtype.left(6) == "cygwin" )
fterm_data.setTermType (FTermType::cygwin);

// rxvt terminal emulator (native MS Window System port) on cygwin
if ( termtype == "rxvt-cygwin-native" )
fterm_data.setTermType (FTermType::rxvt);

// ANSI X3.64 terminal
if ( termtype.left(4) == "ansi" )
{
terminal_detection = false;
fterm_data.setTermType (FTermType::ansi);
}

// Sun Microsystems workstation console
if ( termtype.left(3) == "sun" )
static const std::vector<std::pair<std::wstring, FTermType>> termTypeMap =
{
terminal_detection = false;
fterm_data.setTermType (FTermType::sun_con);
}

// Kterm
if ( termtype.left(5) == "kterm" )
// Cygwin console
{ L"cygwin" , FTermType::cygwin },
// rxvt terminal emulator (native MS Window System port) on cygwin
{ L"rxvt-cygwin-native" , FTermType::rxvt },
// ANSI X3.64 terminal
{ L"ansi" , FTermType::ansi },
// Sun Microsystems workstation console
{ L"sun" , FTermType::sun_con },
// Kterm
{ L"kterm" , FTermType::kterm },
// mlterm
{ L"mlterm" , FTermType::mlterm },
// st - simple terminal
{ L"st-256color" , FTermType::stterm },
// rxvt
{ L"rxvt" , FTermType::rxvt },
// urxvt
{ L"rxvt-unicode" , FTermType::urxvt },
// screen or tmux with termtype screen
{ L"screen" , FTermType::screen },
// tmux
{ L"tmux" , FTermType::tmux },
// Linux console
{ L"linux" , FTermType::linux_con },
{ L"con" , FTermType::linux_con },
// NetBSD workstation console
{ L"wsvt25" , FTermType::netbsd_con },
// kitty
{ L"xterm-kitty" , FTermType::kitty },
// alacritty
{ L"alacritty" , FTermType::xterm }
};

auto search_predicate = [this] (const auto& pair)
{
terminal_detection = false;
fterm_data.setTermType (FTermType::kterm);
}
return startsWithTermType(pair.first);
};
auto iter = std::find_if ( termTypeMap.begin()
, termTypeMap.end()
, search_predicate );

// mlterm
if ( termtype.left(6) == "mlterm" )
fterm_data.setTermType (FTermType::mlterm);

// st - simple terminal
if ( termtype.left(11) == "st-256color" )
fterm_data.setTermType (FTermType::stterm);
if ( iter == termTypeMap.end() ) // not found
return;

// rxvt
if ( termtype.left(4) == "rxvt" )
fterm_data.setTermType (FTermType::rxvt);
fterm_data.setTermType (iter->second);

// urxvt
if ( termtype.left(12) == "rxvt-unicode" )
fterm_data.setTermType (FTermType::urxvt);
if ( fterm_data.isTermType(FTermType::ansi)
|| fterm_data.isTermType(FTermType::sun_con)
|| fterm_data.isTermType(FTermType::kterm) )
terminal_detection = false;

// screen or tmux with termtype screen
if ( termtype.left(6) == "screen" )
if ( fterm_data.isTermType(FTermType::screen) )
{
fterm_data.setTermType (FTermType::screen);
auto tmux = std::getenv("TMUX");

if ( tmux && tmux[0] != '\0' )
fterm_data.setTermType (FTermType::tmux);
}

// tmux
if ( termtype.left(4) == "tmux" )
{
else if ( fterm_data.isTermType(FTermType::tmux) )
fterm_data.setTermType (FTermType::screen);
fterm_data.setTermType (FTermType::tmux);
}

// Linux console
if ( termtype.left(5) == "linux" || termtype.left(3) == "con" )
fterm_data.setTermType (FTermType::linux_con);

// NetBSD workstation console
if ( termtype.left(6) == "wsvt25" )
fterm_data.setTermType (FTermType::netbsd_con);

// kitty
if ( termtype.left(11) == "xterm-kitty" )
fterm_data.setTermType (FTermType::kitty);

// alacritty
if ( termtype.left(9) == "alacritty" )
fterm_data.setTermType (FTermType::xterm);
}

//----------------------------------------------------------------------
Expand Down Expand Up @@ -353,15 +337,15 @@ void FTermDetection::detectTerminal()
static auto& fterm_data = FTermData::getInstance();

// Test if the terminal is a xterm
if ( termtype.left(5) == "xterm" || termtype.left(5) == "Eterm" )
if ( startsWithTermType(L"xterm") || startsWithTermType(L"Eterm") )
{
fterm_data.setTermType (FTermType::xterm);

// Each xterm should be able to use at least 16 colors
if ( ! new_termtype && termtype.getLength() == 5 )
new_termtype = "xterm-16color";
}
else if ( termtype.left(4) == "ansi" ) // ANSI detection
else if ( startsWithTermType(L"ansi") ) // ANSI detection
fterm_data.setTermType (FTermType::ansi);

// set the new environment variable TERM
Expand Down Expand Up @@ -443,19 +427,19 @@ auto FTermDetection::termtype_256color_quirks() -> FString
if ( ! color256 )
return new_termtype;

if ( termtype.left(5) == "xterm" )
if ( startsWithTermType(L"xterm") )
new_termtype = "xterm-256color";

if ( termtype.left(6) == "screen" )
if ( startsWithTermType(L"screen") )
new_termtype = "screen-256color";

if ( termtype.left(5) == "Eterm" )
if ( startsWithTermType(L"Eterm") )
new_termtype = "Eterm-256color";

if ( termtype.left(6) == "mlterm" )
if ( startsWithTermType(L"mlterm") )
new_termtype = "mlterm-256color";

if ( termtype.left(4) == "rxvt"
if ( startsWithTermType(L"rxvt")
&& color_env.string1.left(8) == "rxvt-xpm" )
{
new_termtype = "rxvt-256color";
Expand Down Expand Up @@ -837,9 +821,9 @@ inline auto FTermDetection::secDA_Analysis_24 (const FString& current_termtype)
// NetBSD/OpenBSD workstation console
auto& fterm_data = FTermData::getInstance();

if ( termtype.left(6) == "wsvt25" )
if ( startsWithTermType(L"wsvt25") )
fterm_data.setTermType (FTermType::netbsd_con);
else if ( termtype.left(5) == "vt220" )
else if ( startsWithTermType(L"vt220") )
{
fterm_data.setTermType (FTermType::openbsd_con);
new_termtype = "pccon";
Expand Down Expand Up @@ -941,7 +925,7 @@ inline auto FTermDetection::secDA_Analysis_85() const -> FString

return [this] ()
{
if ( termtype.left(5) == "rxvt-" )
if ( startsWithTermType(L"rxvt-") )
{
if ( color256 )
return FString("rxvt-256color");
Expand Down
11 changes: 10 additions & 1 deletion final/output/tty/ftermdetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2018-2022 Markus Gans *
* Copyright 2018-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -107,6 +107,8 @@ class FTermDetection final
#if F_HAVE_GETTTYNAM
auto getTTYSFileEntry() -> bool;
#endif
template<typename StringT>
bool startsWithTermType (StringT&&) const;
void termtypeAnalysis();
void detectTerminal();
auto init_256colorTerminal() -> FString;
Expand Down Expand Up @@ -191,6 +193,13 @@ inline auto FTermDetection::hasTerminalDetection() const noexcept -> bool
inline void FTermDetection::setTerminalDetection (bool enable) noexcept
{ terminal_detection = enable; }

//----------------------------------------------------------------------
template<typename StringT>
inline bool FTermDetection::startsWithTermType (StringT&& prefix) const
{
return termtype.toWString().find(std::forward<StringT>(prefix)) == 0;
}

} // namespace finalcut

#endif // FTERMDETECTION_H
Loading

0 comments on commit a2bf66e

Please sign in to comment.