From a41727c4fc6c0c510abe4805b6fe84b17be56dfd Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 11 Oct 2015 04:09:58 +0200 Subject: [PATCH] Improve attribute setting for bold, reverse and underline output --- ChangeLog | 3 ++ doc/TODO | 15 +++++++++- src/fdialog.cpp | 9 ++++-- src/flineedit.cpp | 4 +-- src/fmenu.cpp | 2 +- src/fmenubar.cpp | 5 ++++ src/fswitch.cpp | 24 +++++++++++++++- src/fterm.cpp | 71 ++++++++++++++++++++++++++++++++++++++++------- src/fterm.h | 1 + src/fwidget.cpp | 12 ++++---- 10 files changed, 122 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a4a95f7..5cdd1994 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2015-10-11 Markus Gans + * Improve attribute setting for bold, reverse and underline output + 2015-10-10 Markus Gans * Deactivate a key from the status bar automatically after getting back from the callback. diff --git a/doc/TODO b/doc/TODO index 7fec59d2..6296f481 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,6 +1,19 @@ Bugs ~~~~ -- +- + + +Improvements +~~~~~~~~~~~~ +- Use only termpap variables for FTerm::hideCursor() +- If t_exit_underline_mode == "\E[24m" + -> implement t_exit_bold_mode with "\E[21m" + -> implement t_exit_reverse_mode with "\E[27m" +- New behavior in FTerm::appendAttributes(...) + - 1st: reset don't needed attributes (bold, reverse and underline) + - 2nd: set the foreground and background color + - 3rd: set new attributes (bold, reverse and underline) + Missing Features ~~~~~~~~~~~~~~~~ diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 550b2ddc..b43428e2 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -198,12 +198,18 @@ void FDialog::drawTitleBar() // draw the title button gotoxy (xpos+xmin-1, ypos+ymin-1); setColor (wc.titlebar_button_fg, wc.titlebar_button_bg); + + if ( isMonochron() ) + setReverse(true); + if ( isNewFont() ) { print (fc::NF_rev_menu_button1); print (fc::NF_rev_menu_button2); print (fc::NF_rev_menu_button3); } + else if ( isMonochron() ) + print ("[-]"); else print (" - "); @@ -213,9 +219,6 @@ void FDialog::drawTitleBar() else setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg); - if ( isMonochron() ) - setReverse(true); - i = width - 3 - int(length); i = int(i/2); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index f8e3d594..51ce342c 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -138,8 +138,8 @@ void FLineEdit::drawInputField() gotoxy (xpos+xmin-1, ypos+ymin-1); if ( isMonochron() ) { - setReverse(true); print (' '); + setUnderline(true); } else if ( isActiveFocus ) { @@ -190,7 +190,7 @@ void FLineEdit::drawInputField() x++; } if ( isMonochron() ) - setReverse(false); + setUnderline(false); if ( isShadow ) drawShadow (); diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 6dd3be48..71e42d9c 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -565,7 +565,7 @@ FMessageBox::info (this, "Info", FString().sprintf("local(%d,%d) global(%d,%d)\n ev = new FMouseEvent (MouseMove_Event, p, g, b); setClickedWidget(menubar); FMenuBar* sm = reinterpret_cast(menubar); - sm->onMouseMove(ev); + sm->onMouseDown(ev); delete ev; } diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index c76e6f48..8c97a299 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -137,6 +137,8 @@ void FMenuBar::drawItems() iter = itemlist.begin(); end = itemlist.end(); + if ( isMonochron() ) + setReverse(true); while ( iter != end ) { wchar_t* src; @@ -231,8 +233,11 @@ void FMenuBar::drawItems() ++iter; } + for (; x <= screenWidth; x++) print (vmenubar, ' '); + if ( isMonochron() ) + setReverse(false); setUpdateVTerm(true); } diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 140f8af9..a56007fa 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -61,7 +61,8 @@ void FSwitch::drawCheckButton() { if ( hasFocus() && ! button_pressed ) { - + if ( isMonochron() ) + setBold(true); if ( isMonochron() || getMaxColor() < 16 ) { wcsncpy ( on, L" ", 6); @@ -75,7 +76,16 @@ void FSwitch::drawCheckButton() setColor (wc.button_active_focus_fg, wc.button_active_bg); else setColor (wc.button_hotkey_fg, wc.button_active_bg); + + if ( isMonochron() ) + setReverse(true); print (on); + if ( isMonochron() ) + { + setReverse(false); + setBold(false); + } + setColor (wc.button_inactive_fg, wc.button_inactive_bg); print (off); setCursorPos ( xpos + xmin + 1 + switch_offset_pos @@ -85,8 +95,11 @@ void FSwitch::drawCheckButton() { setColor (wc.button_inactive_fg, wc.button_inactive_bg); print (on); + if ( hasFocus() && ! button_pressed ) { + if ( isMonochron() ) + setBold(true); if ( isMonochron() || getMaxColor() < 16 ) { wcsncpy ( off, L"", 6); @@ -100,7 +113,16 @@ void FSwitch::drawCheckButton() setColor (wc.button_active_focus_fg, wc.button_active_bg); else setColor (wc.button_hotkey_fg, wc.button_active_bg); + + if ( isMonochron() ) + setReverse(true); print (off); + if ( isMonochron() ) + { + setReverse(false); + setBold(false); + } + setCursorPos ( xpos + xmin + 5 + switch_offset_pos , ypos + ymin - 1 ); } diff --git a/src/fterm.cpp b/src/fterm.cpp index e8493788..e9a866d8 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -55,6 +55,7 @@ bool FTerm::non_blocking_stdin; bool FTerm::gpm_mouse_enabled; bool FTerm::color256; bool FTerm::monochron; +bool FTerm::exit_underline_caused_reset; bool FTerm::background_color_erase; bool FTerm::automatic_left_margin; bool FTerm::automatic_right_margin; @@ -1103,6 +1104,19 @@ void FTerm::init_termcaps() tcap[t_cursor_address].string = \ const_cast("\033[%i%p1%d;%p2%dH"); + // test if "ue" reset all attributes + if ( tcap[t_exit_underline_mode].string ) + { + if ( strncmp(tcap[t_exit_underline_mode].string, "\033[m", 3) == 0 + || strncmp(tcap[t_exit_underline_mode].string, "\033G0", 3) == 0 + || strncmp(tcap[t_exit_underline_mode].string, "\033[7m", 4) == 0 + || strcmp ( tcap[t_exit_underline_mode].string + , tcap[t_exit_standout_mode].string ) == 0 ) + exit_underline_caused_reset = true; + else + exit_underline_caused_reset = false; + } + // read termcap key strings for (int i=0; Fkey[i].tname[0] != 0; i++) { @@ -3024,6 +3038,9 @@ void FTerm::setTermColor (register int fg, register int bg) char* Sb = tcap[t_set_background].string; char* sp = tcap[t_set_color_pair].string; + if ( monochron ) + return; + if ( AF && AB ) { int ansi_fg = vga2ansi(fg); @@ -3226,13 +3243,23 @@ bool FTerm::setTermBold (bool on) char* us = tcap[t_enter_underline_mode].string; char* mr = tcap[t_enter_reverse_mode].string; + // "t_exit_attribute_mode" will reset all attributes! appendOutputBuffer (me); - setTermColor (fg_color, bg_color); // restore the last color - if ( underline && ue && us ) + // last color restore + if ( ! monochron ) + { + fg_color = fg_term_color; + bg_color = bg_term_color; + fg_term_color = -1; + bg_term_color = -1; + setTermColor (fg_color, bg_color); + } + // underline mode restore + if ( term_underline && ue && us ) appendOutputBuffer (us); - - if ( reverse && me && mr ) + // reverse mode restore + if ( term_reverse && me && mr ) appendOutputBuffer (mr); } term_bold = false; @@ -3262,11 +3289,22 @@ bool FTerm::setTermReverse (bool on) char* us = tcap[t_enter_underline_mode].string; char* md = tcap[t_enter_bold_mode].string; + // "t_exit_standout_mode" will reset all attributes! appendOutputBuffer (se); + // last color restore + if ( ! monochron ) + { + fg_color = fg_term_color; + bg_color = bg_term_color; + fg_term_color = -1; + bg_term_color = -1; + setTermColor (fg_color, bg_color); + } + // underline mode restore if ( term_underline && ue && us ) appendOutputBuffer (us); - + // bold mode restore if ( term_bold && md && se ) appendOutputBuffer (md); } @@ -3302,11 +3340,24 @@ bool FTerm::setTermUnderline (bool on) appendOutputBuffer (ue); - if ( term_reverse && se && mr && strcmp(ue, se) == 0 ) - appendOutputBuffer (mr); - - if ( term_bold && md && se && strcmp(ue, se) == 0 ) - appendOutputBuffer (md); + if ( exit_underline_caused_reset ) + { + // last color restore + if ( ! monochron ) + { + fg_color = fg_term_color; + bg_color = bg_term_color; + fg_term_color = -1; + bg_term_color = -1; + setTermColor (fg_color, bg_color); + } + // reverse mode restore + if ( term_reverse && se && mr ) + appendOutputBuffer (mr); + // bold mode restore + if ( term_bold && md && se ) + appendOutputBuffer (md); + } } term_underline = false; } diff --git a/src/fterm.h b/src/fterm.h index e5ef2a60..f318b324 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -130,6 +130,7 @@ class FTerm static bool tmux_terminal; static bool terminal_updates; static bool vterm_updates; + static bool exit_underline_caused_reset; static bool background_color_erase; static bool automatic_left_margin; static bool automatic_right_margin; diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 6043efc7..d15ed278 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -341,15 +341,15 @@ void FWidget::setColorTheme() wc.menu_inactive_bg = fc::LightGray; wc.menu_hotkey_fg = fc::Red; wc.menu_hotkey_bg = fc::LightGray; - wc.statusbar_fg = fc::LightGray; - wc.statusbar_bg = fc::Blue; + wc.statusbar_fg = fc::Black; + wc.statusbar_bg = fc::LightGray; wc.statusbar_hotkey_fg = fc::Red; - wc.statusbar_hotkey_bg = fc::Blue; + wc.statusbar_hotkey_bg = fc::LightGray; wc.statusbar_separator_fg = fc::Black; - wc.statusbar_active_fg = fc::Blue; - wc.statusbar_active_bg = fc::LightGray; + wc.statusbar_active_fg = fc::LightGray; + wc.statusbar_active_bg = fc::Black; wc.statusbar_active_hotkey_fg = fc::Red; - wc.statusbar_active_hotkey_bg = fc::LightGray; + wc.statusbar_active_hotkey_bg = fc::Black; wc.scrollbar_fg = fc::Black; wc.scrollbar_bg = fc::LightGray; wc.scrollbar_button_fg = fc::Black;