Refactoring FTerm::init_encoding

This commit is contained in:
Markus Gans 2018-02-19 23:02:54 +01:00
parent aa18e5b5ba
commit 4778de5c52
3 changed files with 51 additions and 4 deletions

View File

@ -1,5 +1,6 @@
2017-02-19 Markus Gans <guru.mail@muenster.de> 2017-02-19 Markus Gans <guru.mail@muenster.de>
* Refactoring FTerm::init_termcaps * Refactoring FTerm::init_termcaps
* Refactoring FTerm::init_encoding
2017-02-18 Markus Gans <guru.mail@muenster.de> 2017-02-18 Markus Gans <guru.mail@muenster.de>
* Avoid scroll bar overshooting * Avoid scroll bar overshooting

View File

@ -520,6 +520,12 @@ class FTerm
static void init_font(); static void init_font();
static void init_locale(); static void init_locale();
static void init_encoding(); static void init_encoding();
static void init_encoding_set();
static void init_term_encoding();
static void init_individual_term_encoding();
static bool init_force_vt100_encoding();
static void init_utf8_without_alt_charset();
static void init_tab_quirks();
static void redefineColorPalette(); static void redefineColorPalette();
static void restoreColorPalette(); static void restoreColorPalette();
static void enableMouse(); static void enableMouse();

View File

@ -4166,13 +4166,32 @@ void FTerm::init_encoding()
{ {
// detect encoding and set the Fputchar function pointer // detect encoding and set the Fputchar function pointer
init_encoding_set();
init_term_encoding();
init_pc_charset();
init_individual_term_encoding();
if ( ! init_force_vt100_encoding() )
init_utf8_without_alt_charset();
init_tab_quirks();
}
//----------------------------------------------------------------------
inline void FTerm::init_encoding_set()
{
// Define the encoding set // Define the encoding set
(*encoding_set)["UTF8"] = fc::UTF8; (*encoding_set)["UTF8"] = fc::UTF8;
(*encoding_set)["UTF-8"] = fc::UTF8; (*encoding_set)["UTF-8"] = fc::UTF8;
(*encoding_set)["VT100"] = fc::VT100; (*encoding_set)["VT100"] = fc::VT100;
(*encoding_set)["PC"] = fc::PC; (*encoding_set)["PC"] = fc::PC;
(*encoding_set)["ASCII"] = fc::ASCII; (*encoding_set)["ASCII"] = fc::ASCII;
}
//----------------------------------------------------------------------
void FTerm::init_term_encoding()
{
if ( isatty(stdout_no) if ( isatty(stdout_no)
&& ! std::strcmp(nl_langinfo(CODESET), "UTF-8") ) && ! std::strcmp(nl_langinfo(CODESET), "UTF-8") )
{ {
@ -4197,9 +4216,11 @@ void FTerm::init_encoding()
term_encoding = fc::ASCII; term_encoding = fc::ASCII;
Fputchar = &FTerm::putchar_ASCII; // function pointer Fputchar = &FTerm::putchar_ASCII; // function pointer
} }
}
init_pc_charset(); //----------------------------------------------------------------------
void FTerm::init_individual_term_encoding()
{
if ( linux_terminal if ( linux_terminal
|| cygwin_terminal || cygwin_terminal
|| NewFont || NewFont
@ -4220,24 +4241,43 @@ void FTerm::init_encoding()
Fputchar = &FTerm::putchar_UTF8; // function pointer Fputchar = &FTerm::putchar_UTF8; // function pointer
} }
} }
}
//----------------------------------------------------------------------
bool FTerm::init_force_vt100_encoding()
{
if ( force_vt100 ) if ( force_vt100 )
{ {
vt100_console = true; vt100_console = true;
term_encoding = fc::VT100; term_encoding = fc::VT100;
Fputchar = &FTerm::putchar_ASCII; // function pointer Fputchar = &FTerm::putchar_ASCII; // function pointer
} }
else if ( FTermcap::no_utf8_acs_chars && isUTF8()
return force_vt100;
}
//----------------------------------------------------------------------
void FTerm::init_utf8_without_alt_charset()
{
// Fall back to ascii for utf-8 terminals that
// do not support VT100 line drawings
if ( FTermcap::no_utf8_acs_chars && isUTF8()
&& term_encoding == fc::VT100 ) && term_encoding == fc::VT100 )
{ {
ascii_console = true; ascii_console = true;
term_encoding = fc::ASCII; term_encoding = fc::ASCII;
Fputchar = &FTerm::putchar_ASCII; // function pointer Fputchar = &FTerm::putchar_ASCII; // function pointer
} }
}
//----------------------------------------------------------------------
void FTerm::init_tab_quirks()
{
// In some alternative character sets, a tab character prints a '○' // In some alternative character sets, a tab character prints a '○'
// on the terminal and does not move the cursor to the next tab stop // on the terminal and does not move the cursor to the next tab stop
// position // position
if ( term_encoding == fc::VT100 || term_encoding == fc::PC ) if ( term_encoding == fc::VT100 || term_encoding == fc::PC )
{ {
char* empty = 0; char* empty = 0;