From 44cb96e732f64c2b39d47c95e52bdf4634720acc Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 28 Aug 2016 22:43:14 +0200 Subject: [PATCH] incorrect parameter can now return an error message --- .gitignore | 1 - ChangeLog | 9 ++++- src/fapp.cpp | 30 +++++++++++++- src/fapp.h | 1 + src/fdialog.cpp | 27 ------------- src/fterm.cpp | 96 ++++++++++++++++++++++++++++---------------- src/fterm.h | 1 + test/transparent.cpp | 1 + 8 files changed, 101 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 15e6c3f0..4073dc9b 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,3 @@ test/mandelbrot test/keyboard test/timer test/ui - diff --git a/ChangeLog b/ChangeLog index 25aec7d8..9d2d6f4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ -2016-08-25 Markus Gans +2016-08-28 Markus Gans + * Remove obsolete code from FDialog + * An incorrect parameter can now return an error message + on program exit + * Termcap S2 and S3 fallback only for the vte/gnome-terminal + and the linux terminal + +2016-08-27 Markus Gans * A new inherit background option for characters * Use inherit background for the simple shadows * Updating the transparent example program diff --git a/src/fapp.cpp b/src/fapp.cpp index 2ea73341..a4696b66 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -104,6 +104,15 @@ void FApplication::init() cmd_options(); } +//---------------------------------------------------------------------- +void FApplication::setExitMessage (std::string message) +{ + quit_now = true; + snprintf ( FTerm::exit_message + , sizeof(FTerm::exit_message) + , message.c_str() ); +} + //---------------------------------------------------------------------- void FApplication::cmd_options () { @@ -141,16 +150,29 @@ void FApplication::cmd_options () { setEncoding(encoding.c_str()); } + else + setExitMessage ( "Unknown encoding " + + std::string(encoding.c_str()) ); } if ( strcmp(long_options[idx].name, "no-optimize-cursor") == 0 ) setCursorOptimisation (false); if ( strcmp(long_options[idx].name, "vgafont") == 0 ) - setVGAFont(); + { + bool ret = setVGAFont(); + + if ( ! ret ) + setExitMessage ("VGAfont is not supported by this terminal"); + } if ( strcmp(long_options[idx].name, "newfont") == 0 ) - setNewFont(); + { + bool ret = setNewFont(); + + if ( ! ret ) + setExitMessage ("Newfont is not supported by this terminal"); + } } } } @@ -1753,6 +1775,10 @@ void FApplication::setMainWidget (FWidget* widget) int FApplication::exec() // run { FWidget* widget; + + if ( quit_now ) + return EXIT_FAILURE; + quit_now = false; quit_code = 0; diff --git a/src/fapp.h b/src/fapp.h index 4b2cc12a..01df0c0c 100644 --- a/src/fapp.h +++ b/src/fapp.h @@ -120,6 +120,7 @@ class FApplication : public FWidget FApplication& operator = (const FApplication&); // and operator '=' void init(); + void setExitMessage (std::string); void cmd_options(); bool KeyPressed(); ssize_t readKey(); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 0f50e29b..70e3c940 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -780,21 +780,6 @@ void FDialog::onWindowRaised (FEvent*) if ( window_list->empty() ) return; - - // redraw shadow of the other windows - iter = window_list->begin(); - end = window_list->end(); - - while ( iter != end ) - { - if ( *iter != this && ! maximized - && ((*iter)->getFlags() & fc::shadow) != 0 ) - { - static_cast(*iter)->drawDialogShadow(); - } - - ++iter; - } } //---------------------------------------------------------------------- @@ -814,10 +799,6 @@ void FDialog::onWindowLowered (FEvent*) while ( iter != end ) { putArea ((*iter)->getGlobalPos(), (*iter)->getVWin()); - - if ( ! maximized && ((*iter)->getFlags() & fc::shadow) != 0 ) - static_cast(*iter)->drawDialogShadow(); - ++iter; } } @@ -936,9 +917,6 @@ void FDialog::move (int x, int y) restoreVTerm (old_x, old_y, width+rsw, height+bsh); } - // if ( ! maximized && (flags & fc::shadow) != 0 ) - // drawDialogShadow(); - // handle overlaid windows if ( window_list && ! window_list->empty() ) { @@ -950,13 +928,8 @@ void FDialog::move (int x, int y) while ( iter != end ) { if ( overlaid ) - { putArea ((*iter)->getGlobalPos(), (*iter)->getVWin()); - if ( ! maximized && ((*iter)->getFlags() & fc::shadow) != 0 ) - static_cast(*iter)->drawDialogShadow(); - } - if ( vwin == (*iter)->getVWin() ) overlaid = true; diff --git a/src/fterm.cpp b/src/fterm.cpp index 8a1566c6..3813342e 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -89,6 +89,7 @@ FPoint* FTerm::mouse = 0; FPoint* FTerm::cursor = 0; FRect* FTerm::term = 0; +char FTerm::exit_message[8192] = ""; fc::encoding FTerm::Encoding; const FString* FTerm::xterm_font = 0; const FString* FTerm::xterm_title = 0; @@ -161,6 +162,11 @@ FTerm::~FTerm() // destructor delete term; delete opti_attr; delete opti_move; + + if ( exit_message[0] ) + { + fprintf (stderr, "Warning: %s\n", exit_message); + } } } @@ -1155,44 +1161,47 @@ void FTerm::init_pc_charset() if ( rxvt_terminal || urxvt_terminal ) return; - // fallback if "S2" is not found - if ( ! tcap[t_enter_pc_charset_mode].string ) + if ( gnome_terminal || linux_terminal ) { - if ( utf8_console ) + // fallback if tcap "S2" is not found + if ( ! tcap[t_enter_pc_charset_mode].string ) { - // Select iso8859-1 + null mapping - tcap[t_enter_pc_charset_mode].string = \ - const_cast(ESC "%@" ESC "(U"); - } - else - { - // Select null mapping - tcap[t_enter_pc_charset_mode].string = \ - const_cast(ESC "(U"); + if ( utf8_console ) + { + // Select iso8859-1 + null mapping + tcap[t_enter_pc_charset_mode].string = \ + const_cast(ESC "%@" ESC "(U"); + } + else + { + // Select null mapping + tcap[t_enter_pc_charset_mode].string = \ + const_cast(ESC "(U"); + } + + opti_attr->set_enter_pc_charset_mode (tcap[t_enter_pc_charset_mode].string); + reinit = true; } - opti_attr->set_enter_pc_charset_mode (tcap[t_enter_pc_charset_mode].string); - reinit = true; - } - - // fallback if "S3" is not found - if ( ! tcap[t_exit_pc_charset_mode].string ) - { - if ( utf8_console ) + // fallback if tcap "S3" is not found + if ( ! tcap[t_exit_pc_charset_mode].string ) { - // Select ascii mapping + utf8 - tcap[t_exit_pc_charset_mode].string = \ - const_cast(ESC "(B" ESC "%G"); - } - else - { - // Select ascii mapping - tcap[t_enter_pc_charset_mode].string = \ - const_cast(ESC "(B"); - } + if ( utf8_console ) + { + // Select ascii mapping + utf8 + tcap[t_exit_pc_charset_mode].string = \ + const_cast(ESC "(B" ESC "%G"); + } + else + { + // Select ascii mapping + tcap[t_enter_pc_charset_mode].string = \ + const_cast(ESC "(B"); + } - opti_attr->set_exit_pc_charset_mode (tcap[t_exit_pc_charset_mode].string); - reinit = true; + opti_attr->set_exit_pc_charset_mode (tcap[t_exit_pc_charset_mode].string); + reinit = true; + } } if ( reinit ) @@ -1731,6 +1740,9 @@ void FTerm::init() force_terminal_update = \ non_blocking_stdin = false; + // init arrays with '\0' + std::fill_n (exit_message, sizeof(exit_message), '\0'); + stdin_no = fileno(stdin); stdout_no = fileno(stdout); stdin_status_flags = fcntl(stdin_no, F_GETFL); @@ -3017,6 +3029,14 @@ bool FTerm::setVGAFont() if ( VGAFont ) return VGAFont; + if ( gnome_terminal + || kde_konsole + || putty_terminal + || tera_terminal + || cygwin_terminal + || mintty_terminal ) + return false; + VGAFont = true; if ( xterm || screen_terminal || osc_support ) @@ -3079,6 +3099,14 @@ bool FTerm::setNewFont() if ( NewFont ) return true; + if ( gnome_terminal + || kde_konsole + || putty_terminal + || tera_terminal + || cygwin_terminal + || mintty_terminal ) + return false; + if ( xterm || screen_terminal || urxvt_terminal || osc_support ) { NewFont = true; @@ -3090,7 +3118,7 @@ bool FTerm::setNewFont() pc_charset_console = true; Encoding = fc::PC; - if ( xterm && utf8_console ) + if ( xterm && utf8_console ) Fputchar = &FTerm::putchar_UTF8; else Fputchar = &FTerm::putchar_ASCII; @@ -4644,7 +4672,7 @@ int FTerm::print (FTerm::term_area* area, register int c) inline void FTerm::newFontChanges (FOptiAttr::char_data*& next_char) { // NewFont special cases - if ( isNewFont() ) + if ( NewFont ) { switch ( next_char->code ) { diff --git a/src/fterm.h b/src/fterm.h index 3064a4cf..f7842c4c 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -162,6 +162,7 @@ class FTerm static int x_term_pos; static int y_term_pos; static bool resize_term; + static char exit_message[8192]; static struct termios term_init; static FOptiAttr::char_data term_attribute; diff --git a/test/transparent.cpp b/test/transparent.cpp index 74d45114..68fc92fd 100644 --- a/test/transparent.cpp +++ b/test/transparent.cpp @@ -179,6 +179,7 @@ void MainWindow::draw() { FDialog::draw(); updateVTerm(false); + if ( isMonochron() ) setReverse(true);