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>
|
||||
* Improved code coverage tests
|
||||
|
||||
|
|
|
@ -110,7 +110,8 @@ class FApplication : public FWidget
|
|||
static void sendQueuedEvents ();
|
||||
static bool eventInQueue();
|
||||
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*);
|
||||
|
||||
// Callback method
|
||||
|
@ -148,8 +149,7 @@ class FApplication : public FWidget
|
|||
|
||||
// Methods
|
||||
void init();
|
||||
void setExitMessage (std::string);
|
||||
void cmd_options();
|
||||
static void cmd_options (const int&, char*[]);
|
||||
|
||||
#ifdef F_HAVE_LIBGPM
|
||||
int gpmEvent (bool = true);
|
||||
|
|
|
@ -112,7 +112,8 @@ class fc
|
|||
VT100,
|
||||
PC,
|
||||
ASCII,
|
||||
NUM_OF_ENCODINGS // number of items
|
||||
NUM_OF_ENCODINGS, // number of items
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
// VT100 line graphic keys
|
||||
|
|
|
@ -260,8 +260,9 @@ class FTerm
|
|||
static void resetBeep();
|
||||
static void beep();
|
||||
|
||||
static void setEncoding (std::string);
|
||||
static std::string getEncoding();
|
||||
static void setEncoding (fc::encoding);
|
||||
static fc::encoding getEncoding();
|
||||
static std::string getEncodingString();
|
||||
|
||||
static bool scrollTermForward();
|
||||
static bool scrollTermReverse();
|
||||
|
@ -300,9 +301,6 @@ class FTerm
|
|||
static void initFreeBSDConsoleCharMap();
|
||||
#endif
|
||||
|
||||
static void initCygwinCharMap();
|
||||
static void initTeraTermCharMap();
|
||||
|
||||
static bool charEncodable (uInt);
|
||||
static uInt charEncode (uInt);
|
||||
static uInt charEncode (uInt, fc::encoding);
|
||||
|
@ -324,6 +322,7 @@ class FTerm
|
|||
static FPoint& getMousePos();
|
||||
static void setMousePos (const FPoint&);
|
||||
static void setMousePos (short, short);
|
||||
static void exitWithMessage (std::string);
|
||||
|
||||
// Data Members
|
||||
static int stdin_no;
|
||||
|
@ -340,9 +339,33 @@ class FTerm
|
|||
static bool cursor_optimisation;
|
||||
static bool xterm_default_colors;
|
||||
static bool use_alternate_screen;
|
||||
static fc::encoding Encoding;
|
||||
static fc::encoding term_encoding;
|
||||
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:
|
||||
// Typedefs
|
||||
typedef FTermcap::tcap_map termcap_map;
|
||||
|
@ -418,6 +441,9 @@ class FTerm
|
|||
#endif
|
||||
|
||||
static uInt getBaudRate (const struct termios*);
|
||||
static void init_global_values();
|
||||
static void detectTerminal();
|
||||
static void termtypeAnalysis();
|
||||
static char* init_256colorTerminal();
|
||||
static char* parseAnswerbackMsg (char*&);
|
||||
static char* parseSecDA (char*&);
|
||||
|
@ -425,11 +451,18 @@ class FTerm
|
|||
static void oscPostfix();
|
||||
static void init_alt_charset();
|
||||
static void init_pc_charset();
|
||||
static void init_cygwin_charmap();
|
||||
static void init_teraterm_charmap();
|
||||
static void init_termcaps();
|
||||
static void init_locale();
|
||||
static void init_encoding();
|
||||
static void redefineColorPalette();
|
||||
static void restoreColorPalette();
|
||||
void init();
|
||||
void finish();
|
||||
static uInt cp437_to_unicode (uChar);
|
||||
static void setSignalHandler();
|
||||
static void resetSignalHandler();
|
||||
static void signal_handler (int);
|
||||
|
||||
// Data Members
|
||||
|
|
|
@ -58,7 +58,7 @@ FApplication::eventQueue* FApplication::event_queue = 0;
|
|||
FApplication::FApplication ( const int& _argc
|
||||
, char* _argv[]
|
||||
, bool disable_alt_screen )
|
||||
: FWidget(showParameterUsage(_argc,_argv), disable_alt_screen)
|
||||
: FWidget(processParameters(_argc,_argv), disable_alt_screen)
|
||||
, app_argc(_argc)
|
||||
, app_argv(_argv)
|
||||
, key(0)
|
||||
|
@ -310,10 +310,20 @@ 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
|
||||
|| std::strcmp(argv[1], "-h") == 0 ) )
|
||||
{
|
||||
showParameterUsage();
|
||||
}
|
||||
|
||||
cmd_options (argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::showParameterUsage()
|
||||
{
|
||||
std::cout \
|
||||
<< "Generic options:" << std::endl
|
||||
|
@ -326,7 +336,11 @@ FWidget* FApplication::showParameterUsage (const int& argc, char* argv[])
|
|||
<< " "
|
||||
<< " {UTF8, VT100, PC, ASCII}" << std::endl
|
||||
<< " --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 "
|
||||
<< " Set the standard vga 8x16 font" << std::endl
|
||||
<< " --newfont "
|
||||
|
@ -334,9 +348,6 @@ FWidget* FApplication::showParameterUsage (const int& argc, char* argv[])
|
|||
std::exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev)
|
||||
{
|
||||
|
@ -385,24 +396,13 @@ void FApplication::init()
|
|||
std::fill_n (urxvt_mouse, sizeof(urxvt_mouse), '\0');
|
||||
// init bit field with 0
|
||||
std::memset(&b_state, 0x00, sizeof(b_state));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::cmd_options (const int& argc, char* argv[])
|
||||
{
|
||||
// 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 )
|
||||
{
|
||||
int c, idx = 0;
|
||||
|
@ -411,14 +411,16 @@ void FApplication::cmd_options ()
|
|||
{
|
||||
{"encoding", required_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 },
|
||||
{"newfont", no_argument, 0, 0 },
|
||||
{0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
opterr = 0;
|
||||
c = getopt_long ( app_argc
|
||||
, app_argv
|
||||
c = getopt_long ( argc
|
||||
, argv
|
||||
, ""
|
||||
, long_options
|
||||
, &idx );
|
||||
|
@ -432,36 +434,35 @@ void FApplication::cmd_options ()
|
|||
FString encoding(optarg);
|
||||
encoding = encoding.toUpper();
|
||||
|
||||
if ( encoding.includes("UTF8")
|
||||
|| encoding.includes("VT100")
|
||||
|| encoding.includes("PC")
|
||||
|| encoding.includes("ASCII") )
|
||||
{
|
||||
setEncoding(encoding.c_str());
|
||||
}
|
||||
if ( encoding.includes("UTF8") )
|
||||
init_values.encoding = fc::UTF8;
|
||||
else if ( encoding.includes("VT100") )
|
||||
init_values.encoding = fc::VT100;
|
||||
else if ( encoding.includes("PC") )
|
||||
init_values.encoding = fc::PC;
|
||||
else if ( encoding.includes("ASCII") )
|
||||
init_values.encoding = fc::ASCII;
|
||||
else if ( encoding.includes("HELP") )
|
||||
showParameterUsage();
|
||||
else
|
||||
setExitMessage ( "Unknown encoding "
|
||||
exitWithMessage ( "Unknown encoding "
|
||||
+ std::string(encoding.c_str()) );
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
bool ret = setVGAFont();
|
||||
|
||||
if ( ! ret )
|
||||
setExitMessage ("VGAfont is not supported by this terminal");
|
||||
}
|
||||
init_values.vgafont = true;
|
||||
|
||||
if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
|
||||
{
|
||||
bool ret = setNewFont();
|
||||
|
||||
if ( ! ret )
|
||||
setExitMessage ("Newfont is not supported by this terminal");
|
||||
}
|
||||
init_values.newfont = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,8 +206,8 @@ bool FButton::setFlat (bool on)
|
|||
bool FButton::setShadow (bool on)
|
||||
{
|
||||
if ( on
|
||||
&& Encoding != fc::VT100
|
||||
&& Encoding != fc::ASCII )
|
||||
&& term_encoding != fc::VT100
|
||||
&& term_encoding != fc::ASCII )
|
||||
{
|
||||
flags |= fc::shadow;
|
||||
setShadowSize(1,1);
|
||||
|
|
|
@ -234,8 +234,8 @@ bool FLineEdit::setFocus (bool on)
|
|||
bool FLineEdit::setShadow (bool on)
|
||||
{
|
||||
if ( on
|
||||
&& Encoding != fc::VT100
|
||||
&& Encoding != fc::ASCII )
|
||||
&& term_encoding != fc::VT100
|
||||
&& term_encoding != fc::ASCII )
|
||||
{
|
||||
flags |= fc::shadow;
|
||||
setShadowSize(1,1);
|
||||
|
|
|
@ -1344,7 +1344,7 @@ void FMenu::drawItems()
|
|||
{
|
||||
setColor (wc.menu_inactive_fg, getBackgroundColor());
|
||||
|
||||
if ( getEncoding() == "ASCII" )
|
||||
if ( getEncoding() == fc::ASCII )
|
||||
print ('-');
|
||||
else
|
||||
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)
|
||||
{
|
||||
if ( on
|
||||
&& Encoding != fc::VT100
|
||||
&& Encoding != fc::ASCII )
|
||||
&& term_encoding != fc::VT100
|
||||
&& term_encoding != fc::ASCII )
|
||||
{
|
||||
flags |= fc::shadow;
|
||||
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++)
|
||||
{
|
||||
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
|
||||
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)
|
||||
{
|
||||
if ( Encoding == fc::UTF8 )
|
||||
if ( term_encoding == fc::UTF8 )
|
||||
return;
|
||||
|
||||
uInt code = uInt(next_char->code);
|
||||
|
@ -2733,9 +2733,9 @@ inline void FVTerm::charsetChanges (char_data*& next_char)
|
|||
|
||||
next_char->code = int(ch_enc);
|
||||
|
||||
if ( Encoding == fc::VT100 )
|
||||
if ( term_encoding == fc::VT100 )
|
||||
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;
|
||||
|
||||
|
|
|
@ -1411,8 +1411,8 @@ void FWidget::drawShadow()
|
|||
if ( isMonochron() && ! trans_shadow )
|
||||
return;
|
||||
|
||||
if ( (Encoding == fc::VT100 && ! trans_shadow)
|
||||
|| (Encoding == fc::ASCII && ! trans_shadow) )
|
||||
if ( (term_encoding == fc::VT100 && ! trans_shadow)
|
||||
|| (term_encoding == fc::ASCII && ! trans_shadow) )
|
||||
{
|
||||
clearShadow();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue