Moving all termcap functions into FTermcap

This commit is contained in:
Markus Gans 2020-05-02 04:56:12 +02:00
parent a90cd1ad55
commit deccb4b74c
10 changed files with 149 additions and 123 deletions

View File

@ -1,3 +1,6 @@
2020-05-02 Markus Gans <guru.mail@muenster.de>
* Transfer of all termcap functions into the FTermcap class
2020-04-28 Markus Gans <guru.mail@muenster.de> 2020-04-28 Markus Gans <guru.mail@muenster.de>
* Adding the missing method getClientSize() * Adding the missing method getClientSize()
* Static code for the special built-in key sequences * Static code for the special built-in key sequences

View File

@ -932,7 +932,7 @@ void MyDialog::cb_showProgressBar (const finalcut::FWidget*, const FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_updateNumber (finalcut::FWidget* widget, FDataPtr data) void MyDialog::cb_updateNumber (finalcut::FWidget* widget, FDataPtr data)
{ {
auto& list = *(static_cast<finalcut::FListBox*>(widget)); const auto& list = *(static_cast<finalcut::FListBox*>(widget));
auto& num = *(static_cast<finalcut::FLabel*>(data)); auto& num = *(static_cast<finalcut::FLabel*>(data));
const auto count = list.getCount(); const auto count = list.getCount();
int select_num = 0; int select_num = 0;
@ -949,7 +949,7 @@ void MyDialog::cb_updateNumber (finalcut::FWidget* widget, FDataPtr data)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_activateButton (finalcut::FWidget* widget, FDataPtr data) void MyDialog::cb_activateButton (finalcut::FWidget* widget, FDataPtr data)
{ {
auto& rb = *(static_cast<finalcut::FRadioButton*>(widget)); const auto& rb = *(static_cast<finalcut::FRadioButton*>(widget));
auto& button = *(static_cast<finalcut::FButton*>(data)); auto& button = *(static_cast<finalcut::FButton*>(data));
if ( rb.isChecked() ) if ( rb.isChecked() )

View File

@ -25,6 +25,7 @@
#include "final/fc.h" #include "final/fc.h"
#include "final/foptiattr.h" #include "final/foptiattr.h"
#include "final/fstartoptions.h" #include "final/fstartoptions.h"
#include "final/ftermcap.h"
namespace finalcut namespace finalcut
{ {
@ -956,16 +957,16 @@ bool FOptiAttr::setTermAttributes ( FChar*& term
{ {
if ( term && F_set_attributes.cap ) if ( term && F_set_attributes.cap )
{ {
const char* sgr = tparm ( C_STR(F_set_attributes.cap) const char* sgr = FTermcap::encodeParameter ( F_set_attributes.cap
, p1 && ! fake_reverse , p1 && ! fake_reverse
, p2 , p2
, p3 && ! fake_reverse , p3 && ! fake_reverse
, p4 , p4
, p5 , p5
, p6 , p6
, p7 , p7
, p8 , p8
, p9 ); , p9 );
append_sequence (sgr); append_sequence (sgr);
resetColor(term); resetColor(term);
term->attr.bit.standout = p1; term->attr.bit.standout = p1;
@ -1500,13 +1501,13 @@ inline void FOptiAttr::change_current_color ( const FChar* const& term
if ( term->fg_color != fg || frev ) if ( term->fg_color != fg || frev )
{ {
color_str = tparm(C_STR(AF), ansi_fg, 0, 0, 0, 0, 0, 0, 0, 0); color_str = FTermcap::encodeParameter(AF, ansi_fg);
append_sequence (color_str); append_sequence (color_str);
} }
if ( term->bg_color != bg || frev ) if ( term->bg_color != bg || frev )
{ {
color_str = tparm(C_STR(AB), ansi_bg, 0, 0, 0, 0, 0, 0, 0, 0); color_str = FTermcap::encodeParameter(AB, ansi_bg);
append_sequence (color_str); append_sequence (color_str);
} }
} }
@ -1514,13 +1515,13 @@ inline void FOptiAttr::change_current_color ( const FChar* const& term
{ {
if ( term->fg_color != fg || frev ) if ( term->fg_color != fg || frev )
{ {
color_str = tparm(C_STR(Sf), fg, 0, 0, 0, 0, 0, 0, 0, 0); color_str = FTermcap::encodeParameter(Sf, fg);
append_sequence (color_str); append_sequence (color_str);
} }
if ( term->bg_color != bg || frev ) if ( term->bg_color != bg || frev )
{ {
color_str = tparm(C_STR(Sb), bg, 0, 0, 0, 0, 0, 0, 0, 0); color_str = FTermcap::encodeParameter(Sb, bg);
append_sequence (color_str); append_sequence (color_str);
} }
} }
@ -1528,7 +1529,7 @@ inline void FOptiAttr::change_current_color ( const FChar* const& term
{ {
fg = vga2ansi(fg); fg = vga2ansi(fg);
bg = vga2ansi(bg); bg = vga2ansi(bg);
color_str = tparm(C_STR(sp), fg, bg, 0, 0, 0, 0, 0, 0, 0); color_str = FTermcap::encodeParameter(sp, fg, bg);
append_sequence (color_str); append_sequence (color_str);
} }
} }

View File

@ -24,6 +24,7 @@
#include "final/fc.h" #include "final/fc.h"
#include "final/foptimove.h" #include "final/foptimove.h"
#include "final/ftermcap.h"
namespace finalcut namespace finalcut
{ {
@ -267,7 +268,7 @@ void FOptiMove::set_cursor_address (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tgoto(C_STR(cap), 23, 23); const char* temp = FTermcap::encodeMotionParameter(cap, 23, 23);
F_cursor_address.cap = cap; F_cursor_address.cap = cap;
F_cursor_address.duration = capDuration (temp, 1); F_cursor_address.duration = capDuration (temp, 1);
F_cursor_address.length = capDurationToLength (F_cursor_address.duration); F_cursor_address.length = capDurationToLength (F_cursor_address.duration);
@ -285,7 +286,7 @@ void FOptiMove::set_column_address (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), 23, 0, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, 23);
F_column_address.cap = cap; F_column_address.cap = cap;
F_column_address.duration = capDuration (temp, 1); F_column_address.duration = capDuration (temp, 1);
F_column_address.length = capDurationToLength (F_column_address.duration); F_column_address.length = capDurationToLength (F_column_address.duration);
@ -303,7 +304,7 @@ void FOptiMove::set_row_address (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), 23, 0, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, 23);
F_row_address.cap = cap; F_row_address.cap = cap;
F_row_address.duration = capDuration (temp, 1); F_row_address.duration = capDuration (temp, 1);
F_row_address.length = capDurationToLength (F_row_address.duration); F_row_address.length = capDurationToLength (F_row_address.duration);
@ -321,7 +322,7 @@ void FOptiMove::set_parm_up_cursor (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), 23, 0, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, 23);
F_parm_up_cursor.cap = cap; F_parm_up_cursor.cap = cap;
F_parm_up_cursor.duration = capDuration (temp, 1); F_parm_up_cursor.duration = capDuration (temp, 1);
F_parm_up_cursor.length = capDurationToLength (F_parm_up_cursor.duration); F_parm_up_cursor.length = capDurationToLength (F_parm_up_cursor.duration);
@ -339,7 +340,7 @@ void FOptiMove::set_parm_down_cursor (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), 23, 0, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, 23);
F_parm_down_cursor.cap = cap; F_parm_down_cursor.cap = cap;
F_parm_down_cursor.duration = capDuration (temp, 1); F_parm_down_cursor.duration = capDuration (temp, 1);
F_parm_down_cursor.length = capDurationToLength (F_parm_down_cursor.duration); F_parm_down_cursor.length = capDurationToLength (F_parm_down_cursor.duration);
@ -357,7 +358,7 @@ void FOptiMove::set_parm_left_cursor (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), 23, 0, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, 23);
F_parm_left_cursor.cap = cap; F_parm_left_cursor.cap = cap;
F_parm_left_cursor.duration = capDuration (temp, 1); F_parm_left_cursor.duration = capDuration (temp, 1);
F_parm_left_cursor.length = capDurationToLength (F_parm_left_cursor.duration); F_parm_left_cursor.length = capDurationToLength (F_parm_left_cursor.duration);
@ -375,7 +376,7 @@ void FOptiMove::set_parm_right_cursor (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), 23, 0, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, 23);
F_parm_right_cursor.cap = cap; F_parm_right_cursor.cap = cap;
F_parm_right_cursor.duration = capDuration (temp, 1); F_parm_right_cursor.duration = capDuration (temp, 1);
F_parm_right_cursor.length = capDurationToLength (F_parm_right_cursor.duration); F_parm_right_cursor.length = capDurationToLength (F_parm_right_cursor.duration);
@ -393,7 +394,7 @@ void FOptiMove::set_erase_chars (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), 23, 0, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, 23);
F_erase_chars.cap = cap; F_erase_chars.cap = cap;
F_erase_chars.duration = capDuration (temp, 1); F_erase_chars.duration = capDuration (temp, 1);
F_erase_chars.length = capDurationToLength (F_erase_chars.duration); F_erase_chars.length = capDurationToLength (F_erase_chars.duration);
@ -411,7 +412,7 @@ void FOptiMove::set_repeat_char (const char cap[])
{ {
if ( cap ) if ( cap )
{ {
const char* temp = tparm(C_STR(cap), ' ', 23, 0, 0, 0, 0, 0, 0, 0); const char* temp = FTermcap::encodeParameter(cap, ' ', 23);
F_repeat_char.cap = cap; F_repeat_char.cap = cap;
F_repeat_char.duration = capDuration (temp, 1); F_repeat_char.duration = capDuration (temp, 1);
F_repeat_char.length = capDurationToLength (F_repeat_char.duration); F_repeat_char.length = capDurationToLength (F_repeat_char.duration);
@ -686,7 +687,7 @@ inline int FOptiMove::verticalMove (char move[], int from_y, int to_y)
if ( move ) if ( move )
{ {
std::strncpy ( move std::strncpy ( move
, tparm(C_STR(F_row_address.cap), to_y, 0, 0, 0, 0, 0, 0, 0, 0) , FTermcap::encodeParameter(F_row_address.cap, to_y)
, BUF_SIZE ); , BUF_SIZE );
move[BUF_SIZE - 1] = '\0'; move[BUF_SIZE - 1] = '\0';
} }
@ -713,7 +714,7 @@ inline void FOptiMove::downMove ( char move[], int& vtime
if ( move ) if ( move )
{ {
std::strncpy ( move std::strncpy ( move
, tparm(C_STR(F_parm_down_cursor.cap), num, 0, 0, 0, 0, 0, 0, 0, 0) , FTermcap::encodeParameter(F_parm_down_cursor.cap, num)
, BUF_SIZE ); , BUF_SIZE );
move[BUF_SIZE - 1] = '\0'; move[BUF_SIZE - 1] = '\0';
} }
@ -741,7 +742,7 @@ inline void FOptiMove::upMove ( char move[], int& vtime
if ( move ) if ( move )
{ {
std::strncpy ( move std::strncpy ( move
, tparm(C_STR(F_parm_up_cursor.cap), num, 0, 0, 0, 0, 0, 0, 0, 0) , FTermcap::encodeParameter(F_parm_up_cursor.cap, num)
, BUF_SIZE ); , BUF_SIZE );
move[BUF_SIZE - 1] = '\0'; move[BUF_SIZE - 1] = '\0';
} }
@ -767,7 +768,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
{ {
// Move to fixed column position1 // Move to fixed column position1
std::strncat ( hmove std::strncat ( hmove
, tparm(C_STR(F_column_address.cap), to_x, 0, 0, 0, 0, 0, 0, 0, 0) , FTermcap::encodeParameter(F_column_address.cap, to_x)
, BUF_SIZE - std::strlen(hmove) - 1 ); , BUF_SIZE - std::strlen(hmove) - 1 );
hmove[BUF_SIZE - 1] = '\0'; hmove[BUF_SIZE - 1] = '\0';
htime = F_column_address.duration; htime = F_column_address.duration;
@ -790,7 +791,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime
if ( F_parm_right_cursor.cap && F_parm_right_cursor.duration < htime ) if ( F_parm_right_cursor.cap && F_parm_right_cursor.duration < htime )
{ {
std::strncpy ( hmove std::strncpy ( hmove
, tparm(C_STR(F_parm_right_cursor.cap), num, 0, 0, 0, 0, 0, 0, 0, 0) , FTermcap::encodeParameter(F_parm_right_cursor.cap, num)
, BUF_SIZE - 1); , BUF_SIZE - 1);
hmove[BUF_SIZE - 1] = '\0'; hmove[BUF_SIZE - 1] = '\0';
htime = F_parm_right_cursor.duration; htime = F_parm_right_cursor.duration;
@ -845,7 +846,7 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime
if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime ) if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime )
{ {
std::strncpy ( hmove std::strncpy ( hmove
, tparm(C_STR(F_parm_left_cursor.cap), num, 0, 0, 0, 0, 0, 0, 0, 0) , FTermcap::encodeParameter(F_parm_left_cursor.cap, num)
, BUF_SIZE - 1); , BUF_SIZE - 1);
hmove[BUF_SIZE - 1] = '\0'; hmove[BUF_SIZE - 1] = '\0';
htime = F_parm_left_cursor.duration; htime = F_parm_left_cursor.duration;
@ -906,13 +907,14 @@ inline bool FOptiMove::isMethod0Faster ( int& move_time
, int xnew, int ynew ) , int xnew, int ynew )
{ {
// Test method 0: direct cursor addressing // Test method 0: direct cursor addressing
const char* move_xy = tgoto(C_STR(F_cursor_address.cap), xnew, ynew); const char* move_xy = \
FTermcap::encodeMotionParameter(F_cursor_address.cap, xnew, ynew);
if ( move_xy ) if ( move_xy )
{ {
char* move_ptr = move_buf; std::strncpy ( reinterpret_cast<char*>(move_buf)
std::strncpy (move_ptr, move_xy, BUF_SIZE - 1); , move_xy, BUF_SIZE - 1 );
move_ptr[BUF_SIZE - 1] = '\0'; move_buf[BUF_SIZE - 1] = '\0';
move_time = F_cursor_address.duration; move_time = F_cursor_address.duration;
return true; return true;
} }

View File

@ -836,7 +836,7 @@ const char* FTerm::moveCursorString (int xold, int yold, int xnew, int ynew)
if ( data->hasCursorOptimisation() ) if ( data->hasCursorOptimisation() )
return opti_move->moveCursor (xold, yold, xnew, ynew); return opti_move->moveCursor (xold, yold, xnew, ynew);
else else
return tgoto(C_STR(TCAP(fc::t_cursor_address)), xnew, ynew); return FTermcap::encodeMotionParameter(TCAP(fc::t_cursor_address), xnew, ynew);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -987,9 +987,9 @@ void FTerm::setPalette (FColor index, int r, int g, int b)
const int bb = (b * 1001) / 256; const int bb = (b * 1001) / 256;
if ( Ic ) if ( Ic )
color_str = tparm(C_STR(Ic), index, rr, gg, bb, 0, 0, 0, 0, 0); color_str = FTermcap::encodeParameter(Ic, index, rr, gg, bb);
else if ( Ip ) else if ( Ip )
color_str = tparm(C_STR(Ip), index, 0, 0, 0, rr, gg, bb, 0, 0); color_str = FTermcap::encodeParameter(Ip, index, 0, 0, 0, rr, gg, bb);
if ( color_str ) if ( color_str )
{ {
@ -1199,7 +1199,7 @@ void FTerm::putstring (const char str[], int affcnt)
if ( ! fsys ) if ( ! fsys )
getFSystem(); getFSystem();
fsys->tputs (str, affcnt, FTerm::putchar_ASCII); FTermcap::paddingPrint (str, affcnt, FTerm::putchar_ASCII);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -27,6 +27,7 @@
#include "final/emptyfstring.h" #include "final/emptyfstring.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/fkey_map.h" #include "final/fkey_map.h"
#include "final/fsystem.h"
#include "final/fterm.h" #include "final/fterm.h"
#include "final/ftermdata.h" #include "final/ftermdata.h"
#include "final/ftermcap.h" #include "final/ftermcap.h"
@ -47,9 +48,10 @@ bool FTermcap::no_utf8_acs_chars {false};
int FTermcap::max_color {1}; int FTermcap::max_color {1};
int FTermcap::tabstop {8}; int FTermcap::tabstop {8};
int FTermcap::attr_without_color {0}; int FTermcap::attr_without_color {0};
FSystem* FTermcap::fsystem {nullptr};
FTermData* FTermcap::fterm_data {nullptr}; FTermData* FTermcap::fterm_data {nullptr};
FTermDetection* FTermcap::term_detection {nullptr}; FTermDetection* FTermcap::term_detection {nullptr};
char FTermcap::string_buf[2048] {};
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FTermcap // class FTermcap
@ -65,9 +67,43 @@ FTermDetection* FTermcap::term_detection {nullptr};
*/ */
// public methods of FTermcap // public methods of FTermcap
//----------------------------------------------------------------------
bool FTermcap::getFlag (const std::string& cap)
{
return tgetflag(C_STR(cap.c_str()));
}
//----------------------------------------------------------------------
int FTermcap::getNumber (const std::string& cap)
{
return tgetnum(C_STR(cap.c_str()));
}
//----------------------------------------------------------------------
char* FTermcap::getString (const std::string& cap)
{
return tgetstr( C_STR(cap.c_str())
, reinterpret_cast<char**>(&string_buf) );
}
//----------------------------------------------------------------------
int FTermcap::paddingPrint ( const std::string& str
, int affcnt, fn_putc putc )
{
return fsystem->tputs (str.c_str(), affcnt, putc);
}
//----------------------------------------------------------------------
char* FTermcap::encodeMotionParameter ( const std::string& str
, int col, int row )
{
return tgoto(str.c_str(), col, row);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermcap::init() void FTermcap::init()
{ {
fsystem = FTerm::getFSystem();
fterm_data = FTerm::getFTermData(); fterm_data = FTerm::getFTermData();
term_detection = FTerm::getFTermDetection(); term_detection = FTerm::getFTermDetection();
termcap(); termcap();
@ -81,8 +117,6 @@ void FTermcap::termcap()
static constexpr int success = 1; static constexpr int success = 1;
static constexpr int uninitialized = -2; static constexpr int uninitialized = -2;
static char term_buffer[2048]{}; static char term_buffer[2048]{};
static char string_buf[2048]{};
char* buffer = string_buf;
int status = uninitialized; int status = uninitialized;
const bool color256 = term_detection->canDisplay256Colors(); const bool color256 = term_detection->canDisplay256Colors();
@ -119,7 +153,7 @@ void FTermcap::termcap()
term_detection->setAnsiTerminal (true); term_detection->setAnsiTerminal (true);
termcapError (status); termcapError (status);
termcapVariables (buffer); termcapVariables();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -146,7 +180,7 @@ void FTermcap::termcapError (int status)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermcap::termcapVariables (char*& buffer) void FTermcap::termcapVariables()
{ {
// Get termcap booleans // Get termcap booleans
termcapBoleans(); termcapBoleans();
@ -155,10 +189,10 @@ void FTermcap::termcapVariables (char*& buffer)
termcapNumerics(); termcapNumerics();
// Get termcap strings // Get termcap strings
termcapStrings (buffer); termcapStrings();
// Get termcap keys // Get termcap keys
termcapKeys (buffer); termcapKeys();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -167,29 +201,29 @@ void FTermcap::termcapBoleans()
// Get termcap flags/booleans // Get termcap flags/booleans
// Screen erased with the background color // Screen erased with the background color
background_color_erase = tgetflag(C_STR("ut")); background_color_erase = getFlag("ut");
// Terminal is able to redefine existing colors // Terminal is able to redefine existing colors
can_change_color_palette = tgetflag(C_STR("cc")); can_change_color_palette = getFlag("cc");
// t_cursor_left wraps from column 0 to last column // t_cursor_left wraps from column 0 to last column
automatic_left_margin = tgetflag(C_STR("bw")); automatic_left_margin = getFlag("bw");
// Terminal has auto-matic margins // Terminal has auto-matic margins
automatic_right_margin = tgetflag(C_STR("am")); automatic_right_margin = getFlag("am");
// NewLine ignored after 80 cols // NewLine ignored after 80 cols
eat_nl_glitch = tgetflag(C_STR("xn")); eat_nl_glitch = getFlag("xn");
// Terminal supports ANSI set default fg and bg color // Terminal supports ANSI set default fg and bg color
ansi_default_color = tgetflag(C_STR("AX")); ansi_default_color = getFlag("AX");
// Terminal supports operating system commands (OSC) // Terminal supports operating system commands (OSC)
// OSC = Esc + ']' // OSC = Esc + ']'
osc_support = tgetflag(C_STR("XT")); osc_support = getFlag("XT");
// U8 is nonzero for terminals with no VT100 line-drawing in UTF-8 mode // U8 is nonzero for terminals with no VT100 line-drawing in UTF-8 mode
no_utf8_acs_chars = bool(tgetnum(C_STR("U8")) != 0); no_utf8_acs_chars = bool(getNumber("U8") != 0);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -198,7 +232,7 @@ void FTermcap::termcapNumerics()
// Get termcap numerics // Get termcap numerics
// Maximum number of colors on screen // Maximum number of colors on screen
max_color = std::max(max_color, tgetnum(C_STR("Co"))); max_color = std::max(max_color, getNumber("Co"));
if ( max_color < 0 ) if ( max_color < 0 )
max_color = 1; max_color = 1;
@ -209,24 +243,24 @@ void FTermcap::termcapNumerics()
fterm_data->setMonochron(false); fterm_data->setMonochron(false);
// Get initial spacing for hardware tab stop // Get initial spacing for hardware tab stop
tabstop = tgetnum(C_STR("it")); tabstop = getNumber("it");
// Get video attributes that cannot be used with colors // Get video attributes that cannot be used with colors
attr_without_color = tgetnum(C_STR("NC")); attr_without_color = getNumber("NC");
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermcap::termcapStrings (char*& buffer) void FTermcap::termcapStrings()
{ {
// Get termcap strings // Get termcap strings
// Read termcap output strings // Read termcap output strings
for (std::size_t i{0}; strings[i].tname[0] != 0; i++) for (std::size_t i{0}; strings[i].tname[0] != 0; i++)
strings[i].string = tgetstr(C_STR(strings[i].tname), &buffer); strings[i].string = getString(strings[i].tname);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermcap::termcapKeys (char*& buffer) void FTermcap::termcapKeys()
{ {
// Get termcap keys // Get termcap keys
@ -234,7 +268,7 @@ void FTermcap::termcapKeys (char*& buffer)
for ( std::size_t i{0}; for ( std::size_t i{0};
fc::fkey[i].string == nullptr && fc::fkey[i].tname[0] != 0; fc::fkey[i].string == nullptr && fc::fkey[i].tname[0] != 0;
i++ ) i++ )
fc::fkey[i].string = tgetstr(C_STR(fc::fkey[i].tname), &buffer); fc::fkey[i].string = getString(fc::fkey[i].tname);
} }

View File

@ -2478,7 +2478,7 @@ void FVTerm::printFullWidthPaddingCharacter ( uInt& x, uInt y
if ( le ) if ( le )
appendOutputBuffer (le); appendOutputBuffer (le);
else if ( RI ) else if ( RI )
appendOutputBuffer (tparm(C_STR(RI), 1, 0, 0, 0, 0, 0, 0, 0, 0)); appendOutputBuffer (FTermcap::encodeParameter(RI, 1));
else else
{ {
skipPaddingCharacter (x, y, prev_char); skipPaddingCharacter (x, y, prev_char);
@ -2518,7 +2518,7 @@ void FVTerm::printHalfCovertFullWidthCharacter ( uInt& x, uInt y
if ( le ) if ( le )
appendOutputBuffer (le); appendOutputBuffer (le);
else if ( RI ) else if ( RI )
appendOutputBuffer (tparm(C_STR(RI), 1, 0, 0, 0, 0, 0, 0, 0, 0)); appendOutputBuffer (FTermcap::encodeParameter(RI, 1));
if ( le || RI ) if ( le || RI )
{ {
@ -2590,7 +2590,7 @@ FVTerm::exit_state FVTerm::eraseCharacters ( uInt& x, uInt xmax, uInt y
&& (ut || normal) ) && (ut || normal) )
{ {
appendAttributes (print_char); appendAttributes (print_char);
appendOutputBuffer (tparm(C_STR(ec), whitespace, 0, 0, 0, 0, 0, 0, 0, 0)); appendOutputBuffer (FTermcap::encodeParameter(ec, whitespace));
if ( x + whitespace - 1 < xmax || draw_trailing_ws ) if ( x + whitespace - 1 < xmax || draw_trailing_ws )
setTermXY (int(x + whitespace), int(y)); setTermXY (int(x + whitespace), int(y));
@ -2655,7 +2655,7 @@ FVTerm::exit_state FVTerm::repeatCharacter (uInt& x, uInt xmax, uInt y)
newFontChanges (print_char); newFontChanges (print_char);
charsetChanges (print_char); charsetChanges (print_char);
appendAttributes (print_char); appendAttributes (print_char);
appendOutputBuffer (tparm(C_STR(rp), print_char->ch, repetitions, 0, 0, 0, 0, 0, 0, 0)); appendOutputBuffer (FTermcap::encodeParameter(rp, print_char->ch, repetitions));
term_pos->x_ref() += int(repetitions); term_pos->x_ref() += int(repetitions);
x = x + repetitions - 1; x = x + repetitions - 1;
} }
@ -3038,7 +3038,7 @@ int FVTerm::appendLowerRight (FChar*& screen_char)
if ( IC ) if ( IC )
{ {
appendOutputBuffer (tparm(C_STR(IC), 1, 0, 0, 0, 0, 0, 0, 0, 0)); appendOutputBuffer (FTermcap::encodeParameter(IC, 1));
appendChar (screen_char); appendChar (screen_char);
} }
else if ( im && ei ) else if ( im && ei )
@ -3077,13 +3077,13 @@ inline void FVTerm::characterFilter (FChar*& next_char)
inline void FVTerm::appendOutputBuffer (const std::string& s) inline void FVTerm::appendOutputBuffer (const std::string& s)
{ {
const char* const& c_string = s.c_str(); const char* const& c_string = s.c_str();
fsystem->tputs (c_string, 1, appendOutputBuffer); FTermcap::paddingPrint (c_string, 1, appendOutputBuffer);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::appendOutputBuffer (const char s[]) inline void FVTerm::appendOutputBuffer (const char s[])
{ {
fsystem->tputs (s, 1, appendOutputBuffer); FTermcap::paddingPrint (s, 1, appendOutputBuffer);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -36,23 +36,6 @@
#endif #endif
#include <assert.h> #include <assert.h>
#if defined(__sun) && defined(__SVR4)
#include <termio.h>
typedef struct termio SGTTY;
typedef struct termios SGTTYS;
#ifdef _LP64
typedef unsigned int chtype;
#else
typedef unsigned long chtype;
#endif
#include <term.h> // need for tparm
#else
#include <term.h> // need for tparm
#endif
#include <algorithm> // need for std::swap #include <algorithm> // need for std::swap
#include "final/fstring.h" #include "final/fstring.h"

View File

@ -39,23 +39,6 @@
#endif #endif
#include <assert.h> #include <assert.h>
#if defined(__sun) && defined(__SVR4)
#include <termio.h>
typedef struct termio SGTTY;
typedef struct termios SGTTYS;
#ifdef _LP64
typedef unsigned int chtype;
#else
typedef unsigned long chtype;
#endif // _LP64
#include <term.h> // need for tparm
#else
#include <term.h> // need for tparm
#endif // defined(__sun) && defined(__SVR4)
#include <cctype> #include <cctype>
#include <climits> #include <climits>
#include <cstdlib> #include <cstdlib>

View File

@ -65,6 +65,7 @@ namespace finalcut
{ {
// class forward declaration // class forward declaration
class FSystem;
class FTermData; class FTermData;
class FTermDetection; class FTermDetection;
@ -75,6 +76,9 @@ class FTermDetection;
class FTermcap final class FTermcap final
{ {
public: public:
// Using-declaration
using fn_putc = int (*)(int);
// Typedef // Typedef
typedef struct typedef struct
{ {
@ -90,38 +94,47 @@ class FTermcap final
~FTermcap() = default; ~FTermcap() = default;
// Accessors // Accessors
const FString getClassName() const; const FString getClassName() const;
static bool getFlag (const std::string&);
static int getNumber (const std::string&);
static char* getString (const std::string&);
static int paddingPrint (const std::string&, int, fn_putc);
static char* encodeMotionParameter (const std::string&, int, int);
template<typename... Args>
static char* encodeParameter (const FString&, Args&&...);
// Methods // Methods
static void init(); static void init();
// Data members // Data members
static bool background_color_erase; static bool background_color_erase;
static bool can_change_color_palette; static bool can_change_color_palette;
static bool automatic_left_margin; static bool automatic_left_margin;
static bool automatic_right_margin; static bool automatic_right_margin;
static bool eat_nl_glitch; static bool eat_nl_glitch;
static bool ansi_default_color; static bool ansi_default_color;
static bool osc_support; static bool osc_support;
static bool no_utf8_acs_chars; static bool no_utf8_acs_chars;
static int max_color; static int max_color;
static int tabstop; static int tabstop;
static int attr_without_color; static int attr_without_color;
static tcap_map strings[]; static tcap_map strings[];
private: private:
// Methods // Methods
static void termcap(); static void termcap();
static void termcapError (int); static void termcapError (int);
static void termcapVariables (char*&); static void termcapVariables();
static void termcapBoleans(); static void termcapBoleans();
static void termcapNumerics(); static void termcapNumerics();
static void termcapStrings (char*&); static void termcapStrings();
static void termcapKeys (char*&); static void termcapKeys();
// Data member // Data member
static FSystem* fsystem;
static FTermData* fterm_data; static FTermData* fterm_data;
static FTermDetection* term_detection; static FTermDetection* term_detection;
static char string_buf[2048];
}; };
@ -130,6 +143,13 @@ class FTermcap final
inline const FString FTermcap::getClassName() const inline const FString FTermcap::getClassName() const
{ return "FTermcap"; } { return "FTermcap"; }
//----------------------------------------------------------------------
template<typename... Args>
inline char* FTermcap::encodeParameter (const FString& str, Args&&... args)
{
return tparm (str, std::forward<Args>(args)...);
}
} // namespace finalcut } // namespace finalcut