Improved command line paramenter handlin
This commit is contained in:
parent
053b6bcf30
commit
9c987ca49c
|
@ -1,3 +1,8 @@
|
||||||
|
2017-11-18 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Improved command line paramenter handling
|
||||||
|
* New command line paramenter --no-terminal-detection
|
||||||
|
* New command line paramenter --no-color-change
|
||||||
|
|
||||||
2017-11-11 Markus Gans <guru.mail@muenster.de>
|
2017-11-11 Markus Gans <guru.mail@muenster.de>
|
||||||
* Improved code coverage tests
|
* Improved code coverage tests
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,8 @@ class FApplication : public FWidget
|
||||||
static void sendQueuedEvents ();
|
static void sendQueuedEvents ();
|
||||||
static bool eventInQueue();
|
static bool eventInQueue();
|
||||||
static bool removeQueuedEvent (const FObject*);
|
static bool removeQueuedEvent (const FObject*);
|
||||||
static FWidget* showParameterUsage (const int&, char*[]);
|
static FWidget* processParameters (const int&, char*[]);
|
||||||
|
static void showParameterUsage ();
|
||||||
static void closeConfirmationDialog (FWidget*, FCloseEvent*);
|
static void closeConfirmationDialog (FWidget*, FCloseEvent*);
|
||||||
|
|
||||||
// Callback method
|
// Callback method
|
||||||
|
@ -148,8 +149,7 @@ class FApplication : public FWidget
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
void init();
|
void init();
|
||||||
void setExitMessage (std::string);
|
static void cmd_options (const int&, char*[]);
|
||||||
void cmd_options();
|
|
||||||
|
|
||||||
#ifdef F_HAVE_LIBGPM
|
#ifdef F_HAVE_LIBGPM
|
||||||
int gpmEvent (bool = true);
|
int gpmEvent (bool = true);
|
||||||
|
|
|
@ -112,7 +112,8 @@ class fc
|
||||||
VT100,
|
VT100,
|
||||||
PC,
|
PC,
|
||||||
ASCII,
|
ASCII,
|
||||||
NUM_OF_ENCODINGS // number of items
|
NUM_OF_ENCODINGS, // number of items
|
||||||
|
UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
// VT100 line graphic keys
|
// VT100 line graphic keys
|
||||||
|
|
|
@ -260,8 +260,9 @@ class FTerm
|
||||||
static void resetBeep();
|
static void resetBeep();
|
||||||
static void beep();
|
static void beep();
|
||||||
|
|
||||||
static void setEncoding (std::string);
|
static void setEncoding (fc::encoding);
|
||||||
static std::string getEncoding();
|
static fc::encoding getEncoding();
|
||||||
|
static std::string getEncodingString();
|
||||||
|
|
||||||
static bool scrollTermForward();
|
static bool scrollTermForward();
|
||||||
static bool scrollTermReverse();
|
static bool scrollTermReverse();
|
||||||
|
@ -300,9 +301,6 @@ class FTerm
|
||||||
static void initFreeBSDConsoleCharMap();
|
static void initFreeBSDConsoleCharMap();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void initCygwinCharMap();
|
|
||||||
static void initTeraTermCharMap();
|
|
||||||
|
|
||||||
static bool charEncodable (uInt);
|
static bool charEncodable (uInt);
|
||||||
static uInt charEncode (uInt);
|
static uInt charEncode (uInt);
|
||||||
static uInt charEncode (uInt, fc::encoding);
|
static uInt charEncode (uInt, fc::encoding);
|
||||||
|
@ -324,6 +322,7 @@ class FTerm
|
||||||
static FPoint& getMousePos();
|
static FPoint& getMousePos();
|
||||||
static void setMousePos (const FPoint&);
|
static void setMousePos (const FPoint&);
|
||||||
static void setMousePos (short, short);
|
static void setMousePos (short, short);
|
||||||
|
static void exitWithMessage (std::string);
|
||||||
|
|
||||||
// Data Members
|
// Data Members
|
||||||
static int stdin_no;
|
static int stdin_no;
|
||||||
|
@ -340,9 +339,33 @@ class FTerm
|
||||||
static bool cursor_optimisation;
|
static bool cursor_optimisation;
|
||||||
static bool xterm_default_colors;
|
static bool xterm_default_colors;
|
||||||
static bool use_alternate_screen;
|
static bool use_alternate_screen;
|
||||||
static fc::encoding Encoding;
|
static fc::encoding term_encoding;
|
||||||
static char exit_message[8192];
|
static char exit_message[8192];
|
||||||
|
|
||||||
|
static struct initializationValues
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
initializationValues()
|
||||||
|
: terminal_detection(true)
|
||||||
|
, cursor_optimisation(true)
|
||||||
|
, color_change(true)
|
||||||
|
, vgafont(false)
|
||||||
|
, newfont(false)
|
||||||
|
, encoding(fc::UNKNOWN)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
~initializationValues()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
uInt8 terminal_detection : 1;
|
||||||
|
uInt8 cursor_optimisation : 1;
|
||||||
|
uInt8 color_change : 1;
|
||||||
|
uInt8 vgafont : 1;
|
||||||
|
uInt8 newfont : 1;
|
||||||
|
uInt8 : 3; // padding bits
|
||||||
|
fc::encoding encoding;
|
||||||
|
} init_values;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Typedefs
|
// Typedefs
|
||||||
typedef FTermcap::tcap_map termcap_map;
|
typedef FTermcap::tcap_map termcap_map;
|
||||||
|
@ -418,6 +441,9 @@ class FTerm
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uInt getBaudRate (const struct termios*);
|
static uInt getBaudRate (const struct termios*);
|
||||||
|
static void init_global_values();
|
||||||
|
static void detectTerminal();
|
||||||
|
static void termtypeAnalysis();
|
||||||
static char* init_256colorTerminal();
|
static char* init_256colorTerminal();
|
||||||
static char* parseAnswerbackMsg (char*&);
|
static char* parseAnswerbackMsg (char*&);
|
||||||
static char* parseSecDA (char*&);
|
static char* parseSecDA (char*&);
|
||||||
|
@ -425,11 +451,18 @@ class FTerm
|
||||||
static void oscPostfix();
|
static void oscPostfix();
|
||||||
static void init_alt_charset();
|
static void init_alt_charset();
|
||||||
static void init_pc_charset();
|
static void init_pc_charset();
|
||||||
|
static void init_cygwin_charmap();
|
||||||
|
static void init_teraterm_charmap();
|
||||||
static void init_termcaps();
|
static void init_termcaps();
|
||||||
|
static void init_locale();
|
||||||
static void init_encoding();
|
static void init_encoding();
|
||||||
|
static void redefineColorPalette();
|
||||||
|
static void restoreColorPalette();
|
||||||
void init();
|
void init();
|
||||||
void finish();
|
void finish();
|
||||||
static uInt cp437_to_unicode (uChar);
|
static uInt cp437_to_unicode (uChar);
|
||||||
|
static void setSignalHandler();
|
||||||
|
static void resetSignalHandler();
|
||||||
static void signal_handler (int);
|
static void signal_handler (int);
|
||||||
|
|
||||||
// Data Members
|
// Data Members
|
||||||
|
|
|
@ -58,7 +58,7 @@ FApplication::eventQueue* FApplication::event_queue = 0;
|
||||||
FApplication::FApplication ( const int& _argc
|
FApplication::FApplication ( const int& _argc
|
||||||
, char* _argv[]
|
, char* _argv[]
|
||||||
, bool disable_alt_screen )
|
, bool disable_alt_screen )
|
||||||
: FWidget(showParameterUsage(_argc,_argv), disable_alt_screen)
|
: FWidget(processParameters(_argc,_argv), disable_alt_screen)
|
||||||
, app_argc(_argc)
|
, app_argc(_argc)
|
||||||
, app_argv(_argv)
|
, app_argv(_argv)
|
||||||
, key(0)
|
, key(0)
|
||||||
|
@ -310,11 +310,21 @@ bool FApplication::removeQueuedEvent (const FObject* receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FWidget* FApplication::showParameterUsage (const int& argc, char* argv[])
|
FWidget* FApplication::processParameters (const int& argc, char* argv[])
|
||||||
{
|
{
|
||||||
if ( argc > 0 && argv[1] && ( std::strcmp(argv[1], "--help") == 0
|
if ( argc > 0 && argv[1] && ( std::strcmp(argv[1], "--help") == 0
|
||||||
|| std::strcmp(argv[1], "-h") == 0 ) )
|
|| std::strcmp(argv[1], "-h") == 0 ) )
|
||||||
{
|
{
|
||||||
|
showParameterUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_options (argc, argv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FApplication::showParameterUsage()
|
||||||
|
{
|
||||||
std::cout \
|
std::cout \
|
||||||
<< "Generic options:" << std::endl
|
<< "Generic options:" << std::endl
|
||||||
<< " -h, --help "
|
<< " -h, --help "
|
||||||
|
@ -325,16 +335,17 @@ FWidget* FApplication::showParameterUsage (const int& argc, char* argv[])
|
||||||
<< " Sets the character encoding mode" << std::endl
|
<< " Sets the character encoding mode" << std::endl
|
||||||
<< " "
|
<< " "
|
||||||
<< " {UTF8, VT100, PC, ASCII}" << std::endl
|
<< " {UTF8, VT100, PC, ASCII}" << std::endl
|
||||||
<< " --no-optimized-cursor"
|
<< " --no-optimized-cursor "
|
||||||
<< " No cursor optimisation" << std::endl
|
<< " Disable cursor optimization" << std::endl
|
||||||
|
<< " --no-terminal-detection"
|
||||||
|
<< " Disable terminal detection" << std::endl
|
||||||
|
<< " --no-color-change "
|
||||||
|
<< " Do not redefine the color palette" << std::endl
|
||||||
<< " --vgafont "
|
<< " --vgafont "
|
||||||
<< " Set the standard vga 8x16 font" << std::endl
|
<< " Set the standard vga 8x16 font" << std::endl
|
||||||
<< " --newfont "
|
<< " --newfont "
|
||||||
<< " Enables the graphical font" << std::endl;
|
<< " Enables the graphical font" << std::endl;
|
||||||
std::exit(EXIT_SUCCESS);
|
std::exit(EXIT_SUCCESS);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -385,24 +396,13 @@ void FApplication::init()
|
||||||
std::fill_n (urxvt_mouse, sizeof(urxvt_mouse), '\0');
|
std::fill_n (urxvt_mouse, sizeof(urxvt_mouse), '\0');
|
||||||
// init bit field with 0
|
// init bit field with 0
|
||||||
std::memset(&b_state, 0x00, sizeof(b_state));
|
std::memset(&b_state, 0x00, sizeof(b_state));
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FApplication::cmd_options (const int& argc, char* argv[])
|
||||||
|
{
|
||||||
// interpret the command line options
|
// interpret the command line options
|
||||||
cmd_options();
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
void FApplication::setExitMessage (std::string message)
|
|
||||||
{
|
|
||||||
quit_now = true;
|
|
||||||
snprintf ( FTerm::exit_message
|
|
||||||
, sizeof(FTerm::exit_message)
|
|
||||||
, "%s"
|
|
||||||
, message.c_str() );
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
void FApplication::cmd_options ()
|
|
||||||
{
|
|
||||||
while ( true )
|
while ( true )
|
||||||
{
|
{
|
||||||
int c, idx = 0;
|
int c, idx = 0;
|
||||||
|
@ -411,14 +411,16 @@ void FApplication::cmd_options ()
|
||||||
{
|
{
|
||||||
{"encoding", required_argument, 0, 0 },
|
{"encoding", required_argument, 0, 0 },
|
||||||
{"no-optimized-cursor", no_argument, 0, 0 },
|
{"no-optimized-cursor", no_argument, 0, 0 },
|
||||||
|
{"no-terminal-detection", no_argument, 0, 0 },
|
||||||
|
{"no-color-change", no_argument, 0, 0 },
|
||||||
{"vgafont", no_argument, 0, 0 },
|
{"vgafont", no_argument, 0, 0 },
|
||||||
{"newfont", no_argument, 0, 0 },
|
{"newfont", no_argument, 0, 0 },
|
||||||
{0, 0, 0, 0 }
|
{0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
c = getopt_long ( app_argc
|
c = getopt_long ( argc
|
||||||
, app_argv
|
, argv
|
||||||
, ""
|
, ""
|
||||||
, long_options
|
, long_options
|
||||||
, &idx );
|
, &idx );
|
||||||
|
@ -432,36 +434,35 @@ void FApplication::cmd_options ()
|
||||||
FString encoding(optarg);
|
FString encoding(optarg);
|
||||||
encoding = encoding.toUpper();
|
encoding = encoding.toUpper();
|
||||||
|
|
||||||
if ( encoding.includes("UTF8")
|
if ( encoding.includes("UTF8") )
|
||||||
|| encoding.includes("VT100")
|
init_values.encoding = fc::UTF8;
|
||||||
|| encoding.includes("PC")
|
else if ( encoding.includes("VT100") )
|
||||||
|| encoding.includes("ASCII") )
|
init_values.encoding = fc::VT100;
|
||||||
{
|
else if ( encoding.includes("PC") )
|
||||||
setEncoding(encoding.c_str());
|
init_values.encoding = fc::PC;
|
||||||
}
|
else if ( encoding.includes("ASCII") )
|
||||||
|
init_values.encoding = fc::ASCII;
|
||||||
|
else if ( encoding.includes("HELP") )
|
||||||
|
showParameterUsage();
|
||||||
else
|
else
|
||||||
setExitMessage ( "Unknown encoding "
|
exitWithMessage ( "Unknown encoding "
|
||||||
+ std::string(encoding.c_str()) );
|
+ std::string(encoding.c_str()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 )
|
if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 )
|
||||||
setCursorOptimisation (false);
|
init_values.cursor_optimisation = false;
|
||||||
|
|
||||||
|
if ( std::strcmp(long_options[idx].name, "no-terminal-detection") == 0 )
|
||||||
|
init_values.terminal_detection = false;
|
||||||
|
|
||||||
|
if ( std::strcmp(long_options[idx].name, "no-color-change") == 0 )
|
||||||
|
init_values.color_change = false;
|
||||||
|
|
||||||
if ( std::strcmp(long_options[idx].name, "vgafont") == 0 )
|
if ( std::strcmp(long_options[idx].name, "vgafont") == 0 )
|
||||||
{
|
init_values.vgafont = true;
|
||||||
bool ret = setVGAFont();
|
|
||||||
|
|
||||||
if ( ! ret )
|
|
||||||
setExitMessage ("VGAfont is not supported by this terminal");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
|
if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
|
||||||
{
|
init_values.newfont = true;
|
||||||
bool ret = setNewFont();
|
|
||||||
|
|
||||||
if ( ! ret )
|
|
||||||
setExitMessage ("Newfont is not supported by this terminal");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,8 +206,8 @@ bool FButton::setFlat (bool on)
|
||||||
bool FButton::setShadow (bool on)
|
bool FButton::setShadow (bool on)
|
||||||
{
|
{
|
||||||
if ( on
|
if ( on
|
||||||
&& Encoding != fc::VT100
|
&& term_encoding != fc::VT100
|
||||||
&& Encoding != fc::ASCII )
|
&& term_encoding != fc::ASCII )
|
||||||
{
|
{
|
||||||
flags |= fc::shadow;
|
flags |= fc::shadow;
|
||||||
setShadowSize(1,1);
|
setShadowSize(1,1);
|
||||||
|
|
|
@ -234,8 +234,8 @@ bool FLineEdit::setFocus (bool on)
|
||||||
bool FLineEdit::setShadow (bool on)
|
bool FLineEdit::setShadow (bool on)
|
||||||
{
|
{
|
||||||
if ( on
|
if ( on
|
||||||
&& Encoding != fc::VT100
|
&& term_encoding != fc::VT100
|
||||||
&& Encoding != fc::ASCII )
|
&& term_encoding != fc::ASCII )
|
||||||
{
|
{
|
||||||
flags |= fc::shadow;
|
flags |= fc::shadow;
|
||||||
setShadowSize(1,1);
|
setShadowSize(1,1);
|
||||||
|
|
|
@ -1344,7 +1344,7 @@ void FMenu::drawItems()
|
||||||
{
|
{
|
||||||
setColor (wc.menu_inactive_fg, getBackgroundColor());
|
setColor (wc.menu_inactive_fg, getBackgroundColor());
|
||||||
|
|
||||||
if ( getEncoding() == "ASCII" )
|
if ( getEncoding() == fc::ASCII )
|
||||||
print ('-');
|
print ('-');
|
||||||
else
|
else
|
||||||
print (fc::SmallBullet); // ·
|
print (fc::SmallBullet); // ·
|
||||||
|
|
|
@ -79,8 +79,8 @@ void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust)
|
||||||
bool FProgressbar::setShadow (bool on)
|
bool FProgressbar::setShadow (bool on)
|
||||||
{
|
{
|
||||||
if ( on
|
if ( on
|
||||||
&& Encoding != fc::VT100
|
&& term_encoding != fc::VT100
|
||||||
&& Encoding != fc::ASCII )
|
&& term_encoding != fc::ASCII )
|
||||||
{
|
{
|
||||||
flags |= fc::shadow;
|
flags |= fc::shadow;
|
||||||
setShadowSize(1,1);
|
setShadowSize(1,1);
|
||||||
|
|
801
src/fterm.cpp
801
src/fterm.cpp
File diff suppressed because it is too large
Load Diff
|
@ -791,7 +791,7 @@ void FTextView::drawText()
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
wchar_t ch = line_str[i];
|
wchar_t ch = line_str[i];
|
||||||
bool utf8 = ( Encoding == fc::UTF8 ) ? true : false;
|
bool utf8 = ( term_encoding == fc::UTF8 ) ? true : false;
|
||||||
|
|
||||||
// only printable and 1 column per character
|
// only printable and 1 column per character
|
||||||
if ( ( (utf8 && std::iswprint(wint_t(ch)))
|
if ( ( (utf8 && std::iswprint(wint_t(ch)))
|
||||||
|
|
|
@ -2717,7 +2717,7 @@ inline void FVTerm::newFontChanges (char_data*& next_char)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline void FVTerm::charsetChanges (char_data*& next_char)
|
inline void FVTerm::charsetChanges (char_data*& next_char)
|
||||||
{
|
{
|
||||||
if ( Encoding == fc::UTF8 )
|
if ( term_encoding == fc::UTF8 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uInt code = uInt(next_char->code);
|
uInt code = uInt(next_char->code);
|
||||||
|
@ -2733,9 +2733,9 @@ inline void FVTerm::charsetChanges (char_data*& next_char)
|
||||||
|
|
||||||
next_char->code = int(ch_enc);
|
next_char->code = int(ch_enc);
|
||||||
|
|
||||||
if ( Encoding == fc::VT100 )
|
if ( term_encoding == fc::VT100 )
|
||||||
next_char->attr.bit.alt_charset = true;
|
next_char->attr.bit.alt_charset = true;
|
||||||
else if ( Encoding == fc::PC )
|
else if ( term_encoding == fc::PC )
|
||||||
{
|
{
|
||||||
next_char->attr.bit.pc_charset = true;
|
next_char->attr.bit.pc_charset = true;
|
||||||
|
|
||||||
|
|
|
@ -1411,8 +1411,8 @@ void FWidget::drawShadow()
|
||||||
if ( isMonochron() && ! trans_shadow )
|
if ( isMonochron() && ! trans_shadow )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( (Encoding == fc::VT100 && ! trans_shadow)
|
if ( (term_encoding == fc::VT100 && ! trans_shadow)
|
||||||
|| (Encoding == fc::ASCII && ! trans_shadow) )
|
|| (term_encoding == fc::ASCII && ! trans_shadow) )
|
||||||
{
|
{
|
||||||
clearShadow();
|
clearShadow();
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue