From 49629a995ab1827447224e3a64dfa7215b9f97d4 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Fri, 8 Jan 2016 01:00:05 +0100 Subject: [PATCH] New class FOptiAttr to control video attributes and colors --- ChangeLog | 4 + README.md | 17 +- doc/TODO | 6 +- doc/class-diagram.txt | 20 +- finalcut.spec | 2 +- src/Makefile.am | 4 +- src/Makefile.clang | 2 + src/Makefile.gcc | 2 + src/Makefile.in | 9 +- src/fbutton.cpp | 27 +- src/fbutton.h | 34 +- src/fbuttongroup.cpp | 3 +- src/fcharmap.h | 17 +- src/fcheckbox.cpp | 7 +- src/fdialog.cpp | 34 +- src/fenum.h | 1 + src/ffiledialog.cpp | 10 - src/ffiledialog.h | 1 - src/fkey_map.h | 2 + src/flabel.cpp | 5 +- src/flabel.h | 4 +- src/flineedit.cpp | 6 +- src/flistbox.cpp | 6 +- src/fmenu.cpp | 14 +- src/fmenubar.cpp | 3 +- src/fmessagebox.cpp | 3 - src/fmessagebox.h | 2 +- src/fobject.cpp | 2 +- src/foptiattr.cpp | 1330 ++++++++++++++++++++++++++++++++++++++ src/foptiattr.h | 265 ++++++++ src/foptimove.h | 2 +- src/fprogressbar.cpp | 7 +- src/fradiobutton.cpp | 2 + src/fstatusbar.cpp | 3 +- src/ftcap_map.h | 43 +- src/fterm.cpp | 1173 +++++++++++++-------------------- src/fterm.h | 113 +--- src/ftextview.cpp | 17 +- src/ftogglebutton.cpp | 7 +- src/fwidget.cpp | 128 +++- src/fwidget.h | 430 ++++++++---- test/keyboard.cpp | 33 +- test/mandelbrot.cpp | 3 - test/menu.cpp | 2 +- test/term-attributes.cpp | 307 ++++++--- test/timer.cpp | 26 +- test/ui.cpp | 4 +- 47 files changed, 2922 insertions(+), 1220 deletions(-) create mode 100644 src/foptiattr.cpp create mode 100644 src/foptiattr.h diff --git a/ChangeLog b/ChangeLog index b5379777..e2d600b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-01-07 Markus Gans + * Add the new class FOptiAttr to control video attributes and colors + for output on terminals + 2015-12-23 Markus Gans * Add video attribute support for dim (half-bright) and italic * An example program to test video attributes on your terminal diff --git a/README.md b/README.md index 08fa5f55..26161a89 100644 --- a/README.md +++ b/README.md @@ -150,13 +150,16 @@ Class digramm │ :1:1 │ └───────────────┘ │ └───────────┘ : ┌───────┐ │ : : │ ┌──────────────┐ │ ┌─────────┐1 : │ FTerm │◄─┘ : : ├────┤ FProgressbar │ └──┤ FSwitch ├-------: - └──┬─┬──┘ : : │ └──────────────┘ └─────────┘ : - :1:1 : : │ ┌────────────┐ : *┌─────────┐ - : └----------: : ├────┤ FScrollbar │ ├---┤ FString │ - :1 : : │ └────────────┘ : └─────────┘ - ┌────┴──────┐ : : │ ┌───────────┐1 : - │ FOptiMove │ : : ├────┤ FTextView ├---------------------------: - └───────────┘ : : │ └───────────┘ : + └┬─┬─┬──┘ : : │ └──────────────┘ └─────────┘ : + : :1:1 : : │ ┌────────────┐ : *┌─────────┐ + : : └----------: : ├────┤ FScrollbar │ ├---┤ FString │ + : :1 : : │ └────────────┘ : └─────────┘ + :┌┴──────────┐ : : │ ┌───────────┐1 : + :│ FOptiAttr │ : : ├────┤ FTextView ├---------------------------: + :└───────────┘ : : │ └───────────┘ : + ┌┴──────────┐ : : │ ┌──────────┐1 *┌──────────────┐1 : + │ FOptiMove │ : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----: + └───────────┘ : : │ └──────────┘ └──────────────┘ : : : │ ┌──────────┐1 *┌──────────────┐1 : : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----: : : │ └──────────┘ └──────────────┘ : diff --git a/doc/TODO b/doc/TODO index d737c6e4..a165a4f8 100644 --- a/doc/TODO +++ b/doc/TODO @@ -4,11 +4,7 @@ Bugs Improvements ~~~~~~~~~~~~ -- New behavior in FTerm::appendAttributes(...) - - 1st: reset don't needed attributes (bold, reverse and underline) - use 'sgr' for this, to do this in one step => 3rd is don't need - - 2nd: set the foreground and background color - - 3rd: set new attributes (bold, reverse and underline) +- Missing Features ~~~~~~~~~~~~~~~~ diff --git a/doc/class-diagram.txt b/doc/class-diagram.txt index 5dad3a21..f89742cf 100644 --- a/doc/class-diagram.txt +++ b/doc/class-diagram.txt @@ -53,16 +53,16 @@ │ :1:1 │ └───────────────┘ │ └───────────┘ : ┌───────┐ │ : : │ ┌──────────────┐ │ ┌─────────┐1 : │ FTerm │◄─┘ : : ├────┤ FProgressbar │ └──┤ FSwitch ├-------: - └──┬─┬──┘ : : │ └──────────────┘ └─────────┘ : - :1:1 : : │ ┌────────────┐ : *┌─────────┐ - : └----------: : ├────┤ FScrollbar │ ├---┤ FString │ - :1 : : │ └────────────┘ : └─────────┘ - ┌────┴──────┐ : : │ ┌───────────┐1 : - │ FOptiMove │ : : ├────┤ FTextView ├---------------------------: - └───────────┘ : : │ └───────────┘ : - : : │ ┌──────────┐1 *┌──────────────┐1 : - : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----: - : : │ └──────────┘ └──────────────┘ : + └┬─┬─┬──┘ : : │ └──────────────┘ └─────────┘ : + : :1:1 : : │ ┌────────────┐ : *┌─────────┐ + : : └----------: : ├────┤ FScrollbar │ ├---┤ FString │ + : :1 : : │ └────────────┘ : └─────────┘ + :┌┴──────────┐ : : │ ┌───────────┐1 : + :│ FOptiAttr │ : : ├────┤ FTextView ├---------------------------: + :└───────────┘ : : │ └───────────┘ : + ┌┴──────────┐ : : │ ┌──────────┐1 *┌──────────────┐1 : + │ FOptiMove │ : : ├────┤ FListBox ├-------┤ FListBoxItem ├-----: + └───────────┘ : : │ └──────────┘ └──────────────┘ : : : │ ┌────────────┐1 *┌────────────┐1 : : : ├────┤ FStatusBar ├-----┤ FStatusKey ├-------: : : │ └────┬───────┘ └────────────┘ : diff --git a/finalcut.spec b/finalcut.spec index e9c9a4ab..1f3abc23 100644 --- a/finalcut.spec +++ b/finalcut.spec @@ -1,7 +1,7 @@ # # spec file for package finalcut # -# Copyright (c) 2015 by Markus Gans +# Copyright (c) 2016 by Markus Gans # Name: finalcut diff --git a/src/Makefile.am b/src/Makefile.am index 7177a5f3..1e091270 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,6 +37,7 @@ libfinal_la_SOURCES = \ fstatusbar.cpp \ fterm.cpp \ fevent.cpp \ + foptiattr.cpp \ foptimove.cpp \ fapp.cpp \ fwidget.cpp \ @@ -71,8 +72,9 @@ finalcutinclude_HEADERS = \ fmenulist.h \ fmessagebox.h \ fobject.h \ - foptimove.h \ fpoint.h \ + foptiattr.h \ + foptimove.h \ fprogressbar.h \ fradiobutton.h \ frect.h \ diff --git a/src/Makefile.clang b/src/Makefile.clang index 488150f3..6eaf0b67 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -26,6 +26,7 @@ INCLUDE_HEADERS = \ fcheckmenuitem.h \ fmessagebox.h \ fobject.h \ + foptiattr.h \ foptimove.h \ fpoint.h \ fprogressbar.h \ @@ -79,6 +80,7 @@ OBJS = \ fstatusbar.o \ fterm.o \ fevent.o \ + foptiattr.o \ foptimove.o \ fapp.o \ fwidget.o \ diff --git a/src/Makefile.gcc b/src/Makefile.gcc index 6396f013..f0fcb33b 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -26,6 +26,7 @@ INCLUDE_HEADERS = \ fcheckmenuitem.h \ fmessagebox.h \ fobject.h \ + foptiattr.h \ foptimove.h \ fpoint.h \ fprogressbar.h \ @@ -79,6 +80,7 @@ OBJS = \ fstatusbar.o \ fterm.o \ fevent.o \ + foptiattr.o \ foptimove.o \ fapp.o \ fwidget.o \ diff --git a/src/Makefile.in b/src/Makefile.in index f3d19156..01db2d62 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -134,8 +134,8 @@ am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \ flabel.lo flistbox.lo fmenu.lo fmenubar.lo fmenuitem.lo \ fradiomenuitem.lo fcheckmenuitem.lo fmenulist.lo fdialog.lo \ fwindow.lo fmessagebox.lo ffiledialog.lo ftextview.lo \ - fstatusbar.lo fterm.lo fevent.lo foptimove.lo fapp.lo \ - fwidget.lo fobject.lo + fstatusbar.lo fterm.lo fevent.lo foptiattr.lo foptimove.lo \ + fapp.lo fwidget.lo fobject.lo libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -401,6 +401,7 @@ libfinal_la_SOURCES = \ fstatusbar.cpp \ fterm.cpp \ fevent.cpp \ + foptiattr.cpp \ foptimove.cpp \ fapp.cpp \ fwidget.cpp \ @@ -433,8 +434,9 @@ finalcutinclude_HEADERS = \ fmenulist.h \ fmessagebox.h \ fobject.h \ - foptimove.h \ fpoint.h \ + foptiattr.h \ + foptimove.h \ fprogressbar.h \ fradiobutton.h \ frect.h \ @@ -544,6 +546,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenulist.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmessagebox.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fobject.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/foptiattr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/foptimove.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fpoint.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fprogressbar.Plo@am__quote@ diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 292440db..63f2ee0a 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -396,53 +396,53 @@ void FButton::processClick() // public methods of FButton //---------------------------------------------------------------------- -void FButton::setForegroundColor (int color) +void FButton::setForegroundColor (short color) { FWidget::setForegroundColor(color); updateButtonColor(); } //---------------------------------------------------------------------- -void FButton::setBackgroundColor (int color) +void FButton::setBackgroundColor (short color) { FWidget::setBackgroundColor(color); updateButtonColor(); } //---------------------------------------------------------------------- -void FButton::setHotkeyForegroundColor (int color) +void FButton::setHotkeyForegroundColor (short color) { - if ( color >> 8 == 0 ) // valid colors 0..254 + if ( color == -1 || color >> 8 == 0 ) // valid colors -1..254 button_hotkey_fg = color; } -void FButton::setFocusForegroundColor (int color) +void FButton::setFocusForegroundColor (short color) { - if ( color >> 8 == 0 ) // valid colors 0..254 + if ( color == -1 || color >> 8 == 0 ) // valid colors -1..254 button_focus_fg = color; updateButtonColor(); } //---------------------------------------------------------------------- -void FButton::setFocusBackgroundColor (int color) +void FButton::setFocusBackgroundColor (short color) { - if ( color >> 8 == 0 ) // valid colors 0..254 + if ( color == -1 || color >> 8 == 0 ) // valid colors -1..254 button_focus_bg = color; updateButtonColor(); } //---------------------------------------------------------------------- -void FButton::setInactiveForegroundColor (int color) +void FButton::setInactiveForegroundColor (short color) { - if ( color >> 8 == 0 ) // valid colors 0..254 + if ( color == -1 || color >> 8 == 0 ) // valid colors -1..254 button_inactive_fg = color; updateButtonColor(); } //---------------------------------------------------------------------- -void FButton::setInactiveBackgroundColor (int color) +void FButton::setInactiveBackgroundColor (short color) { - if ( color >> 8 == 0 ) // valid colors 0..254 + if ( color == -1 || color >> 8 == 0 ) // valid colors -1..254 button_inactive_bg = color; updateButtonColor(); } @@ -450,7 +450,8 @@ void FButton::setInactiveBackgroundColor (int color) //---------------------------------------------------------------------- void FButton::hide() { - int fg, bg, s, f, size; + int s, f, size; + short fg, bg; char* blank; FWidget::hide(); diff --git a/src/fbutton.h b/src/fbutton.h index 0b0fab10..dedd5a8b 100644 --- a/src/fbutton.h +++ b/src/fbutton.h @@ -37,16 +37,16 @@ class FButton : public FWidget { private: FString text; - bool button_down; - bool click_animation; - int click_time; - int button_fg; - int button_bg; - int button_hotkey_fg; - int button_focus_fg; - int button_focus_bg; - int button_inactive_fg; - int button_inactive_bg; + bool button_down; + bool click_animation; + int click_time; + short button_fg; + short button_bg; + short button_hotkey_fg; + short button_focus_fg; + short button_focus_bg; + short button_inactive_fg; + short button_inactive_bg; private: FButton (const FButton&); @@ -66,13 +66,13 @@ class FButton : public FWidget virtual ~FButton(); // destructor const char* getClassName() const; - void setForegroundColor (int); - void setBackgroundColor (int); - void setHotkeyForegroundColor (int); - void setFocusForegroundColor (int); - void setFocusBackgroundColor (int); - void setInactiveForegroundColor (int); - void setInactiveBackgroundColor (int); + void setForegroundColor (short); + void setBackgroundColor (short); + void setHotkeyForegroundColor (short); + void setFocusForegroundColor (short); + void setFocusBackgroundColor (short); + void setInactiveForegroundColor (short); + void setInactiveBackgroundColor (short); void hide(); void onKeyPress (FKeyEvent*); diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index d5a11bb0..35a3c46f 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -263,7 +263,8 @@ void FButtonGroup::drawLabel() //---------------------------------------------------------------------- void FButtonGroup::hide() { - int fg, bg, size; + int size; + short fg, bg; char* blank; FWidget::hide(); if ( ! buttonlist.empty() ) diff --git a/src/fcharmap.h b/src/fcharmap.h index 723a07e8..7d70e9ec 100644 --- a/src/fcharmap.h +++ b/src/fcharmap.h @@ -10,26 +10,17 @@ static uInt character[][fc::NUM_OF_ENCODINGS] = // | | .--------- PC (IBM-437) // | | | .---- ASCII (7-Bit) // | | | | - {0x00f6,0xf6, 0x94, 'o'}, // ö - o-umlaut - {0x00e4,0xe4, 0x84, 'a'}, // ä - a-umlaut - {0x00fc,0xfc, 0x81, 'u'}, // ü - u-umlaut - {0x00d6,0xd6, 0x99, 'O'}, // Ö - O-umlaut - {0x00c4,0xc4, 0x8e, 'A'}, // Ä - A-umlaut - {0x00dc,0xdc, 0x9a, 'U'}, // Ü - U-umlaut - {0x00db,0xdb, 0x96, 'U'}, // Û - U-circumflex - {0x00fb,0xfb, 0x96, 'u'}, // û - u-circumflex - {0x00df,0xdf, 0xe1, 's'}, // ß - sz-ligature - {0x20ac, 'E', 0xee, 'E'}, // € - Euro + {0x20ac, 0, 0xee, 'E'}, // € - Euro {0x00a3, '}', 0x9c, 'P'}, // £ - Pound {0x03c0, '{', 0xe3, 'n'}, // π - Pi {0x207F, 'I', 0xfc, ' '}, // ⁿ - SuperscriptLatinSmallLetterN {0x2265, 'z', 0xf2, '>'}, // ≥ - GreaterThanOrEqualTo {0x2264, 'y', 0xf3, '<'}, // ≤ - LessThanOrEqualTo - {0x2260, '|', 0xd8, '!'}, // ≠ - NotEqualTo + {0x2260, 0, 0xd8, '#'}, // ≠ - NotEqualTo {0x00b1, 'g', 0xf1, '#'}, // ± - PlusMinus {0x00f7, '/', 0xf6, '/'}, // ÷ - Division sign - {0x00d7, 'x', 'x', 'x'}, // × - Multiplication sign - {0x02e3, '~', 0xfc, '~'}, // ˣ - Modifier letter small x + {0x00d7, 0, 'x', 'x'}, // × - Multiplication sign + {0x02e3, '~', 0xfc, '`'}, // ˣ - Modifier letter small x {0x00b0, 'f', 0xb0, 'o'}, // ° - Degree {0x2022, '`', 0x04, '*'}, // • - Bullet {0x00b7, '`', 0xfa, '.'}, // · - small Bullet diff --git a/src/fcheckbox.cpp b/src/fcheckbox.cpp index cec6d6a1..4c0e0836 100644 --- a/src/fcheckbox.cpp +++ b/src/fcheckbox.cpp @@ -53,8 +53,10 @@ void FCheckBox::drawCheckButton() { if ( ! isVisible() ) return; + gotoxy (xpos+xmin-1, ypos+ymin-1); setColor (foregroundColor, backgroundColor); + if ( isMonochron() ) { if ( hasFocus() ) @@ -69,10 +71,7 @@ void FCheckBox::drawCheckButton() else { print ('['); - if ( isTeraTerm() ) - print ('x'); - else - print (fc::Times); // Times × + print (fc::Times); // Times × print (']'); } } diff --git a/src/fdialog.cpp b/src/fdialog.cpp index ce3d9a1d..6c1ad3ab 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -137,7 +137,7 @@ void FDialog::drawBorder() if ( isNewFont() ) { - int fg; + short fg; if ( ! isRootWidget() ) fg = parentWidget()->getForegroundColor(); else @@ -269,7 +269,7 @@ void FDialog::drawDialogShadow() if ( isNewFont() && ((flags & SCROLLABLE) == 0) ) { - FTerm::char_data ch; + FOptiAttr::char_data ch; // left of the shadow ▀▀ gotoxy (xpos+xmin-1, ypos+ymin-1+height); for (int x=0; x <= 1; x++) @@ -288,7 +288,7 @@ void FDialog::drawDialogShadow() drawShadow(); - FTerm::char_data ch; + FOptiAttr::char_data ch; ch = getCoveredCharacter (xpos+xmin-1, ypos+ymin-1+height, this); // left of the shadow ▀▀ gotoxy (xpos+xmin-1, ypos+ymin-1+height); @@ -305,16 +305,34 @@ void FDialog::drawDialogShadow() if ( ch.bold ) setBold(); - if ( ch.reverse ) - setReverse(); + if ( ch.dim ) + setDim(); + if ( ch.italic ) + setItalic(); if ( ch.underline ) setUnderline(); + if ( ch.blink ) + setBlink(); + if ( ch.reverse ) + setReverse(); + if ( ch.standout ) + setStandout(); + if ( ch.invisible ) + setInvisible(); + if ( ch.protect ) + setProtected(); + if ( ch.crossed_out ) + setCrossedOut(); + if ( ch.dbl_underline ) + setDoubleUnderline(); + if ( ch.alt_charset ) + setAltCharset (true); + if ( ch.pc_charset ) + setPCcharset (true); print (ch.code); - unsetUnderline(); - unsetReverse(); - unsetBold(); + setNormal(); } } } diff --git a/src/fenum.h b/src/fenum.h index 217407bb..8438244d 100644 --- a/src/fenum.h +++ b/src/fenum.h @@ -570,6 +570,7 @@ class fc // console color names enum colornames { + Default = -1, Black = 0, Blue = 1, Green = 2, diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index c5814448..9841e028 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -200,16 +200,6 @@ char* FFileDialog::getHomeDir() } } -//---------------------------------------------------------------------- -void FFileDialog::draw() -{ - FDialog::draw(); - - if ( Encoding == fc::VT100 ) - unsetVT100altChar(); - -} - //---------------------------------------------------------------------- inline bool FFileDialog::pattern_match ( const char* pattern , const char* fname ) diff --git a/src/ffiledialog.h b/src/ffiledialog.h index e03db408..3d135ca3 100644 --- a/src/ffiledialog.h +++ b/src/ffiledialog.h @@ -95,7 +95,6 @@ class FFileDialog : public FDialog private: void init(); static char* getHomeDir(); - virtual void draw(); inline bool pattern_match (const char*, const char*); void clear(); int numOfDirs(); diff --git a/src/fkey_map.h b/src/fkey_map.h index e86d4750..c8ed26db 100644 --- a/src/fkey_map.h +++ b/src/fkey_map.h @@ -79,6 +79,7 @@ static keymap Fkey[] = { fc::Fkey_create , 0, "@6" }, // create key { fc::Fkey_end , 0, "@7" }, // end key { fc::Fkey_end , 0, "@7x"}, // end key + { fc::Fkey_end , 0, "@7X"}, // end key { fc::Fkey_enter , 0, "@8" }, // enter/send key { fc::Fkey_exit , 0, "@9" }, // exit key { fc::Fkey_find , 0, "@0" }, // find key @@ -424,6 +425,7 @@ static keyname FkeyName[] = { fc::Fckey_g , "Ctrl+G" }, { fc::Fkey_erase , "Backspace" }, // Ctrl+H { fc::Fkey_tab , "Tab" }, // Ctrl+I + { fc::Fckey_j , "Ctrl+J" }, { fc::Fckey_h , "Ctrl+K" }, { fc::Fckey_l , "Ctrl+L" }, { fc::Fkey_return , "Return" }, // Ctrl+M diff --git a/src/flabel.cpp b/src/flabel.cpp index e441159d..4196fc84 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -233,9 +233,6 @@ void FLabel::draw() if ( text.isNull() || text.isEmpty() ) return; - if ( Encoding == fc::VT100 ) - unsetVT100altChar(); - setUpdateVTerm(false); if ( isMonochron() ) @@ -319,7 +316,7 @@ void FLabel::draw() //---------------------------------------------------------------------- void FLabel::hide() { - int fg, bg; + short fg, bg; char* blank; FWidget::hide(); diff --git a/src/flabel.h b/src/flabel.h index 8662baba..0a1ff13b 100644 --- a/src/flabel.h +++ b/src/flabel.h @@ -45,8 +45,8 @@ class FLabel : public FWidget FString text; int emphasis; uInt alignment; - uChar emphasis_color; - uChar ellipsis_color; + short emphasis_color; + short ellipsis_color; bool reverse_mode; FWidget* accel_widget; diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 53335edf..a2ae36e0 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -106,9 +106,6 @@ void FLineEdit::draw() { bool isFocus; - if ( Encoding == fc::VT100 ) - unsetVT100altChar(); - drawInputField(); isFocus = ((flags & FOCUS) != 0); @@ -276,7 +273,8 @@ void FLineEdit::adjustSize() //---------------------------------------------------------------------- void FLineEdit::hide() { - int fg, bg, s, size, lable_Length; + int s, size, lable_Length; + short fg, bg; char* blank; FWidget::hide(); diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 6d499b9c..02f4523b 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -187,9 +187,6 @@ void FListBox::drawLabel() if ( text.isNull() || text.isEmpty() ) return; - if ( Encoding == fc::VT100 ) - unsetVT100altChar(); - txt = " " + text + " "; length = txt.getLength(); gotoxy (xpos+xmin, ypos+ymin-1); @@ -537,7 +534,8 @@ void FListBox::setCurrentItem(int index) //---------------------------------------------------------------------- void FListBox::hide() { - int fg, bg, n, size; + int n, size; + short fg, bg; char* blank; FWidget::hide(); diff --git a/src/fmenu.cpp b/src/fmenu.cpp index ae3414e5..ae2a5a73 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -754,8 +754,10 @@ void FMenu::drawItems() { if ( ! iswprint(wint_t(item_text[z])) ) { - if ( ! isNewFont() && ( int(item_text[z]) < fc::NF_rev_left_arrow2 - || int(item_text[z]) > fc::NF_check_mark ) ) + if ( ! isNewFont() + && ( int(item_text[z]) < fc::NF_rev_left_arrow2 + || int(item_text[z]) > fc::NF_check_mark ) + && ! charEncodable(uInt(item_text[z])) ) { item_text[z] = L' '; } @@ -778,11 +780,9 @@ void FMenu::drawItems() int len = int(maxItemWidth) - (to_char + c + 3); if ( len > 0 ) { - FString spaces (len, wchar_t(' ')); - if ( isTeraTerm() ) - print (spaces + wchar_t('>')); - else // BlackRightPointingPointer ► - print (spaces + wchar_t(fc::BlackRightPointingPointer)); + print (FString(len, wchar_t(' '))); + // BlackRightPointingPointer ► + print (wchar_t(fc::BlackRightPointingPointer)); to_char = int(maxItemWidth) - (c + 2); } } diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index e0d17133..0a00a433 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -835,7 +835,8 @@ void FMenuBar::onAccel (FAccelEvent* ev) //---------------------------------------------------------------------- void FMenuBar::hide() { - int fg, bg, screenWidth; + int screenWidth; + short fg, bg; char* blank; FWindow::hide(); diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index df8f0f43..4c4db0be 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -218,9 +218,6 @@ void FMessageBox::draw() { FDialog::draw(); - if ( Encoding == fc::VT100 ) - unsetVT100altChar(); - int head_offset = 0; int center_x = 0; int msg_x = int((width - int(maxLineWidth)) / 2); // center the whole block diff --git a/src/fmessagebox.h b/src/fmessagebox.h index 0958b7ab..571d954c 100644 --- a/src/fmessagebox.h +++ b/src/fmessagebox.h @@ -69,7 +69,7 @@ class FMessageBox : public FDialog std::vector text_split; uInt maxLineWidth; bool center_text; - uChar emphasis_color; + short emphasis_color; uInt numButtons; uInt text_num_lines; int* button_digit[3]; diff --git a/src/fobject.cpp b/src/fobject.cpp index e6445663..f7dd3ec6 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -204,7 +204,7 @@ bool FObject::delTimer (int id) //---------------------------------------------------------------------- bool FObject::delOwnTimer() { - FObject::TimerList::iterator iter, end; + FObject::TimerList::iterator iter; if ( ! timer_list ) return false; diff --git a/src/foptiattr.cpp b/src/foptiattr.cpp new file mode 100644 index 00000000..bb889064 --- /dev/null +++ b/src/foptiattr.cpp @@ -0,0 +1,1330 @@ +// File: foptiattr.cpp +// Provides: class FOptiAttr + +#include "foptiattr.h" +#include "string.h" + +//---------------------------------------------------------------------- +// class FOptiAttr +//---------------------------------------------------------------------- + +// constructors and destructor +//---------------------------------------------------------------------- +FOptiAttr::FOptiAttr() + : F_enter_bold_mode() + , F_exit_bold_mode() + , F_enter_dim_mode() + , F_exit_dim_mode() + , F_enter_italics_mode() + , F_exit_italics_mode() + , F_enter_underline_mode() + , F_exit_underline_mode() + , F_enter_blink_mode() + , F_exit_blink_mode() + , F_enter_reverse_mode() + , F_exit_reverse_mode() + , F_enter_standout_mode() + , F_exit_standout_mode() + , F_enter_secure_mode() + , F_exit_secure_mode() + , F_enter_protected_mode() + , F_exit_protected_mode() + , F_enter_crossed_out_mode() + , F_exit_crossed_out_mode() + , F_enter_dbl_underline_mode() + , F_exit_dbl_underline_mode() + , F_set_attributes() + , F_exit_attribute_mode() + , F_enter_alt_charset_mode() + , F_exit_alt_charset_mode() + , F_enter_pc_charset_mode() + , F_exit_pc_charset_mode() + , F_set_a_foreground() + , F_set_a_background() + , F_set_foreground() + , F_set_background() + , F_set_color_pair() + , max_color(1) + , attr_without_color(0) + , monochron(true) + , fake_reverse(false) + , cygwin_terminal(false) + , attr_ptr(attr_buf) + , on() + , off() +{ + attr_buf[0] = '\0'; +} + +//---------------------------------------------------------------------- +FOptiAttr::~FOptiAttr() // destructor +{ } + + +// private methods of FApplication +//---------------------------------------------------------------------- +inline bool FOptiAttr::hasColor (char_data*& attr) +{ + if ( attr->fg_color < 0 && attr->bg_color < 0 ) + return false; + else + return true; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::colorChange (char_data*& term, char_data*& next) +{ + return bool ( fake_reverse + || term->fg_color != next->fg_color + || term->bg_color != next->bg_color ); +} + +//---------------------------------------------------------------------- +inline void FOptiAttr::resetColor (char_data*& attr) +{ + attr->fg_color = -1; + attr->bg_color = -1; +} + +//---------------------------------------------------------------------- +inline void FOptiAttr::prevent_no_color_video_attributes (char_data*& attr) +{ + // ignore attributes which can not combined with a color + + enum attr_modes + { + standout_mode = 1, + underline_mode = 2, + reverse_mode = 4, + blink_mode = 8, + dim_mode = 16, + bold_mode = 32, + invisible_mode = 64, + protected_mode = 128, + alt_charset_mode = 256, + horizontal_mode = 512, + left_mode = 1024, + low_mode = 2048, + right_mode = 4096, + top_mode = 8192, + vertical_mode = 16384, + italic_mode = 32768, + no_mode = 65536 + }; + + if ( hasColor(attr) && attr_without_color > 0 ) + { + for (int bit=1; bit < no_mode; bit <<= 1) + { + switch ( bit & attr_without_color ) + { + case standout_mode: + if ( attr->standout ) + attr->standout = false; + break; + + case underline_mode: + if ( attr->underline ) + attr->underline = false; + break; + + case reverse_mode: + if ( attr->reverse ) + { + attr->reverse = false; + if ( attr->fg_color != attr->bg_color ) + fake_reverse = true; + } + break; + + case blink_mode: + if ( attr->blink ) + attr->blink = false; + break; + + case dim_mode: + if ( attr->dim ) + attr->dim = false; + break; + + case bold_mode: + if ( attr->bold ) + attr->bold = false; + break; + + case invisible_mode: + if ( attr->invisible ) + attr->invisible = false; + break; + + case protected_mode: + if ( attr->protect ) + attr->protect = false; + break; + + case alt_charset_mode: + if ( attr->alt_charset ) + attr->alt_charset = false; + break; + + case italic_mode: + if ( attr->italic ) + attr->italic = false; + break; + + default: + break; + } + } + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::change_color (char_data*& term, char_data*& next) +{ + char* color_str; + char* AF = F_set_a_foreground.cap; + char* AB = F_set_a_background.cap; + char* Sf = F_set_foreground.cap; + char* Sb = F_set_background.cap; + char* sp = F_set_color_pair.cap; + short fg = next->fg_color; + short bg = next->bg_color; + + if ( monochron ) + return; + + if ( fg == -1 && fg != term->fg_color ) + { + char* sgr_39 = const_cast("\033[39m"); + append_sequence (sgr_39); + term->fg_color = next->fg_color; + } + if ( bg == -1 && bg != term->bg_color ) + { + char* sgr_49 = const_cast("\033[49m"); + append_sequence (sgr_49); + term->bg_color = next->bg_color; + } + + if ( ! fake_reverse && fg < 0 && bg < 0 ) + return; + + if ( fake_reverse ) + std::swap (fg, bg); + + if ( AF && AB ) + { + short ansi_fg = vga2ansi(fg); + short ansi_bg = vga2ansi(bg); + + if ( cygwin_terminal ) + { + char* rst = const_cast("\033[m"); + append_sequence (rst); + reset(term); + + color_str = tparm(AF, ansi_fg); + if ( color_str ) + append_sequence (color_str); + + color_str = tparm(AB, ansi_bg); + if ( color_str ) + append_sequence (color_str); + } + else + { + if ( term->fg_color != fg && (color_str = tparm(AF, ansi_fg)) ) + append_sequence (color_str); + + if ( term->bg_color != bg && (color_str = tparm(AB, ansi_bg)) ) + append_sequence (color_str); + } + } + else if ( Sf && Sb ) + { + if ( term->fg_color != fg && (color_str = tparm(Sf, fg)) ) + append_sequence (color_str); + + if ( term->bg_color != bg && (color_str = tparm(Sb, bg)) ) + append_sequence (color_str); + } + else if ( sp ) + { + fg = vga2ansi(fg); + bg = vga2ansi(bg); + + if ( (color_str = tparm(sp, fg, bg)) ) + append_sequence (color_str); + } + + term->fg_color = next->fg_color; + term->bg_color = next->bg_color; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::hasAttribute (char_data*& attr) +{ + return attr->bold == true + || attr->dim == true + || attr->italic == true + || attr->underline == true + || attr->blink == true + || attr->reverse == true + || attr->standout == true + || attr->invisible == true + || attr->protect == true + || attr->crossed_out == true + || attr->dbl_underline == true + || attr->alt_charset == true + || attr->pc_charset == true; +} + +//---------------------------------------------------------------------- +inline void FOptiAttr::resetAttribute (char_data*& attr) +{ + attr->bold = \ + attr->dim = \ + attr->italic = \ + attr->underline = \ + attr->blink = \ + attr->reverse = \ + attr->standout = \ + attr->invisible = \ + attr->protect = \ + attr->crossed_out = \ + attr->dbl_underline = \ + attr->alt_charset = \ + attr->pc_charset = false; +} + +//---------------------------------------------------------------------- +inline void FOptiAttr::reset (char_data*& attr) +{ + resetAttribute(attr); + resetColor(attr); +} + +//---------------------------------------------------------------------- +bool FOptiAttr::caused_reset_attributes (char*& cap, uChar test) +{ + // test if "cap" reset all attributes + char* ue = F_exit_underline_mode.cap; + char* se = F_exit_standout_mode.cap; + char* me = F_exit_attribute_mode.cap; + + if ( cap ) + { + if ( (test & test_ansi_reset) && strncmp (cap, "\033[m", 3) == 0 ) + return true; + if ( (test & test_adm3_reset) && strncmp (cap, "\033G0", 3) == 0 ) + return true; + if ( (test & same_like_ue) && ue && strcmp (cap, ue) == 0 ) + return true; + if ( (test & same_like_se) && se && strcmp (cap, se) == 0 ) + return true; + if ( (test & same_like_me) && me && strcmp (cap, me) == 0 ) + return true; + } + return false; +} + +//---------------------------------------------------------------------- +inline void FOptiAttr::detectSwitchOn (char_data*& term, char_data*& next) +{ + on.bold = ! term->bold && next->bold; + on.dim = ! term->dim && next->dim; + on.italic = ! term->italic && next->italic; + on.underline = ! term->underline && next->underline; + on.blink = ! term->blink && next->blink; + on.reverse = ! term->reverse && next->reverse; + on.standout = ! term->standout && next->standout; + on.invisible = ! term->invisible && next->invisible; + on.protect = ! term->protect && next->protect; + on.crossed_out = ! term->crossed_out && next->crossed_out; + on.dbl_underline = ! term->dbl_underline && next->dbl_underline; + on.alt_charset = ! term->alt_charset && next->alt_charset; + on.pc_charset = ! term->pc_charset && next->pc_charset; +} + +//---------------------------------------------------------------------- +inline void FOptiAttr::detectSwitchOff (char_data*& term, char_data*& next) +{ + off.bold = term->bold && ! next->bold; + off.dim = term->dim && ! next->dim; + off.italic = term->italic && ! next->italic; + off.underline = term->underline && ! next->underline; + off.blink = term->blink && ! next->blink; + off.reverse = term->reverse && ! next->reverse; + off.standout = term->standout && ! next->standout; + off.invisible = term->invisible && ! next->invisible; + off.protect = term->protect && ! next->protect; + off.crossed_out = term->crossed_out && ! next->crossed_out; + off.dbl_underline = term->dbl_underline && ! next->dbl_underline; + off.alt_charset = term->alt_charset && ! next->alt_charset; + off.pc_charset = term->pc_charset && ! next->pc_charset; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::switchOn() +{ + char_data* on_ptr = &on; + return hasAttribute(on_ptr); +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::switchOff() +{ + char_data* off_ptr = &off; + return hasAttribute(off_ptr); +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::append_sequence (char*& seq) +{ + if ( seq ) + { + strncat (attr_ptr, seq, sizeof(attr_buf) - strlen(attr_ptr) - 1 ); + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::replace_sequence (char*& seq) +{ + if ( seq ) + { + strncpy (attr_ptr, seq, sizeof(attr_buf) - 1); + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermBold (char_data*& term) +{ + if ( append_sequence(F_enter_bold_mode.cap) ) + return (term->bold = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermBold (char_data*& term) +{ + // Back to normal intensity (turns off bold + dim) + if ( append_sequence(F_exit_bold_mode.cap) ) + { + if ( F_exit_bold_mode.caused_reset ) + reset(term); + else + { + term->bold = false; + term->dim = false; + } + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermDim (char_data*& term) +{ + if ( append_sequence(F_enter_dim_mode.cap) ) + return (term->dim = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermDim (char_data*& term) +{ + // Back to normal intensity (turns off bold + dim) + if ( append_sequence(F_exit_dim_mode.cap) ) + { + if ( F_exit_dim_mode.caused_reset ) + reset(term); + else + { + term->bold = false; + term->dim = false; + } + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermItalic (char_data*& term) +{ + if ( append_sequence(F_enter_italics_mode.cap) ) + return (term->italic = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermItalic (char_data*& term) +{ + if ( append_sequence(F_exit_italics_mode.cap) ) + { + if ( F_exit_italics_mode.caused_reset ) + reset(term); + else + term->italic = false; + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermUnderline (char_data*& term) +{ + if ( append_sequence(F_enter_underline_mode.cap) ) + return (term->underline = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermUnderline (char_data*& term) +{ + // Turns off every underlining + if ( append_sequence(F_exit_underline_mode.cap) ) + { + if ( F_exit_underline_mode.caused_reset ) + reset(term); + else + { + term->underline = false; + term->dbl_underline = false; + } + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermBlink (char_data*& term) +{ + if ( append_sequence(F_enter_blink_mode.cap) ) + return (term->blink = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermBlink (char_data*& term) +{ + if ( append_sequence(F_exit_blink_mode.cap) ) + { + if ( F_exit_blink_mode.caused_reset ) + reset(term); + else + term->blink = false; + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermReverse (char_data*& term) +{ + if ( append_sequence(F_enter_reverse_mode.cap) ) + return (term->reverse = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermReverse (char_data*& term) +{ + if ( append_sequence(F_exit_reverse_mode.cap) ) + { + if ( F_exit_reverse_mode.caused_reset ) + reset(term); + else + term->reverse = false; + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermStandout (char_data*& term) +{ + if ( append_sequence(F_enter_standout_mode.cap) ) + return (term->standout = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermStandout (char_data*& term) +{ + if ( append_sequence(F_exit_standout_mode.cap) ) + { + if ( F_exit_standout_mode.caused_reset ) + reset(term); + else + term->standout = false; + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermInvisible (char_data*& term) +{ + if ( append_sequence(F_enter_secure_mode.cap) ) + return (term->invisible = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermInvisible (char_data*& term) +{ + if ( append_sequence(F_exit_secure_mode.cap) ) + { + if ( F_exit_secure_mode.caused_reset ) + reset(term); + else + term->invisible = false; + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermProtected (char_data*& term) +{ + if ( append_sequence(F_enter_protected_mode.cap) ) + return (term->protect = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermProtected (char_data*& term) +{ + if ( append_sequence(F_exit_protected_mode.cap) ) + { + if ( F_exit_protected_mode.caused_reset ) + reset(term); + else + term->protect = false; + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermCrossedOut (char_data*& term) +{ + if ( append_sequence(F_enter_crossed_out_mode.cap) ) + return (term->crossed_out = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermCrossedOut (char_data*& term) +{ + if ( append_sequence(F_exit_crossed_out_mode.cap) ) + { + if ( F_exit_crossed_out_mode.caused_reset ) + reset(term); + else + term->crossed_out = false; + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermDoubleUnderline (char_data*& term) +{ + if ( append_sequence(F_enter_dbl_underline_mode.cap) ) + return (term->dbl_underline = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermDoubleUnderline (char_data*& term) +{ + // Turns off every underlining + if ( append_sequence(F_exit_dbl_underline_mode.cap) ) + { + if ( F_exit_dbl_underline_mode.caused_reset ) + reset(term); + else + { + term->underline = false; + term->dbl_underline = false; + } + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +bool FOptiAttr::setTermAttributes ( char_data*& term + , bool p1, bool p2, bool p3 + , bool p4, bool p5, bool p6 + , bool p7, bool p8, bool p9 ) +{ + if ( F_set_attributes.cap ) + { + char* sgr = tparm ( F_set_attributes.cap + , p1, p2, p3, p4, p5, p6, p7, p8, p9 ); + + append_sequence (sgr); + + resetColor(term); + term->standout = p1; + term->underline = p2; + term->reverse = p3; + term->blink = p4; + term->dim = p5; + term->bold = p6; + term->invisible = p7; + term->protect = p8; + term->alt_charset = p9; + term->pc_charset = false; + term->italic = false; + term->crossed_out = false; + term->dbl_underline = false; + + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermAttributes (char_data*& term) +{ + if ( replace_sequence(F_exit_attribute_mode.cap) ) + { + reset(term); + return true; + } + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermAltCharset (char_data*& term) +{ + if ( append_sequence(F_enter_alt_charset_mode.cap) ) + return (term->alt_charset = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermAltCharset (char_data*& term) +{ + if ( append_sequence(F_exit_alt_charset_mode.cap) ) + return !(term->alt_charset = false); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::setTermPCcharset (char_data*& term) +{ + if ( append_sequence(F_enter_pc_charset_mode.cap) ) + return (term->pc_charset = true); + else + return false; +} + +//---------------------------------------------------------------------- +inline bool FOptiAttr::unsetTermPCcharset (char_data*& term) +{ + if ( append_sequence(F_exit_pc_charset_mode.cap) ) + return !(term->pc_charset = false); + else + return false; +} + + +// public methods of FOptiAttr +//---------------------------------------------------------------------- +inline short FOptiAttr::vga2ansi (register short color) +{ + // VGA | ANSI + // i R G B | i B G R + //---------+--------- + // 0 0 0 0 | 0 0 0 0 i = intensity bit + // 0 0 0 1 | 0 1 0 0 R = red + // 0 0 1 0 | 0 0 1 0 G = green + // 0 0 1 1 | 0 1 1 0 B = blue + // 0 1 0 0 | 0 0 0 1 + // 0 1 0 1 | 0 1 0 1 + // 0 1 1 0 | 0 0 1 1 + // 0 1 1 1 | 0 1 1 1 + // 1 0 0 0 | 1 0 0 0 + // 1 0 0 1 | 1 1 0 0 + // 1 0 1 0 | 1 0 1 0 + // 1 0 1 1 | 1 1 1 0 + // 1 1 0 0 | 1 0 0 1 + // 1 1 0 1 | 1 1 0 1 + // 1 1 1 0 | 1 0 1 1 + // 1 1 1 1 | 1 1 1 1 + + if ( color < 16 ) + { + static const short lookup_table[] = + { + 0, 4, 2, 6, 1, 5, 3, 7, + 8, 12, 10, 14, 9, 13, 11, 15 + }; + color = lookup_table[color]; + } + return color; +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_bold_mode (char*& cap) +{ + if ( cap ) + { + F_enter_bold_mode.cap = cap; + F_enter_bold_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_bold_mode (char*& cap) +{ + if ( cap ) + { + F_exit_bold_mode.cap = cap; + F_exit_bold_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_dim_mode (char*& cap) +{ + if ( cap ) + { + F_enter_dim_mode.cap = cap; + F_enter_dim_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_dim_mode (char*& cap) +{ + if ( cap ) + { + F_exit_dim_mode.cap = cap; + F_exit_dim_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_italics_mode (char*& cap) +{ + if ( cap ) + { + F_enter_italics_mode.cap = cap; + F_enter_italics_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_italics_mode (char*& cap) +{ + if ( cap ) + { + F_exit_italics_mode.cap = cap; + F_exit_italics_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_underline_mode (char*& cap) +{ + if ( cap ) + { + F_enter_underline_mode.cap = cap; + F_enter_underline_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_underline_mode (char*& cap) +{ + if ( cap ) + { + F_exit_underline_mode.cap = cap; + F_exit_underline_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_blink_mode (char*& cap) +{ + if ( cap ) + { + F_enter_blink_mode.cap = cap; + F_enter_blink_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_blink_mode (char*& cap) +{ + if ( cap ) + { + F_exit_blink_mode.cap = cap; + F_exit_blink_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_reverse_mode (char*& cap) +{ + if ( cap ) + { + F_enter_reverse_mode.cap = cap; + F_enter_reverse_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_reverse_mode (char*& cap) +{ + if ( cap ) + { + F_exit_reverse_mode.cap = cap; + F_exit_reverse_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_secure_mode (char*& cap) +{ + if ( cap ) + { + F_enter_secure_mode.cap = cap; + F_enter_secure_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_secure_mode (char*& cap) +{ + if ( cap ) + { + F_exit_secure_mode.cap = cap; + F_exit_secure_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_protected_mode (char*& cap) +{ + if ( cap ) + { + F_enter_protected_mode.cap = cap; + F_enter_protected_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_protected_mode (char*& cap) +{ + if ( cap ) + { + F_exit_protected_mode.cap = cap; + F_exit_protected_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_crossed_out_mode (char*& cap) +{ + if ( cap ) + { + F_enter_crossed_out_mode.cap = cap; + F_enter_crossed_out_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_crossed_out_mode (char*& cap) +{ + if ( cap ) + { + F_exit_crossed_out_mode.cap = cap; + F_exit_crossed_out_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_dbl_underline_mode (char*& cap) +{ + if ( cap ) + { + F_enter_dbl_underline_mode.cap = cap; + F_enter_dbl_underline_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_dbl_underline_mode (char*& cap) +{ + if ( cap ) + { + F_exit_dbl_underline_mode.cap = cap; + F_exit_dbl_underline_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_standout_mode (char*& cap) +{ + if ( cap ) + { + F_enter_standout_mode.cap = cap; + F_enter_standout_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_standout_mode (char*& cap) +{ + if ( cap ) + { + F_exit_standout_mode.cap = cap; + F_exit_standout_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_set_attributes (char*& cap) +{ + if ( cap ) + { + F_set_attributes.cap = cap; + F_set_attributes.caused_reset = true; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_attribute_mode (char*& cap) +{ + if ( cap ) + { + F_exit_attribute_mode.cap = cap; + F_exit_attribute_mode.caused_reset = true; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_alt_charset_mode (char*& cap) +{ + if ( cap ) + { + F_enter_alt_charset_mode.cap = cap; + F_enter_alt_charset_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_alt_charset_mode (char*& cap) +{ + if ( cap ) + { + F_exit_alt_charset_mode.cap = cap; + F_exit_alt_charset_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_enter_pc_charset_mode (char*& cap) +{ + if ( cap ) + { + F_enter_pc_charset_mode.cap = cap; + F_enter_pc_charset_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_exit_pc_charset_mode (char*& cap) +{ + if ( cap ) + { + F_exit_pc_charset_mode.cap = cap; + F_exit_pc_charset_mode.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_a_foreground_color (char*& cap) +{ + if ( cap ) + { + F_set_a_foreground.cap = cap; + F_set_a_foreground.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_a_background_color (char*& cap) +{ + if ( cap ) + { + F_set_a_background.cap = cap; + F_set_a_background.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_foreground_color (char*& cap) +{ + if ( cap ) + { + F_set_foreground.cap = cap; + F_set_foreground.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_background_color (char*& cap) +{ + if ( cap ) + { + F_set_background.cap = cap; + F_set_background.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::set_term_color_pair (char*& cap) +{ + if ( cap ) + { + F_set_color_pair.cap = cap; + F_set_color_pair.caused_reset = false; + } +} + +//---------------------------------------------------------------------- +void FOptiAttr::init() +{ + if ( max_color < 8 ) + monochron = true; + else + monochron = false; + + if ( caused_reset_attributes(F_exit_bold_mode.cap) ) + F_exit_bold_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_dim_mode.cap) ) + F_exit_dim_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_italics_mode.cap) ) + F_exit_italics_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_blink_mode.cap) ) + F_exit_blink_mode.caused_reset = true; + + if ( caused_reset_attributes ( F_exit_underline_mode.cap + , all_tests & ~same_like_ue) ) + F_exit_underline_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_reverse_mode.cap) ) + F_exit_reverse_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_secure_mode.cap) ) + F_exit_secure_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_protected_mode.cap) ) + F_exit_protected_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_crossed_out_mode.cap) ) + F_exit_crossed_out_mode.caused_reset = true; + + if ( caused_reset_attributes(F_exit_dbl_underline_mode.cap) ) + F_exit_dbl_underline_mode.caused_reset = true; + + if ( caused_reset_attributes ( F_exit_standout_mode.cap + , all_tests & ~same_like_se) ) + F_exit_standout_mode.caused_reset = true; +} + +//---------------------------------------------------------------------- +char* FOptiAttr::change_attribute (char_data*& term, char_data*& next) +{ + fake_reverse = false; + attr_buf[0] = '\0'; + + prevent_no_color_video_attributes (next); + + detectSwitchOn (term, next); + detectSwitchOff (term, next); + + // look for no changes + if ( ! ( switchOn() || switchOff() || colorChange(term, next) ) ) + return 0; + + if ( hasNoAttribute(next) ) + { + if ( off.pc_charset ) + unsetTermPCcharset(term); + if ( off.alt_charset ) + unsetTermAltCharset(term); + + if ( hasAttribute(term) ) + { + if ( F_exit_attribute_mode.cap ) + unsetTermAttributes(term); + else + { + if ( off.bold ) + unsetTermBold(term); + if ( off.dim ) + unsetTermDim(term); + if ( off.italic ) + unsetTermItalic(term); + if ( off.underline ) + unsetTermUnderline(term); + if ( off.blink ) + unsetTermBlink(term); + if ( off.reverse ) + unsetTermReverse(term); + if ( off.standout ) + unsetTermStandout(term); + if ( off.invisible ) + unsetTermInvisible(term); + if ( off.protect ) + unsetTermProtected(term); + if ( off.crossed_out ) + unsetTermCrossedOut(term); + if ( off.dbl_underline ) + unsetTermDoubleUnderline(term); + } + } + if ( colorChange(term, next) ) + change_color (term, next); + } + else if ( F_set_attributes.cap ) + { + unsetTermPCcharset(term); + setTermAttributes ( term + , next->standout + , next->underline + , next->reverse + , next->blink + , next->dim + , next->bold + , next->invisible + , next->protect + , next->alt_charset ); + + if ( next->italic ) + setTermItalic(term); + if ( next->crossed_out ) + setTermCrossedOut(term); + if ( next->dbl_underline ) + setTermDoubleUnderline(term); + if ( next->pc_charset ) + setTermPCcharset(term); + + if ( colorChange(term, next) ) + change_color (term, next); + } + else + { + if ( off.pc_charset ) + unsetTermPCcharset(term); + if ( off.alt_charset ) + unsetTermAltCharset(term); + if ( off.bold ) + unsetTermBold(term); + if ( off.dim ) + unsetTermDim(term); + if ( off.italic ) + unsetTermItalic(term); + if ( off.underline ) + unsetTermUnderline(term); + if ( off.blink ) + unsetTermBlink(term); + if ( off.reverse ) + unsetTermReverse(term); + if ( off.standout ) + unsetTermStandout(term); + if ( off.invisible ) + unsetTermInvisible(term); + if ( off.protect ) + unsetTermProtected(term); + if ( off.crossed_out ) + unsetTermCrossedOut(term); + if ( off.dbl_underline ) + unsetTermDoubleUnderline(term); + + detectSwitchOff (term, next); + + if ( switchOff() ) + unsetTermAttributes(term); + + if ( colorChange(term, next) ) + change_color (term, next); + + detectSwitchOn (term, next); + if ( on.pc_charset ) + setTermPCcharset(term); + if ( on.alt_charset ) + setTermAltCharset(term); + if ( on.bold ) + setTermBold(term); + if ( on.dim ) + setTermDim(term); + if ( on.italic ) + setTermItalic(term); + if ( on.underline ) + setTermUnderline(term); + if ( on.blink ) + setTermBlink(term); + if ( on.reverse ) + setTermReverse(term); + if ( on.standout ) + setTermStandout(term); + if ( on.invisible ) + setTermInvisible(term); + if ( on.protect ) + setTermProtected(term); + if ( on.crossed_out ) + setTermCrossedOut(term); + if ( on.dbl_underline ) + setTermDoubleUnderline(term); + } + + if ( fake_reverse ) + term->reverse = true; + + return attr_buf; +} diff --git a/src/foptiattr.h b/src/foptiattr.h new file mode 100644 index 00000000..f22358d2 --- /dev/null +++ b/src/foptiattr.h @@ -0,0 +1,265 @@ +// File: foptiattr.h +// Provides: class FOptiAttr +// +// Standalone class +// ════════════════ +// +// ▕▔▔▔▔▔▔▔▔▔▔▔▏ +// ▕ FOptiAttr ▏ +// ▕▁▁▁▁▁▁▁▁▁▁▁▏ + +#ifndef _FOPTIATTR_H +#define _FOPTIATTR_H + + +#include // need for std::swap +#include +#include // need for tparm + + +//---------------------------------------------------------------------- +// class FOptiAttr +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FOptiAttr +{ + private: + typedef unsigned char uChar; + + enum init_reset_tests + { + no_test = 0x00, + test_ansi_reset = 0x01, // ANSI X3.64 terminal + test_adm3_reset = 0x02, // Lear Siegler ADM-3 terminal + same_like_ue = 0x04, + same_like_se = 0x08, + same_like_me = 0x10, + all_tests = 0x1f + }; + + typedef struct + { + char* cap; + bool caused_reset; + } capability; + + capability F_enter_bold_mode; + capability F_exit_bold_mode; + capability F_enter_dim_mode; + capability F_exit_dim_mode; + capability F_enter_italics_mode; + capability F_exit_italics_mode; + capability F_enter_underline_mode; + capability F_exit_underline_mode; + capability F_enter_blink_mode; + capability F_exit_blink_mode; + capability F_enter_reverse_mode; + capability F_exit_reverse_mode; + capability F_enter_standout_mode; + capability F_exit_standout_mode; + capability F_enter_secure_mode; + capability F_exit_secure_mode; + capability F_enter_protected_mode; + capability F_exit_protected_mode; + capability F_enter_crossed_out_mode; + capability F_exit_crossed_out_mode; + capability F_enter_dbl_underline_mode; + capability F_exit_dbl_underline_mode; + capability F_set_attributes; + capability F_exit_attribute_mode; + capability F_enter_alt_charset_mode; + capability F_exit_alt_charset_mode; + capability F_enter_pc_charset_mode; + capability F_exit_pc_charset_mode; + capability F_set_a_foreground; + capability F_set_a_background; + capability F_set_foreground; + capability F_set_background; + capability F_set_color_pair; + + int max_color; + int attr_without_color; + bool monochron; + bool fake_reverse; + bool cygwin_terminal; + char attr_buf[8192]; + char* attr_ptr; + + public: + typedef struct + { + int code; // character code + short fg_color; // foreground color + short bg_color; // background color + uChar bold : 1; // bold + uChar dim : 1; // dim + uChar italic : 1; // italic + uChar underline : 1; // underline + uChar blink : 1; // blink + uChar reverse : 1; // reverse + uChar standout : 1; // standout + uChar invisible : 1; // invisible + uChar protect : 1; // protect mode + uChar crossed_out : 1; // crossed out + uChar dbl_underline : 1; // double underline + uChar alt_charset : 1; // alternate character set (vt100) + uChar pc_charset : 1; // pc character set (CP437) + uChar : 3; // padding bits + } char_data; + + private: + char_data on; + char_data off; + + private: + FOptiAttr (const FOptiAttr&); // Disabled copy constructor + FOptiAttr& operator = (const FOptiAttr&); // and operator '=' + bool hasColor (char_data*&); + bool colorChange (char_data*&, char_data*&); + void resetColor (char_data*&); + void prevent_no_color_video_attributes (char_data*&); + void change_color (char_data*&, char_data*&); + bool hasAttribute (char_data*&); + bool hasNoAttribute (char_data*&); + void resetAttribute (char_data*&); + void reset (char_data*&); + bool caused_reset_attributes (char*&, uChar = all_tests); + void detectSwitchOn (char_data*&, char_data*&); + void detectSwitchOff (char_data*&, char_data*&); + bool switchOn(); + bool switchOff(); + bool append_sequence (char*&); + bool replace_sequence (char*&); + bool setTermBold (char_data*&); + bool unsetTermBold (char_data*&); + bool setTermDim (char_data*&); + bool unsetTermDim (char_data*&); + bool setTermItalic (char_data*&); + bool unsetTermItalic (char_data*&); + bool setTermUnderline (char_data*&); + bool unsetTermUnderline (char_data*&); + bool setTermBlink (char_data*&); + bool unsetTermBlink (char_data*&); + bool setTermReverse (char_data*&); + bool unsetTermReverse (char_data*&); + bool setTermStandout (char_data*&); + bool unsetTermStandout (char_data*&); + bool setTermInvisible (char_data*&); + bool unsetTermInvisible (char_data*&); + bool setTermProtected (char_data*&); + bool unsetTermProtected (char_data*&); + bool setTermCrossedOut (char_data*&); + bool unsetTermCrossedOut (char_data*&); + bool setTermDoubleUnderline (char_data*&); + bool unsetTermDoubleUnderline (char_data*&); + bool setTermAttributes ( char_data*& + , bool, bool, bool + , bool, bool, bool + , bool, bool, bool ); + bool unsetTermAttributes (char_data*&); + bool setTermAltCharset (char_data*&); + bool unsetTermAltCharset (char_data*&); + bool setTermPCcharset (char_data*&); + bool unsetTermPCcharset (char_data*&); + + public: + explicit FOptiAttr(); // constructor + ~FOptiAttr(); // destructor + + static short vga2ansi (short); + + void setMaxColor (int&); + void setNoColorVideo (int); + void setCygwinTerminal(); + void set_enter_bold_mode (char*&); + void set_exit_bold_mode (char*&); + void set_enter_dim_mode (char*&); + void set_exit_dim_mode (char*&); + void set_enter_italics_mode (char*&); + void set_exit_italics_mode (char*&); + void set_enter_underline_mode (char*&); + void set_exit_underline_mode (char*&); + void set_enter_blink_mode (char*&); + void set_exit_blink_mode (char*&); + void set_enter_reverse_mode (char*&); + void set_exit_reverse_mode (char*&); + void set_enter_secure_mode (char*&); + void set_exit_secure_mode (char*&); + void set_enter_protected_mode (char*&); + void set_exit_protected_mode (char*&); + void set_enter_crossed_out_mode (char*&); + void set_exit_crossed_out_mode (char*&); + void set_enter_dbl_underline_mode (char*&); + void set_exit_dbl_underline_mode (char*&); + void set_enter_standout_mode (char*&); + void set_exit_standout_mode (char*&); + void set_set_attributes (char*&); + void set_exit_attribute_mode (char*&); + void set_enter_alt_charset_mode (char*&); + void set_exit_alt_charset_mode (char*&); + void set_enter_pc_charset_mode (char*&); + void set_exit_pc_charset_mode (char*&); + void set_a_foreground_color (char*&); + void set_a_background_color (char*&); + void set_foreground_color (char*&); + void set_background_color (char*&); + void set_term_color_pair (char*&); + void init(); + + char* change_attribute (char_data*&, char_data*&); + + friend bool operator == (const char_data&, const char_data&); + friend bool operator != (const char_data&, const char_data&); +}; +#pragma pack(pop) + + +// FOptiAttr inline functions +//---------------------------------------------------------------------- +inline void FOptiAttr::setMaxColor (int& c) +{ max_color = c; } + +//---------------------------------------------------------------------- +inline void FOptiAttr::setNoColorVideo (int attr) +{ attr_without_color = attr; } + +//---------------------------------------------------------------------- +inline void FOptiAttr::setCygwinTerminal() +{ cygwin_terminal = true; } + +//---------------------------------------------------------------------- +inline bool FOptiAttr::hasNoAttribute (char_data*& attr) +{ return ! hasAttribute(attr); } + +//---------------------------------------------------------------------- +inline bool operator == ( const FOptiAttr::char_data& lhs, + const FOptiAttr::char_data& rhs ) +{ + return lhs.code == rhs.code + && lhs.fg_color == rhs.fg_color + && lhs.bg_color == rhs.bg_color + && lhs.bold == rhs.bold + && lhs.dim == rhs.dim + && lhs.italic == rhs.italic + && lhs.underline == rhs.underline + && lhs.blink == rhs.blink + && lhs.reverse == rhs.reverse + && lhs.standout == rhs.standout + && lhs.invisible == rhs.invisible + && lhs.protect == rhs.protect + && lhs.crossed_out == rhs.crossed_out + && lhs.dbl_underline == rhs.dbl_underline + && lhs.alt_charset == rhs.alt_charset + && lhs.pc_charset == rhs.pc_charset; +} + +//---------------------------------------------------------------------- +inline bool operator != ( const FOptiAttr::char_data& lhs, + const FOptiAttr::char_data& rhs ) +{ return ! ( lhs == rhs ); } + + +#endif // _FOPTIATTR_H diff --git a/src/foptimove.h b/src/foptimove.h index 79c5310d..d03be822 100644 --- a/src/foptimove.h +++ b/src/foptimove.h @@ -15,7 +15,7 @@ #define _FOPTIMOVE_H #include -#include +#include // need for tparm #include #include // need for printf diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 11958185..d59596cb 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -110,13 +110,13 @@ void FProgressbar::drawBar() } else { - setColor(wc.progressbar_fg, wc.progressbar_bg); + setColor (wc.progressbar_fg, wc.progressbar_bg); print (fc::LeftHalfBlock); // ▌ } i++; } - setColor(wc.progressbar_fg, wc.progressbar_bg); + setColor (wc.progressbar_fg, wc.progressbar_bg); if ( getMaxColor() < 16 ) { for (; i < BarLength; i++) @@ -154,7 +154,8 @@ void FProgressbar::draw() //---------------------------------------------------------------------- void FProgressbar::hide() { - int fg, bg, s, size; + int s, size; + short fg, bg; char* blank; FWidget::hide(); diff --git a/src/fradiobutton.cpp b/src/fradiobutton.cpp index af62865f..8f1d9b6e 100644 --- a/src/fradiobutton.cpp +++ b/src/fradiobutton.cpp @@ -54,8 +54,10 @@ void FRadioButton::drawRadioButton() { if ( ! isVisible() ) return; + gotoxy (xpos+xmin-1, ypos+ymin-1); setColor (foregroundColor, backgroundColor); + if ( isMonochron() ) { if ( hasFocus() ) diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 82ec3e43..a7a0fe0f 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -515,7 +515,8 @@ void FStatusBar::onMouseMove (FMouseEvent* ev) //---------------------------------------------------------------------- void FStatusBar::hide() { - int fg, bg, lastLine, screenWidth; + int lastLine, screenWidth; + short fg, bg; char* blank; FWindow::hide(); diff --git a/src/ftcap_map.h b/src/ftcap_map.h index 1c31aa83..33027fa6 100644 --- a/src/ftcap_map.h +++ b/src/ftcap_map.h @@ -40,9 +40,10 @@ static tcap_map tcap[] = { 0, "Sf" }, // set_foreground -> Set foreground color #1 { 0, "Sb" }, // set_background -> Set background color #1 { 0, "sp" }, // set_color_pair -> Set current color pair to #1 - { 0, "sa" }, // set_attributes -> define videoattributes #1-#9 (PG9) { 0, "op" }, // orig_pair -> Set default pair to original value { 0, "oc" }, // orig_colors -> Set all color pairs to the original + { 0, "NC" }, // no_color_video -> video attributes that cannot be used + // with colors { 0, "cm" }, // cursor_address -> move to row #1 columns #2 { 0, "ch" }, // column_address -> horizontal position #1, absolute (P) { 0, "cv" }, // row_address -> vertical position #1 absolute (P) @@ -62,24 +63,29 @@ static tcap_map tcap[] = { 0, "ti" }, // enter_ca_mode -> string to start programs using cup { 0, "te" }, // exit_ca_mode -> strings to end programs using cup { 0, "eA" }, // enable_acs -> enable alternate char set - { 0, "md" }, // enter_bold_mode -> turn on bold (extra bright) mode + { 0, "md" }, // enter_bold_mode -> turn on bold (double-bright) mode { 0, "me" }, // exit_bold_mode -> turn off bold mode { 0, "mh" }, // enter_dim_mode -> turn on half-bright { 0, "me" }, // exit_dim_mode -> turn off half-bright { 0, "ZH" }, // enter_italics_mode -> Enter italic mode { 0, "ZR" }, // exit_italics_mode -> End italic mode - { 0, "mb" }, // enter_blink_mode -> turn on blinking - { 0, "me" }, // exit_blink_mode -> turn off blinking { 0, "us" }, // enter_underline_mode -> begin underline mode { 0, "ue" }, // exit_underline_mode -> exit underline mode + { 0, "mb" }, // enter_blink_mode -> turn on blinking + { 0, "me" }, // exit_blink_mode -> turn off blinking { 0, "mr" }, // enter_reverse_mode -> turn on reverse video mode { 0, "me" }, // exit_reverse_mode -> turn off reverse video mode - { 0, "mk" }, // enter_secure_mode -> turn on blank mode (characters invisible) - { 0, "me" }, // exit_secure_mode -> turn off blank mode (characters visible) - { 0, "XX" }, // enter_crossed_out_mode -> turn on mark character as deleted - { 0, "me" }, // exit_crossed_out_mode -> turn off mark character as deleted { 0, "so" }, // enter_standout_mode -> begin standout mode { 0, "se" }, // exit_standout_mode -> exit standout mode + { 0, "mk" }, // enter_secure_mode -> turn on blank mode (characters invisible) + { 0, "me" }, // exit_secure_mode -> turn off blank mode (characters visible) + { 0, "mp" }, // enter_protected_mode -> turn on protected mode + { 0, "me" }, // exit_protected_mode -> turn off protected mode + { 0, "XX" }, // enter_crossed_out_mode -> turn on mark character as deleted + { 0, "me" }, // exit_crossed_out_mode -> turn off mark character as deleted + { 0, "Us" }, // enter_dbl_underline_mode -> begin double underline mode + { 0, "Ue" }, // exit_dbl_underline_mode -> exit double underline mode + { 0, "sa" }, // set_attributes -> define videoattributes #1-#9 (PG9) { 0, "me" }, // exit_attribute_mode -> turn off all attributes { 0, "as" }, // enter_alt_charset_mode -> start alternate character set (P) { 0, "ae" }, // exit_alt_charset_mode -> end alternate character set (P) @@ -103,6 +109,8 @@ static tcap_map tcap[] = * (P*) indicates that padding may vary in proportion * to the number of lines affected * (#i) indicates the ith parameter. + * + * "XX", "Us" and "Ue" are unofficial and are only used here. */ enum termcaps @@ -124,9 +132,9 @@ enum termcaps t_set_foreground, t_set_background, t_set_color_pair, - t_set_attributes, t_orig_pair, t_orig_colors, + t_no_color_video, t_cursor_address, t_column_address, t_row_address, @@ -152,18 +160,23 @@ enum termcaps t_exit_dim_mode, t_enter_italics_mode, t_exit_italics_mode, - t_enter_blink_mode, - t_exit_blink_mode, t_enter_underline_mode, t_exit_underline_mode, + t_enter_blink_mode, + t_exit_blink_mode, t_enter_reverse_mode, t_exit_reverse_mode, - t_enter_secure_mode, - t_exit_secure_mode, - t_enter_crossed_out_mode, - t_exit_crossed_out_mode, t_enter_standout_mode, t_exit_standout_mode, + t_enter_secure_mode, + t_exit_secure_mode, + t_enter_protected_mode, + t_exit_protected_mode, + t_enter_crossed_out_mode, + t_exit_crossed_out_mode, + t_enter_dbl_underline_mode, + t_exit_dbl_underline_mode, + t_set_attributes, t_exit_attribute_mode, t_enter_alt_charset_mode, t_exit_alt_charset_mode, diff --git a/src/fterm.cpp b/src/fterm.cpp index ef9a9f4e..37b693af 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -26,31 +26,16 @@ int (*FTerm::Fputchar)(int); int FTerm::stdin_no; int FTerm::stdout_no; int FTerm::fd_tty; -int FTerm::fg_color; -int FTerm::bg_color; -int FTerm::fg_term_color; -int FTerm::bg_term_color; int FTerm::x_term_pos; int FTerm::y_term_pos; int FTerm::max_color; int FTerm::stdin_status_flags; uInt FTerm::baudrate; uInt FTerm::tabstop; +uInt FTerm::attr_without_color; bool FTerm::resize_term; -bool FTerm::bold; -bool FTerm::dim; -bool FTerm::italic; -bool FTerm::reverse; -bool FTerm::underline; -bool FTerm::term_bold; -bool FTerm::term_dim; -bool FTerm::term_italic; -bool FTerm::term_reverse; -bool FTerm::term_underline; bool FTerm::hiddenCursor; bool FTerm::mouse_support; -bool FTerm::vt100_state; -bool FTerm::ignore_vt100_state; bool FTerm::raw_mode; bool FTerm::input_data_pending; bool FTerm::terminal_update_pending; @@ -59,7 +44,6 @@ 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; @@ -80,7 +64,6 @@ bool FTerm::screen_terminal; bool FTerm::tmux_terminal; bool FTerm::terminal_updates; bool FTerm::vterm_updates; -bool FTerm::pc_charset_state; bool FTerm::pc_charset_console; bool FTerm::utf8_input; bool FTerm::utf8_state; @@ -94,6 +77,7 @@ bool FTerm::VGAFont; bool FTerm::cursor_optimisation; uChar FTerm::x11_button_state; termios FTerm::term_init; + char FTerm::termtype[30] = ""; char* FTerm::term_name = 0; char* FTerm::locale_name = 0; @@ -107,7 +91,8 @@ const FString* FTerm::xterm_font = 0; const FString* FTerm::xterm_title = 0; const FString* FTerm::AnswerBack = 0; const FString* FTerm::Sec_DA = 0; -FOptiMove* FTerm::opti = 0; +FOptiMove* FTerm::opti_move = 0; +FOptiAttr* FTerm::opti_attr = 0; FTerm::term_area* FTerm::vterm = 0; FTerm::term_area* FTerm::vdesktop = 0; FTerm::term_area* FTerm::vmenubar = 0; @@ -117,6 +102,8 @@ std::queue* FTerm::output_buffer = 0; std::map* FTerm::vt100_alt_char = 0; std::map* \ FTerm::encoding_set = 0; +FOptiAttr::char_data FTerm::term_attribute; +FOptiAttr::char_data FTerm::next_attribute; console_font_op FTerm::screenFont; unimapdesc FTerm::screenUnicodeMap; fc::console_cursor_style \ @@ -146,17 +133,14 @@ FTerm::FTerm() vmenubar = 0; vstatusbar = 0; last_area = 0; - fg_color = -1; - bg_color = -1; - fg_term_color = -1; - bg_term_color = -1; x_term_pos = -1; y_term_pos = -1; - opti = new FOptiMove(); - term = new FRect(0,0,0,0); - mouse = new FPoint(0,0); - cursor = new FPoint(0,0); + opti_move = new FOptiMove(); + opti_attr = new FOptiAttr(); + term = new FRect(0,0,0,0); + mouse = new FPoint(0,0); + cursor = new FPoint(0,0); init(); } @@ -171,7 +155,8 @@ FTerm::~FTerm() // destructor delete cursor; delete mouse; delete term; - delete opti; + delete opti_attr; + delete opti_move; } } @@ -825,6 +810,8 @@ char* FTerm::parseAnswerbackMsg (char*& current_termtype) char* FTerm::parseSecDA (char*& current_termtype) { char* new_termtype = current_termtype; + bool sec_da_supported = false; + // The Linux console knows no Sec_DA if ( linux_terminal ) @@ -835,11 +822,21 @@ char* FTerm::parseSecDA (char*& current_termtype) if ( Sec_DA && Sec_DA->getLength() > 5 ) { + uLong num_components; + + // remove the first 3 bytes ("\033[>") FString temp = Sec_DA->right(Sec_DA->getLength() - 3); + // remove the last byte ("c") temp.remove(temp.getLength()-1, 1); + // split into components std::vector Sec_DA_split = temp.split(';'); - if ( Sec_DA_split.size() >= 2 ) + num_components = Sec_DA_split.size(); + + if ( num_components == 3 ) + sec_da_supported = true; + + if ( num_components >= 2 ) { FString* Sec_DA_components = &Sec_DA_split[0]; @@ -878,13 +875,24 @@ char* FTerm::parseSecDA (char*& current_termtype) break; case 1: - // also used by apple terminal - if ( Sec_DA_components[1] - && strncmp(Sec_DA_components[1].c_str(), "2c", 2) == 0 ) + // Read the terminal (firmware) version + try { - kterm_terminal = true; // kterm + if ( Sec_DA_components[1] ) + terminal_id_version = Sec_DA_components[1].toInt(); + else + terminal_id_version = -1; } - else + catch (const std::exception&) + { + terminal_id_version = -1; + } + if ( ! sec_da_supported ) + { + if ( terminal_id_version == 2 ) // also used by apple terminal + kterm_terminal = true; // kterm + } + else if ( terminal_id_version > 1000 ) { gnome_terminal = true; // vte / gnome terminal if ( color256 ) @@ -941,7 +949,7 @@ char* FTerm::parseSecDA (char*& current_termtype) } //---------------------------------------------------------------------- -void FTerm::init_vt100altChar() +void FTerm::init_alt_charset() { // read the used vt100 pairs if ( tcap[t_acs_chars].string ) @@ -984,6 +992,53 @@ void FTerm::init_vt100altChar() } } +//---------------------------------------------------------------------- +void FTerm::init_pc_charset() +{ + bool reinit = false; + + // fallback if "S2" is not found + if ( ! tcap[t_enter_pc_charset_mode].string ) + { + if ( utf8_console ) + { + // Select iso8859-1 + null mapping + tcap[t_enter_pc_charset_mode].string = \ + const_cast("\033%@\033(U"); + } + else + { + // Select null mapping + tcap[t_enter_pc_charset_mode].string = \ + const_cast("\033(U"); + } + 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 ) + { + // Select ascii mapping + utf8 + tcap[t_exit_pc_charset_mode].string = \ + const_cast("\033(B\033%G"); + } + else + { + // Select ascii mapping + tcap[t_enter_pc_charset_mode].string = \ + const_cast("\033(B"); + } + opti_attr->set_exit_pc_charset_mode (tcap[t_exit_pc_charset_mode].string); + reinit = true; + } + + if ( reinit ) + opti_attr->init(); +} + //---------------------------------------------------------------------- void FTerm::init_termcaps() { @@ -1022,12 +1077,19 @@ void FTerm::init_termcaps() // maximum number of colors on screen max_color = tgetnum(const_cast("Co")); + if ( max_color < 0 ) + max_color = 1; + if ( max_color < 8 ) monochron = true; else monochron = false; tabstop = uInt(tgetnum(const_cast("it"))); + attr_without_color = uInt(tgetnum(const_cast("NC"))); + // gnome-terminal has NC=16 however, it can use the dim attribute + if ( gnome_terminal ) + attr_without_color = 0; // read termcap output strings for (int i=0; tcap[i].tname[0] != 0; i++) @@ -1070,12 +1132,21 @@ void FTerm::init_termcaps() tcap[t_set_a_background].string = \ const_cast("\033[4%p1%{8}%m%d%?%p1%{7}%>%t;5%e;25%;m"); } + else if ( rxvt_terminal && ! urxvt_terminal ) + { + tcap[t_set_a_foreground].string = \ + const_cast("\033[%?%p1%{8}%<%t%p1%{30}%+%e%p1%'R'%+%;%dm"); + tcap[t_set_a_background].string = \ + const_cast("\033[%?%p1%{8}%<%t%p1%'('%+%e%p1%{92}%+%;%dm"); + } else if ( tera_terminal ) { tcap[t_set_a_foreground].string = \ const_cast("\033[38;5;%p1%dm"); tcap[t_set_a_background].string = \ const_cast("\033[48;5;%p1%dm"); + tcap[t_exit_attribute_mode].string = \ + const_cast("\033[0m\017"); } else if ( putty_terminal ) { @@ -1126,45 +1197,40 @@ 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 ) + // test for standard ECMA-48 (ANSI X3.64) terminal + if ( tcap[t_exit_underline_mode].string + && strncmp(tcap[t_exit_underline_mode].string, "\033[24m", 5) == 0 ) { - 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; + // seems to be a ECMA-48 (ANSI X3.64) compatible terminal + tcap[t_enter_dbl_underline_mode].string = \ + const_cast("\033[21m"); // Exit single underline, too - // test for standard ECMA-48 terminal - if ( strncmp(tcap[t_exit_underline_mode].string, "\033[24m", 5) == 0 ) - { - tcap[t_exit_bold_mode].string = \ - const_cast("\033[22m"); // Exit dim, too + tcap[t_exit_dbl_underline_mode].string = \ + const_cast("\033[24m"); - tcap[t_exit_dim_mode].string = \ - const_cast("\033[22m"); + tcap[t_exit_bold_mode].string = \ + const_cast("\033[22m"); // Exit dim, too - tcap[t_exit_underline_mode].string = \ - const_cast("\033[24m"); + tcap[t_exit_dim_mode].string = \ + const_cast("\033[22m"); - tcap[t_exit_blink_mode].string = \ - const_cast("\033[25m"); + tcap[t_exit_underline_mode].string = \ + const_cast("\033[24m"); - tcap[t_exit_reverse_mode].string = \ - const_cast("\033[27m"); + tcap[t_exit_blink_mode].string = \ + const_cast("\033[25m"); - tcap[t_exit_secure_mode].string = \ - const_cast("\033[28m"); + tcap[t_exit_reverse_mode].string = \ + const_cast("\033[27m"); - tcap[t_enter_crossed_out_mode].string = \ - const_cast("\033[9m"); + tcap[t_exit_secure_mode].string = \ + const_cast("\033[28m"); - tcap[t_exit_crossed_out_mode].string = \ - const_cast("\033[29m"); - } + tcap[t_enter_crossed_out_mode].string = \ + const_cast("\033[9m"); + + tcap[t_exit_crossed_out_mode].string = \ + const_cast("\033[29m"); } // read termcap key strings @@ -1190,6 +1256,10 @@ void FTerm::init_termcaps() if ( strncmp(Fkey[i].tname, "k4x", 3) == 0 ) Fkey[i].string = const_cast("\033[14~"); // F4 + + // fallback for TERM=ansi + if ( strncmp(Fkey[i].tname, "@7X", 3) == 0 ) + Fkey[i].string = const_cast("\033[K"); // end key } // Some terminals (e.g. PuTTY) send the wrong code for the arrow keys @@ -1238,26 +1308,66 @@ void FTerm::init_termcaps() } // duration precalculation of the cursor movement strings - opti->setTabStop(int(tabstop)); - opti->set_cursor_home (tcap[t_cursor_home].string); - opti->set_cursor_to_ll (tcap[t_cursor_to_ll].string); - opti->set_carriage_return (tcap[t_carriage_return].string); - opti->set_tabular (tcap[t_tab].string); - opti->set_back_tab (tcap[t_back_tab].string); - opti->set_cursor_up (tcap[t_cursor_up].string); - opti->set_cursor_down (tcap[t_cursor_down].string); - opti->set_cursor_left (tcap[t_cursor_left].string); - opti->set_cursor_right (tcap[t_cursor_right].string); - opti->set_cursor_address (tcap[t_cursor_address].string); - opti->set_column_address (tcap[t_column_address].string); - opti->set_row_address (tcap[t_row_address].string); - opti->set_parm_up_cursor (tcap[t_parm_up_cursor].string); - opti->set_parm_down_cursor (tcap[t_parm_down_cursor].string); - opti->set_parm_left_cursor (tcap[t_parm_left_cursor].string); - opti->set_parm_right_cursor (tcap[t_parm_right_cursor].string); - opti->set_auto_left_margin (automatic_left_margin); - opti->set_eat_newline_glitch (eat_nl_glitch); - //opti->printDurations(); + opti_move->setTabStop(int(tabstop)); + opti_move->set_cursor_home (tcap[t_cursor_home].string); + opti_move->set_cursor_to_ll (tcap[t_cursor_to_ll].string); + opti_move->set_carriage_return (tcap[t_carriage_return].string); + opti_move->set_tabular (tcap[t_tab].string); + opti_move->set_back_tab (tcap[t_back_tab].string); + opti_move->set_cursor_up (tcap[t_cursor_up].string); + opti_move->set_cursor_down (tcap[t_cursor_down].string); + opti_move->set_cursor_left (tcap[t_cursor_left].string); + opti_move->set_cursor_right (tcap[t_cursor_right].string); + opti_move->set_cursor_address (tcap[t_cursor_address].string); + opti_move->set_column_address (tcap[t_column_address].string); + opti_move->set_row_address (tcap[t_row_address].string); + opti_move->set_parm_up_cursor (tcap[t_parm_up_cursor].string); + opti_move->set_parm_down_cursor (tcap[t_parm_down_cursor].string); + opti_move->set_parm_left_cursor (tcap[t_parm_left_cursor].string); + opti_move->set_parm_right_cursor (tcap[t_parm_right_cursor].string); + opti_move->set_auto_left_margin (automatic_left_margin); + opti_move->set_eat_newline_glitch (eat_nl_glitch); + //opti_move->printDurations(); + + // attribute settings + opti_attr->setNoColorVideo (int(attr_without_color)); + opti_attr->set_enter_bold_mode (tcap[t_enter_bold_mode].string); + opti_attr->set_exit_bold_mode (tcap[t_exit_bold_mode].string); + opti_attr->set_enter_dim_mode (tcap[t_enter_dim_mode].string); + opti_attr->set_exit_dim_mode (tcap[t_exit_dim_mode].string); + opti_attr->set_enter_italics_mode (tcap[t_enter_italics_mode].string); + opti_attr->set_exit_italics_mode (tcap[t_exit_italics_mode].string); + opti_attr->set_enter_underline_mode (tcap[t_enter_underline_mode].string); + opti_attr->set_exit_underline_mode (tcap[t_exit_underline_mode].string); + opti_attr->set_enter_blink_mode (tcap[t_enter_blink_mode].string); + opti_attr->set_exit_blink_mode (tcap[t_exit_blink_mode].string); + opti_attr->set_enter_reverse_mode (tcap[t_enter_reverse_mode].string); + opti_attr->set_exit_reverse_mode (tcap[t_exit_reverse_mode].string); + opti_attr->set_enter_standout_mode (tcap[t_enter_standout_mode].string); + opti_attr->set_exit_standout_mode (tcap[t_exit_standout_mode].string); + opti_attr->set_enter_secure_mode (tcap[t_enter_secure_mode].string); + opti_attr->set_exit_secure_mode (tcap[t_exit_secure_mode].string); + opti_attr->set_enter_protected_mode (tcap[t_enter_protected_mode].string); + opti_attr->set_exit_protected_mode (tcap[t_exit_protected_mode].string); + opti_attr->set_enter_crossed_out_mode (tcap[t_enter_crossed_out_mode].string); + opti_attr->set_exit_crossed_out_mode (tcap[t_exit_crossed_out_mode].string); + opti_attr->set_enter_dbl_underline_mode (tcap[t_enter_dbl_underline_mode].string); + opti_attr->set_exit_dbl_underline_mode (tcap[t_exit_dbl_underline_mode].string); + opti_attr->set_set_attributes (tcap[t_set_attributes].string); + opti_attr->set_exit_attribute_mode (tcap[t_exit_attribute_mode].string); + opti_attr->set_enter_alt_charset_mode (tcap[t_enter_alt_charset_mode].string); + opti_attr->set_exit_alt_charset_mode (tcap[t_exit_alt_charset_mode].string); + opti_attr->set_enter_pc_charset_mode (tcap[t_enter_pc_charset_mode].string); + opti_attr->set_exit_pc_charset_mode (tcap[t_exit_pc_charset_mode].string); + opti_attr->set_a_foreground_color (tcap[t_set_a_foreground].string); + opti_attr->set_a_background_color (tcap[t_set_a_background].string); + opti_attr->set_foreground_color (tcap[t_set_foreground].string); + opti_attr->set_background_color (tcap[t_set_background].string); + opti_attr->set_term_color_pair (tcap[t_set_color_pair].string); + opti_attr->setMaxColor(max_color); + if ( cygwin_terminal ) + opti_attr->setCygwinTerminal(); + opti_attr->init(); } //---------------------------------------------------------------------- @@ -1278,7 +1388,7 @@ void FTerm::init_encoding() { vt100_console = true; Encoding = fc::VT100; - Fputchar = &FTerm::putchar_VT100; // function pointer + Fputchar = &FTerm::putchar_ASCII; // function pointer } else { @@ -1287,6 +1397,8 @@ void FTerm::init_encoding() Fputchar = &FTerm::putchar_ASCII; // function pointer } + init_pc_charset(); + if ( linux_terminal || cygwin_terminal || NewFont @@ -1294,24 +1406,24 @@ void FTerm::init_encoding() { pc_charset_console = true; Encoding = fc::PC; - Fputchar = &FTerm::putchar_PC; // function pointer + Fputchar = &FTerm::putchar_ASCII; // function pointer if ( linux_terminal && utf8_console ) { utf8_linux_terminal = true; setUTF8(false); } - } - else - { - pc_charset_console = false; + else if ( xterm && utf8_console ) + { + Fputchar = &FTerm::putchar_UTF8; // function pointer + } } if ( force_vt100 ) { vt100_console = true; Encoding = fc::VT100; - Fputchar = &FTerm::putchar_VT100; // function pointer + Fputchar = &FTerm::putchar_ASCII; // function pointer } } @@ -1338,25 +1450,13 @@ void FTerm::init() utf8_input = \ utf8_state = \ utf8_linux_terminal = \ + pc_charset_console = \ vt100_console = \ - vt100_state = \ - ignore_vt100_state = \ - pc_charset_state = \ NewFont = \ VGAFont = \ ascii_console = \ hiddenCursor = \ mouse_support = \ - bold = \ - dim = \ - italic = \ - underline = \ - reverse = \ - term_bold = \ - term_dim = \ - term_italic = \ - term_underline = \ - term_reverse = \ force_vt100 = \ tera_terminal = \ kterm_terminal = \ @@ -1368,6 +1468,40 @@ void FTerm::init() tmux_terminal = \ background_color_erase = false; + term_attribute.code = '\0'; + term_attribute.fg_color = -1; + term_attribute.bg_color = -1; + term_attribute.bold = \ + term_attribute.dim = \ + term_attribute.italic = \ + term_attribute.underline = \ + term_attribute.blink = \ + term_attribute.reverse = \ + term_attribute.standout = \ + term_attribute.invisible = \ + term_attribute.protect = \ + term_attribute.crossed_out = \ + term_attribute.dbl_underline = \ + term_attribute.alt_charset = \ + term_attribute.pc_charset = false; + + next_attribute.code = '\0'; + next_attribute.fg_color = -1; + next_attribute.bg_color = -1; + next_attribute.bold = \ + next_attribute.dim = \ + next_attribute.italic = \ + next_attribute.underline = \ + next_attribute.blink = \ + next_attribute.reverse = \ + next_attribute.standout = \ + next_attribute.invisible = \ + next_attribute.protect = \ + next_attribute.crossed_out = \ + next_attribute.dbl_underline = \ + next_attribute.alt_charset = \ + next_attribute.pc_charset = false; + // Preset to true cursor_optimisation = true; @@ -1408,7 +1542,7 @@ void FTerm::init() baudrate = getBaudRate(&term_init); if ( isatty(stdout_no) ) - opti->setBaudRate(int(baudrate)); + opti_move->setBaudRate(int(baudrate)); // Import the untrusted environment variable TERM const char* term_env = getenv(const_cast("TERM")); @@ -1426,10 +1560,7 @@ void FTerm::init() cygwin_terminal = false; if ( strncmp(termtype, "rxvt-cygwin-native", 18) == 0 ) - { - new_termtype = const_cast("rxvt-16color"); rxvt_terminal = true; - } // Test for Linux console if ( strncmp(termtype, const_cast("linux"), 5) == 0 @@ -1466,7 +1597,7 @@ void FTerm::init() // Initializes variables for the current terminal init_termcaps(); - init_vt100altChar(); + init_alt_charset(); // set the Fputchar function pointer locale_name = setlocale(LC_ALL, ""); // init current locale @@ -1570,9 +1701,15 @@ void FTerm::init() unsetNonBlockingInput(); } - if ( (max_color == 8) - && (linux_terminal || cygwin_terminal || putty_terminal || tera_terminal) ) + if ( (max_color == 8) + && ( linux_terminal + || cygwin_terminal + || putty_terminal + || tera_terminal + || rxvt_terminal) ) + { max_color = 16; + } if ( linux_terminal && openConsole() == 0 ) { @@ -1650,6 +1787,13 @@ void FTerm::finish() fflush(stdout); } + // turn off pc charset mode + if ( tcap[t_exit_pc_charset_mode].string ) + { + putstring (tcap[t_exit_pc_charset_mode].string); + fflush(stdout); + } + // reset xterm color settings to default setXTermCursorColor("rgb:b1b1/b1b1/b1b1"); resetXTermMouseForeground(); @@ -1672,21 +1816,23 @@ void FTerm::finish() resetXTermColors(); resetColorMap(); } + if ( mintty_terminal ) { // normal escape key mode putstring ("\033[?7727l"); fflush(stdout); } + if ( linux_terminal ) { setLightBackgroundColors (false); setConsoleCursor(fc::default_cursor); } + if ( kde_konsole ) setKDECursor(fc::BlockCursor); - setVT100altChar(false); resetBeep(); if ( linux_terminal @@ -1773,19 +1919,21 @@ void FTerm::finish() } //---------------------------------------------------------------------- -uInt FTerm::charEncode (uInt c) +inline uInt FTerm::charEncode (uInt c) { - register uInt* p; - fc::encoding num = fc::NUM_OF_ENCODINGS; + return charEncode (c, Encoding); +} - p = std::find ( character[0] - , character[lastCharItem] + num - , c ); - if ( p != character[lastCharItem] + num ) // found +//---------------------------------------------------------------------- +uInt FTerm::charEncode (uInt c, fc::encoding enc) +{ + for (uInt i=0; i<=lastCharItem; i++) { - register uInt item = uInt( std::distance(character[0], p) - / num ); - c = character[item][Encoding]; + if ( character[i][0] == c ) + { + c = character[i][enc]; + break; + } } return c; } @@ -1807,6 +1955,14 @@ uInt FTerm::cp437_to_unicode (uChar c) } // protected methods of FTerm +//---------------------------------------------------------------------- +bool FTerm::charEncodable (uInt c) +{ + uInt ch = charEncode(c); + + return bool(ch > 0 && ch != c); +} + //---------------------------------------------------------------------- void FTerm::createArea (term_area*& area) { @@ -1875,18 +2031,28 @@ void FTerm::resizeArea (term_area* area) area->right_shadow = rsw; area->bottom_shadow = bsh; - default_char.code = ' '; - default_char.fg_color = fc::Black; - default_char.bg_color = fc::Black; - default_char.bold = 0; - default_char.dim = 0; - default_char.italic = 0; - default_char.reverse = 0; - default_char.underline = 0; + default_char.code = ' '; + default_char.fg_color = fc::Black; + default_char.bg_color = fc::Black; + default_char.bold = 0; + default_char.dim = 0; + default_char.italic = 0; + default_char.underline = 0; + default_char.blink = 0; + default_char.reverse = 0; + default_char.standout = 0; + default_char.invisible = 0; + default_char.protect = 0; + default_char.crossed_out = 0; + default_char.dbl_underline = 0; + default_char.alt_charset = 0; + default_char.pc_charset = 0; + std::fill_n (area->text, area_size, default_char); unchanged.xmin = uInt(width+rsw); unchanged.xmax = 0; + std::fill_n (area->changes, height+bsh, unchanged); } @@ -1902,8 +2068,8 @@ void FTerm::restoreVTerm (const FRect& box) //---------------------------------------------------------------------- void FTerm::restoreVTerm (int x, int y, int w, int h) { - FTerm::char_data* tc; // terminal character - FTerm::char_data* sc; // shown character + char_data* tc; // terminal character + char_data* sc; // shown character FWidget* widget; x--; @@ -1981,7 +2147,7 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) sc = &vstatusbar->text[(y+ty-bar_y) * vstatusbar->width + (x+tx-bar_x)]; } - memcpy (tc, sc, sizeof(FTerm::char_data)); + memcpy (tc, sc, sizeof(char_data)); if ( short(vterm->changes[y+ty].xmin) > x ) vterm->changes[y+ty].xmin = uInt(x); @@ -2063,8 +2229,8 @@ bool FTerm::isCovered(int x, int y, FTerm::term_area* area) const void FTerm::updateVTerm (FTerm::term_area* area) { int ax, ay, aw, ah, rsh, bsh, y_end, ol; - FTerm::char_data* tc; // terminal character - FTerm::char_data* ac; // area character + char_data* tc; // terminal character + char_data* ac; // area character if ( ! vterm_updates ) { @@ -2126,7 +2292,9 @@ void FTerm::updateVTerm (FTerm::term_area* area) tc = &vterm->text[gy * vterm->width + gx - ol]; if ( ! isCovered(gx-ol, gy, area) ) - memcpy (tc, ac, sizeof(FTerm::char_data)); + memcpy (tc, ac, sizeof(char_data)); + else + line_xmin++; // don't update covered character } _xmin = ax + line_xmin - ol; _xmax = ax + line_xmax; @@ -2153,8 +2321,8 @@ void FTerm::getArea (int ax, int ay, FTerm::term_area* area) { int y_end; int length; - FTerm::char_data* tc; // terminal character - FTerm::char_data* ac; // area character + char_data* tc; // terminal character + char_data* ac; // area character if ( ! area ) return; @@ -2175,7 +2343,7 @@ void FTerm::getArea (int ax, int ay, FTerm::term_area* area) { ac = &area->text[y * area->width]; tc = &vterm->text[(ay+y) * vterm->width + ax]; - memcpy (ac, tc, sizeof(FTerm::char_data) * unsigned(length)); + memcpy (ac, tc, sizeof(char_data) * unsigned(length)); if ( short(area->changes[y].xmin) > 0 ) area->changes[y].xmin = 0; @@ -2188,8 +2356,8 @@ void FTerm::getArea (int ax, int ay, FTerm::term_area* area) void FTerm::getArea (int x, int y, int w, int h, FTerm::term_area* area) { int y_end, length, dx, dy; - FTerm::char_data* tc; // terminal character - FTerm::char_data* ac; // area character + char_data* tc; // terminal character + char_data* ac; // area character if ( ! area ) return; @@ -2218,7 +2386,7 @@ void FTerm::getArea (int x, int y, int w, int h, FTerm::term_area* area) tc = &vterm->text[(y+_y-1) * vterm->width + x-1]; ac = &area->text[(dy+_y) * line_len + dx]; - memcpy (ac, tc, sizeof(FTerm::char_data) * unsigned(length)); + memcpy (ac, tc, sizeof(char_data) * unsigned(length)); if ( short(area->changes[dy+_y].xmin) > dx ) area->changes[dy+_y].xmin = uInt(dx); @@ -2241,8 +2409,8 @@ void FTerm::putArea (const FPoint& pos, FTerm::term_area* area) void FTerm::putArea (int ax, int ay, FTerm::term_area* area) { int aw, ah, rsh, bsh, y_end, length, ol, sbar; - FTerm::char_data* tc; // terminal character - FTerm::char_data* ac; // area character + char_data* tc; // terminal character + char_data* ac; // area character if ( ! area ) return; @@ -2287,7 +2455,7 @@ void FTerm::putArea (int ax, int ay, FTerm::term_area* area) tc = &vterm->text[(ay+y) * vterm->width + ax]; ac = &area->text[y * line_len + ol]; - memcpy (tc, ac, sizeof(FTerm::char_data) * unsigned(length)); + memcpy (tc, ac, sizeof(char_data) * unsigned(length)); if ( ax < short(vterm->changes[ay+y].xmin) ) vterm->changes[ay+y].xmin = uInt(ax); @@ -2300,7 +2468,7 @@ void FTerm::putArea (int ax, int ay, FTerm::term_area* area) FTerm::char_data FTerm::getCoveredCharacter (int x, int y, FTerm* obj) { int xx,yy; - FTerm::char_data* cc; // covered character + char_data* cc; // covered character FWidget* w; x--; @@ -2371,7 +2539,10 @@ bool FTerm::setVGAFont() NewFont = false; pc_charset_console = true; Encoding = fc::PC; - Fputchar = &FTerm::putchar_PC; // function pointer + if ( xterm && utf8_console ) + Fputchar = &FTerm::putchar_UTF8; + else + Fputchar = &FTerm::putchar_ASCII; } else if ( linux_terminal ) { @@ -2400,7 +2571,7 @@ bool FTerm::setVGAFont() pc_charset_console = true; Encoding = fc::PC; - Fputchar = &FTerm::putchar_PC; // function pointer + Fputchar = &FTerm::putchar_ASCII; } else VGAFont = false; @@ -2422,7 +2593,10 @@ bool FTerm::setNewFont() fflush(stdout); pc_charset_console = true; Encoding = fc::PC; - Fputchar = &FTerm::putchar_PC; // function pointer + if ( xterm && utf8_console ) + Fputchar = &FTerm::putchar_UTF8; + else + Fputchar = &FTerm::putchar_ASCII; } else if ( linux_terminal ) { @@ -2450,7 +2624,7 @@ bool FTerm::setNewFont() } pc_charset_console = true; Encoding = fc::PC; - Fputchar = &FTerm::putchar_PC; // function pointer + Fputchar = &FTerm::putchar_ASCII; // function pointer } else NewFont = false; @@ -2551,7 +2725,7 @@ void FTerm::getTermSize() term->setRect(1, 1, win_size.ws_col, win_size.ws_row); } - opti->setTermSize (term->getWidth(), term->getHeight()); + opti_move->setTermSize (term->getWidth(), term->getHeight()); } //---------------------------------------------------------------------- @@ -2615,18 +2789,28 @@ void FTerm::resizeVTerm() vterm->width = term_width; vterm->height = term_height; - default_char.code = ' '; - default_char.fg_color = fc::LightGray; - default_char.bg_color = fc::Black; - default_char.bold = 0; - default_char.dim = 0; - default_char.italic = 0; - default_char.reverse = 0; - default_char.underline = 0; + default_char.code = ' '; + default_char.fg_color = fc::LightGray; + default_char.bg_color = fc::Black; + default_char.bold = 0; + default_char.dim = 0; + default_char.italic = 0; + default_char.underline = 0; + default_char.blink = 0; + default_char.reverse = 0; + default_char.standout = 0; + default_char.invisible = 0; + default_char.protect = 0; + default_char.crossed_out = 0; + default_char.dbl_underline = 0; + default_char.alt_charset = 0; + default_char.pc_charset = 0; + std::fill_n (vterm->text, vterm_size, default_char); unchanged.xmin = uInt(term_width); unchanged.xmax = 0; + std::fill_n (vterm->changes, term_height, unchanged); } @@ -3003,12 +3187,12 @@ void FTerm::resetColorMap() } //---------------------------------------------------------------------- -void FTerm::setPalette (int index, int r, int g, int b) +void FTerm::setPalette (short index, int r, int g, int b) { char* Ic = tcap[t_initialize_color].string; char* Ip = tcap[t_initialize_pair].string; - index = vga2ansi(index); + index = FOptiAttr::vga2ansi(index); if ( Ic || Ip ) { @@ -3042,108 +3226,6 @@ void FTerm::setPalette (int index, int r, int g, int b) fflush(stdout); } -//---------------------------------------------------------------------- -void FTerm::setColor (register int fg, register int bg) // Changes colors -{ - fg_color = fg; - bg_color = bg; -} - -//---------------------------------------------------------------------- -inline int FTerm::vga2ansi (register int color) -{ - // VGA | ANSI - // i R G B | i B G R - //---------+--------- - // 0 0 0 0 | 0 0 0 0 i = intensity bit - // 0 0 0 1 | 0 1 0 0 R = red - // 0 0 1 0 | 0 0 1 0 G = green - // 0 0 1 1 | 0 1 1 0 B = blue - // 0 1 0 0 | 0 0 0 1 - // 0 1 0 1 | 0 1 0 1 - // 0 1 1 0 | 0 0 1 1 - // 0 1 1 1 | 0 1 1 1 - // 1 0 0 0 | 1 0 0 0 - // 1 0 0 1 | 1 1 0 0 - // 1 0 1 0 | 1 0 1 0 - // 1 0 1 1 | 1 1 1 0 - // 1 1 0 0 | 1 0 0 1 - // 1 1 0 1 | 1 1 0 1 - // 1 1 1 0 | 1 0 1 1 - // 1 1 1 1 | 1 1 1 1 - - if ( color < 16 ) - { - static const int lookup_table[] = - { - 0, 4, 2, 6, 1, 5, 3, 7, - 8, 12, 10, 14, 9, 13, 11, 15 - }; - color = lookup_table[color]; - } - return color; -} - -//---------------------------------------------------------------------- -void FTerm::setTermColor (register int fg, register int bg) -{ - char* color_str; - char* AF = tcap[t_set_a_foreground].string; - char* AB = tcap[t_set_a_background].string; - char* Sf = tcap[t_set_foreground].string; - 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); - int ansi_bg = vga2ansi(bg); - - if ( cygwin_terminal ) - { - appendOutputBuffer ("\033[m"); - - color_str = tparm(AF, ansi_fg); - if ( color_str ) - appendOutputBuffer (color_str); - - color_str = tparm(AB, ansi_bg); - if ( color_str ) - appendOutputBuffer (color_str); - } - else - { - if ( fg_term_color != fg && (color_str = tparm(AF, ansi_fg)) ) - appendOutputBuffer (color_str); - - if ( bg_term_color != bg && (color_str = tparm(AB, ansi_bg)) ) - appendOutputBuffer (color_str); - } - } - else if ( Sf && Sb ) - { - if ( fg_term_color != fg && (color_str = tparm(Sf, fg)) ) - appendOutputBuffer (color_str); - - if ( bg_term_color != bg && (color_str = tparm(Sb, bg)) ) - appendOutputBuffer (color_str); - } - else if ( sp ) - { - fg = vga2ansi(fg); - bg = vga2ansi(bg); - - if ( (color_str = tparm(sp, fg, bg)) ) - appendOutputBuffer (color_str); - } - - fg_term_color = fg; - bg_term_color = bg; -} - //---------------------------------------------------------------------- void FTerm::xtermMouse (bool on) { @@ -3234,12 +3316,15 @@ void FTerm::setTermXY (register int x, register int y) y = term_height - 1; if ( cursor_optimisation ) - move_str = opti->cursor_move (x_term_pos, y_term_pos, x, y); + move_str = opti_move->cursor_move (x_term_pos, y_term_pos, x, y); else move_str = tgoto(tcap[t_cursor_address].string, x, y); + if ( move_str ) appendOutputBuffer(move_str); + flush_out(); + x_term_pos = x; y_term_pos = y; } @@ -3280,225 +3365,6 @@ void FTerm::beep() } } -//---------------------------------------------------------------------- -bool FTerm::setTermBold (bool on) -{ - if ( on == term_bold ) - return term_bold; - - if ( on ) - { - char* md = tcap[t_enter_bold_mode].string; - if ( md ) - appendOutputBuffer (md); - term_bold = true; - } - else - { - char* me = tcap[t_exit_attribute_mode].string; - if ( me ) - { - char* ue = tcap[t_exit_underline_mode].string; - 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); - - // 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); - // reverse mode restore - if ( term_reverse && me && mr ) - appendOutputBuffer (mr); - } - term_bold = false; - } - return term_bold; -} - -//---------------------------------------------------------------------- -bool FTerm::setTermDim (bool on) -{ - if ( on == term_dim ) - return term_dim; - - if ( on ) - { - char* mh = tcap[t_enter_dim_mode].string; - if ( mh ) - appendOutputBuffer (mh); - term_dim = true; - } - else - { - char* me = tcap[t_exit_attribute_mode].string; - if ( me ) - { - char* se = tcap[t_exit_standout_mode].string; - char* ue = tcap[t_exit_underline_mode].string; - char* us = tcap[t_enter_underline_mode].string; - char* mr = tcap[t_enter_reverse_mode].string; - char* md = tcap[t_enter_bold_mode].string; - - // "t_exit_attribute_mode" will reset all attributes! - appendOutputBuffer (me); - - // 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); - // reverse mode restore - if ( term_reverse && me && mr ) - appendOutputBuffer (mr); - // bold mode restore - if ( term_bold && md && se ) - appendOutputBuffer (md); - } - term_dim = false; - } - return term_dim; -} - -//---------------------------------------------------------------------- -bool FTerm::setTermItalic (bool on) -{ - if ( on == term_italic ) - return term_italic; - - if ( on ) - { - char* ZH = tcap[t_enter_italics_mode].string; - if ( ZH ) - appendOutputBuffer (ZH); - term_italic = true; - } - else - { - char* ZR = tcap[t_exit_italics_mode].string; - - if ( ZR ) - appendOutputBuffer (ZR); - - term_italic = false; - } - return term_italic; -} - -//---------------------------------------------------------------------- -bool FTerm::setTermReverse (bool on) -{ - if ( on == term_reverse ) - return term_reverse; - - if ( on ) - { - char* mr = tcap[t_enter_reverse_mode].string; - if ( mr ) - appendOutputBuffer (mr); - term_reverse = true; - } - else - { - char* se = tcap[t_exit_standout_mode].string; - if ( se ) - { - char* ue = tcap[t_exit_underline_mode].string; - 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); - } - term_reverse = false; - } - return term_reverse; -} - -//---------------------------------------------------------------------- -bool FTerm::setTermUnderline (bool on) -{ - if ( linux_terminal || cygwin_terminal ) - return false; - - if ( on == term_underline ) - return term_underline; - - if ( on ) - { - char* us = tcap[t_enter_underline_mode].string; - if ( us ) - appendOutputBuffer (us); - term_underline = true; - } - else - { - char* ue = tcap[t_exit_underline_mode].string; - if ( ue ) - { - char* se = tcap[t_exit_standout_mode].string; - char* mr = tcap[t_enter_reverse_mode].string; - char* md = tcap[t_enter_bold_mode].string; - - appendOutputBuffer (ue); - - 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; - } - return term_underline; -} - //---------------------------------------------------------------------- bool FTerm::hideCursor (bool on) { @@ -3572,12 +3438,12 @@ void FTerm::setEncoding (std::string enc) case fc::UTF8: Fputchar = &FTerm::putchar_UTF8; break; + case fc::VT100: - Fputchar = &FTerm::putchar_VT100; - break; case fc::PC: - Fputchar = &FTerm::putchar_PC; - break; + if ( xterm && utf8_console ) + Fputchar = &FTerm::putchar_UTF8; + // fall through case fc::ASCII: default: Fputchar = &FTerm::putchar_ASCII; @@ -3597,37 +3463,6 @@ std::string FTerm::getEncoding() return ""; } -//---------------------------------------------------------------------- -bool FTerm::setPCcharset (bool on) -{ - // display all CP437/VGA characters [00...ff] - if ( on == pc_charset_state ) - return pc_charset_state; - - if ( on ) - { - if ( linux_terminal ) // man 4 console_codes - putstring ("\033%@\033(U"); - else if ( tcap[t_enter_alt_charset_mode].string ) - putstring (tcap[t_enter_alt_charset_mode].string); - else - return pc_charset_state; - pc_charset_state = true; - } - else - { - if ( linux_terminal ) - putstring ("\033(B"); - else if ( tcap[t_exit_alt_charset_mode].string ) - putstring (tcap[t_exit_alt_charset_mode].string); - else - return pc_charset_state; - pc_charset_state = false; - } - fflush(stdout); - return pc_charset_state; -} - //---------------------------------------------------------------------- bool FTerm::setNonBlockingInput (bool on) { @@ -3649,28 +3484,6 @@ bool FTerm::setNonBlockingInput (bool on) return non_blocking_stdin; } -//---------------------------------------------------------------------- -bool FTerm::setVT100altChar (bool on) -{ - if ( on == vt100_state ) - return vt100_state; - - if ( on && tcap[t_enter_alt_charset_mode].string ) - { - appendOutputBuffer (tcap[t_enter_alt_charset_mode].string); - ignore_vt100_state = true; - vt100_state = true; - } - else if ( tcap[t_exit_alt_charset_mode].string ) - { - appendOutputBuffer (tcap[t_exit_alt_charset_mode].string); - ignore_vt100_state = false; - vt100_state = false; - } - flush_out(); - return vt100_state; -} - //---------------------------------------------------------------------- bool FTerm::setUTF8 (bool on) // UTF-8 (Unicode) { @@ -3975,6 +3788,7 @@ int FTerm::print (FTerm::term_area* area, FString& s) { case '\n': cursor->y_ref()++; + case '\r': cursor->x_ref() = 1; break; @@ -4000,15 +3814,23 @@ int FTerm::print (FTerm::term_area* area, FString& s) short x = short(cursor->getX()); short y = short(cursor->getY()); - char_data nc; // new character - nc.code = *p; - nc.fg_color = uChar(fg_color); - nc.bg_color = uChar(bg_color); - nc.bold = bold; - nc.dim = dim; - nc.italic = italic; - nc.reverse = reverse; - nc.underline = underline; + char_data nc; // next character + nc.code = *p; + nc.fg_color = next_attribute.fg_color; + nc.bg_color = next_attribute.bg_color; + nc.bold = next_attribute.bold; + nc.dim = next_attribute.dim; + nc.italic = next_attribute.italic; + nc.underline = next_attribute.underline; + nc.blink = next_attribute.blink; + nc.reverse = next_attribute.reverse; + nc.standout = next_attribute.standout; + nc.invisible = next_attribute.invisible; + nc.protect = next_attribute.protect; + nc.crossed_out = next_attribute.crossed_out; + nc.dbl_underline = next_attribute.dbl_underline; + nc.alt_charset = next_attribute.alt_charset; + nc.pc_charset = next_attribute.pc_charset; int ax = x - area_widget->getGlobalX(); int ay = y - area_widget->getGlobalY(); @@ -4019,29 +3841,10 @@ int FTerm::print (FTerm::term_area* area, FString& s) && ay < area->height + area->bottom_shadow ) { char_data* ac; // area character - uChar ac_attr, nc_attr; - uInt ac_color, nc_color; int line_len = area->width + area->right_shadow; ac = &area->text[ay * line_len + ax]; - ac_color = ac->fg_color | ac->bg_color << 8; - nc_color = nc.fg_color | nc.bg_color << 8; - - ac_attr = ac->bold - | ac->reverse << 1 - | ac->dim << 2 - | ac->italic << 3 - | ac->underline << 4; - - nc_attr = nc.bold - | nc.reverse << 1 - | nc.dim << 2 - | nc.italic << 3 - | nc.underline << 4; - - if ( (ac->code != nc.code) - || ac_color!= nc_color - || ac_attr != nc_attr ) + if ( *ac != nc ) { memcpy (ac, &nc, sizeof(nc)); @@ -4097,7 +3900,7 @@ int FTerm::print (register int c) //---------------------------------------------------------------------- int FTerm::print (FTerm::term_area* area, register int c) { - char_data nc; // new character + char_data nc; // next character FWidget* area_widget; int rsh, bsh, ax, ay; short x, y; @@ -4105,14 +3908,22 @@ int FTerm::print (FTerm::term_area* area, register int c) if ( ! area ) return -1; - nc.code = c; - nc.fg_color = uChar(fg_color); - nc.bg_color = uChar(bg_color); - nc.bold = bold; - nc.dim = dim; - nc.italic = italic; - nc.reverse = reverse; - nc.underline = underline; + nc.code = c; + nc.fg_color = next_attribute.fg_color; + nc.bg_color = next_attribute.bg_color; + nc.bold = next_attribute.bold; + nc.dim = next_attribute.dim; + nc.italic = next_attribute.italic; + nc.underline = next_attribute.underline; + nc.blink = next_attribute.blink; + nc.reverse = next_attribute.reverse; + nc.standout = next_attribute.standout; + nc.invisible = next_attribute.invisible; + nc.protect = next_attribute.protect; + nc.crossed_out = next_attribute.crossed_out; + nc.dbl_underline = next_attribute.dbl_underline; + nc.alt_charset = next_attribute.alt_charset; + nc.pc_charset = next_attribute.pc_charset; x = short(cursor->getX()); y = short(cursor->getY()); @@ -4129,30 +3940,10 @@ int FTerm::print (FTerm::term_area* area, register int c) && ay < area->height + area->bottom_shadow ) { char_data* ac; // area character - uChar ac_attr, nc_attr; - uInt ac_color, nc_color; - int line_len = area->width + area->right_shadow; ac = &area->text[ay * line_len + ax]; - ac_color = ac->fg_color | ac->bg_color << 8; - nc_color = nc.fg_color | nc.bg_color << 8; - - ac_attr = ac->bold - | ac->reverse << 1 - | ac->dim << 2 - | ac->italic << 3 - | ac->underline << 4; - - nc_attr = nc.bold - | nc.reverse << 1 - | nc.dim << 2 - | nc.italic << 3 - | nc.underline << 4; - - if ( (ac->code != nc.code) - || ac_color != nc_color - || ac_attr != nc_attr ) + if ( *ac != nc ) { memcpy (ac, &nc, sizeof(nc)); @@ -4184,41 +3975,15 @@ int FTerm::print (FTerm::term_area* area, register int c) } //---------------------------------------------------------------------- -inline void FTerm::appendCharacter (char_data*& screen_char) +inline void FTerm::newFontChanges (char_data*& next_char) { - appendAttributes (screen_char); - appendOutputBuffer (screen_char->code); -} - -//---------------------------------------------------------------------- -void FTerm::appendAttributes (char_data*& screen_attr) -{ - if ( screen_attr->fg_color != fg_term_color - || screen_attr->bg_color != bg_term_color ) - setTermColor ( screen_attr->fg_color, - screen_attr->bg_color ); - - if ( bool(screen_attr->bold) != term_bold ) - setTermBold (bool(screen_attr->bold)); - - if ( bool(screen_attr->dim) != term_dim ) - setTermDim (bool(screen_attr->dim)); - - if ( bool(screen_attr->italic) != term_italic ) - setTermItalic (bool(screen_attr->italic)); - - if ( bool(screen_attr->reverse) != term_reverse ) - setTermReverse (bool(screen_attr->reverse)); - - if ( bool(screen_attr->underline) != term_underline ) - setTermUnderline (bool(screen_attr->underline)); - + // NewFont special cases if ( isNewFont() ) { - switch ( screen_attr->code ) + switch ( next_char->code ) { case fc::LowerHalfBlock: - screen_attr->code = fc::UpperHalfBlock; + next_char->code = fc::UpperHalfBlock; // fall through case fc::NF_rev_left_arrow2: case fc::NF_rev_right_arrow2: @@ -4240,7 +4005,8 @@ void FTerm::appendAttributes (char_data*& screen_attr) case fc::NF_rev_down_pointing_triangle2: case fc::NF_rev_menu_button3: case fc::NF_rev_border_line_right_and_left: - setTermColor (screen_attr->bg_color, screen_attr->fg_color); + // swap foreground and background color + std::swap (next_char->fg_color, next_char->bg_color); break; default: @@ -4249,6 +4015,59 @@ void FTerm::appendAttributes (char_data*& screen_attr) } } +//---------------------------------------------------------------------- +inline void FTerm::charsetChanges (char_data*& next_char) +{ + if ( Encoding == fc::UTF8 ) + return; + + uInt code = uInt(next_char->code); + uInt ch = charEncode(code); + + if ( ch != code ) + { + if ( ch == 0 ) + { + next_char->code = int(charEncode(code, fc::ASCII)); + return; + } + next_char->code = int(ch); + + if ( Encoding == fc::VT100 ) + next_char->alt_charset = true; + else if ( Encoding == fc::PC ) + { + next_char->pc_charset = true; + + if ( xterm && utf8_console && ch < 0x20 ) // Character 0x00..0x1f + next_char->code = int(charEncode(code, fc::ASCII)); + } + } +} + +//---------------------------------------------------------------------- +inline void FTerm::appendCharacter (char_data*& next_char) +{ + newFontChanges (next_char); + charsetChanges (next_char); + + appendAttributes (next_char); + appendOutputBuffer (next_char->code); +} + +//---------------------------------------------------------------------- +inline void FTerm::appendAttributes (char_data*& next_attr) +{ + char* attr_str; + char_data* term_attr = &term_attribute; + + // generate attribute string for the next character + attr_str = opti_attr->change_attribute (term_attr, next_attr); + + if ( attr_str ) + appendOutputBuffer (attr_str); +} + //---------------------------------------------------------------------- int FTerm::appendLowerRight (char_data*& screen_char) { @@ -4365,97 +4184,7 @@ inline void FTerm::putstring (const char* s, int affcnt) //---------------------------------------------------------------------- int FTerm::putchar_ASCII (register int c) { - register char ch; - if ( c >> 7 ) // more than 7-bit - ch = char(charEncode(uInt(c))); - else - ch = char(c); - if ( putchar(ch) == EOF ) - return 0; - else - return 1; -} - -//---------------------------------------------------------------------- -int FTerm::putchar_VT100 (register int c) -{ - register uChar ch; - ch = uChar(charEncode(uInt(c))); - if ( ch != 0 && (c >> 7) ) // vt100 alternate character set - { - if ( ! vt100_state - && tcap[t_enter_alt_charset_mode].string - && ! ignore_vt100_state ) - { - putstring (tcap[t_enter_alt_charset_mode].string); - vt100_state = true; - } - if ( putchar(ch) == EOF ) - return 0; - else - return 1; - } - else // ascii - { - if ( vt100_state - && tcap[t_exit_alt_charset_mode].string - && ! ignore_vt100_state ) - { - putstring (tcap[t_exit_alt_charset_mode].string); - vt100_state = false; - } - if ( c >> 7 ) // more than 7-bit - { - Encoding = fc::ASCII; - ch = uChar(charEncode(uInt(c))); - Encoding = fc::VT100; - } - else - ch = uChar(c); - if ( putchar(ch) == EOF ) - return 0; - else - return 1; - } -} - -//---------------------------------------------------------------------- -int FTerm::putchar_PC (register int c) -{ - register char ch; - register int ret; - - if ( c >> 7 ) // more than 7-bit - { - ch = char(charEncode(uInt(c))); - // IBM PC alternate character set on - putstring (tcap[t_enter_pc_charset_mode].string); - } - else - ch = char(c); - - if ( xterm && utf8_console ) - { - if ( uChar(ch) < 0x20 ) // Character 0x00..0x1f - { - Encoding = fc::ASCII; - ch = char(charEncode(uInt(c))); - Encoding = fc::PC; - ret = putchar(ch); - } - else - ret = putchar_UTF8(ch & 0xff); - } - else - ret = putchar(ch); - - if ( c >> 7 ) - { - // IBM PC alternate character set off - putstring (tcap[t_exit_pc_charset_mode].string); - } - - if ( ret == EOF ) + if ( putchar(char(c)) == EOF ) return 0; else return 1; diff --git a/src/fterm.h b/src/fterm.h index 0ba606fe..c1cfe4c9 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -8,6 +8,10 @@ // ▕ FTerm ▏-┬- - - -▕ FOptiMove ▏ // ▕▁▁▁▁▁▁▁▏ : ▕▁▁▁▁▁▁▁▁▁▁▁▏ // : +// : 1▕▔▔▔▔▔▔▔▔▔▔▔▏ +// :- - - -▕ FOptiAttr ▏ +// : ▕▁▁▁▁▁▁▁▁▁▁▁▏ +// : // : *▕▔▔▔▔▔▔▔▔▔▏ // :- - - -▕ FString ▏ // : ▕▁▁▁▁▁▁▁▁▁▏ @@ -54,6 +58,7 @@ #include "fenum.h" #include "fobject.h" +#include "foptiattr.h" #include "foptimove.h" #include "fpoint.h" #include "frect.h" @@ -90,22 +95,14 @@ class FTerm static std::map * vt100_alt_char; static std::map * encoding_set; - static bool term_bold; - static bool term_dim; - static bool term_italic; - static bool term_reverse; - static bool term_underline; static bool hiddenCursor; static bool mouse_support; - static bool vt100_state; - static bool ignore_vt100_state; static bool raw_mode; static bool input_data_pending; static bool terminal_update_pending; static bool force_terminal_update; static bool non_blocking_stdin; static bool gpm_mouse_enabled; - static bool pc_charset_state; static bool pc_charset_console; static bool utf8_input; static bool utf8_state; @@ -132,7 +129,6 @@ 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; @@ -151,25 +147,27 @@ class FTerm static int max_color; static int fd_tty; static uInt baudrate; - static int fg_color; - static int bg_color; - static int fg_term_color; - static int bg_term_color; static int x_term_pos; static int y_term_pos; static bool resize_term; static struct termios term_init; + static FOptiAttr::char_data term_attribute; + static FOptiAttr::char_data next_attribute; static fc::console_cursor_style consoleCursorStyle; static struct console_font_op screenFont; static struct unimapdesc screenUnicodeMap; - static FOptiMove* opti; + + static FOptiMove* opti_move; + static FOptiAttr* opti_attr; static const FString* xterm_font; static const FString* xterm_title; static const FString* AnswerBack; static const FString* Sec_DA; + typedef FOptiAttr::char_data char_data; + typedef struct { uChar red; @@ -183,15 +181,11 @@ class FTerm } map; protected: - static bool bold; - static bool dim; - static bool italic; - static bool reverse; - static bool underline; static bool NewFont; static bool VGAFont; static bool cursor_optimisation; static uInt tabstop; + static uInt attr_without_color; static fc::encoding Encoding; typedef struct @@ -200,19 +194,6 @@ class FTerm uInt xmax; } line_changes; - typedef struct - { - int code; // character code - uChar fg_color; // foreground color - uChar bg_color; // background color - uChar bold : 1; // bold - uChar dim : 1; // dim - uChar italic : 1; // italic - uChar reverse : 1; // reverse - uChar underline : 1; // underline - uChar : 3; // padding bits - } char_data; - typedef struct { int width; @@ -254,17 +235,20 @@ class FTerm static char* parseAnswerbackMsg (char*&); static char* parseSecDA (char*&); static void init_termcaps(); - static void init_vt100altChar(); + static void init_alt_charset(); + static void init_pc_charset(); static void init_encoding(); void init(); void finish(); static uInt charEncode (uInt); + static uInt charEncode (uInt, fc::encoding); static uInt cp437_to_unicode (uChar); static void signal_handler (int); friend class FWidget; friend class FApplication; protected: + static bool charEncodable (uInt); void createArea (FTerm::term_area*&); // reference to pointer void resizeArea (FTerm::term_area*); void restoreVTerm (const FRect&); @@ -283,7 +267,7 @@ class FTerm char_data getCoveredCharacter (int, int, FTerm*); public: - FTerm (); // constructor + FTerm (); // constructor virtual ~FTerm(); // destructor virtual const char* getClassName() const; @@ -336,12 +320,9 @@ class FTerm static void resetXTermHighlightBackground(); static void saveColorMap(); static void resetColorMap(); - static void setPalette (int, int, int, int); - static int vga2ansi (int); - void setColor (int, int); - static void setTermColor (int, int); - static int getTermForegroundColor(); - static int getTermBackgroundColor(); + static void setPalette (short, int, int, int); + static short getTermForegroundColor(); + static short getTermBackgroundColor(); static int getMaxColor(); static void xtermMouse (bool); static void enableXTermMouse(); @@ -358,12 +339,6 @@ class FTerm static void resetBeep(); static void beep(); - static bool setTermBold (bool); - static bool setTermDim (bool); - static bool setTermItalic (bool); - static bool setTermReverse (bool); - static bool setTermUnderline (bool); - static bool hideCursor (bool); static bool hideCursor(); static bool showCursor(); @@ -373,20 +348,10 @@ class FTerm static void setEncoding (std::string); static std::string getEncoding(); - static bool setPCcharset (bool); - static bool setPCcharset(); - static bool unsetPCcharset(); - static bool isPCcharset(); - static bool setNonBlockingInput (bool); static bool setNonBlockingInput(); static bool unsetNonBlockingInput(); - static bool setVT100altChar (bool); - static bool setVT100altChar(); - static bool unsetVT100altChar(); - static bool isVT100altChar(); - static bool setUTF8 (bool); static bool setUTF8(); static bool unsetUTF8(); @@ -421,6 +386,8 @@ class FTerm int print (FTerm::term_area*, FString&); int print (int); int print (FTerm::term_area*, int); + static void newFontChanges (char_data*&); + static void charsetChanges (char_data*&); static void appendCharacter (char_data*&); static void appendAttributes (char_data*&); static int appendLowerRight (char_data*&); @@ -438,8 +405,6 @@ class FTerm ; static void putstring (const char*, int = 1); static int putchar_ASCII (register int); - static int putchar_VT100 (register int); - static int putchar_PC (register int); static int putchar_UTF8 (register int); static int UTF8decode (char*); }; @@ -553,12 +518,12 @@ inline bool FTerm::isRaw() { return raw_mode; } //---------------------------------------------------------------------- -inline int FTerm::getTermForegroundColor() -{ return fg_color; } +inline short FTerm::getTermForegroundColor() +{ return next_attribute.fg_color; } //---------------------------------------------------------------------- -inline int FTerm::getTermBackgroundColor() -{ return bg_color; } +inline short FTerm::getTermBackgroundColor() +{ return next_attribute.bg_color; } //---------------------------------------------------------------------- inline int FTerm::getMaxColor() @@ -592,18 +557,6 @@ inline bool FTerm::hideCursor() inline bool FTerm::showCursor() { return hideCursor(false); } -//---------------------------------------------------------------------- -inline bool FTerm::setPCcharset() -{ return setPCcharset(true); } - -//---------------------------------------------------------------------- -inline bool FTerm::unsetPCcharset() -{ return setPCcharset(false); } - -//---------------------------------------------------------------------- -inline bool FTerm::isPCcharset() -{ return pc_charset_state; } - //---------------------------------------------------------------------- inline bool FTerm::setNonBlockingInput() { return setNonBlockingInput(true); } @@ -612,18 +565,6 @@ inline bool FTerm::setNonBlockingInput() inline bool FTerm::unsetNonBlockingInput() { return setNonBlockingInput(false); } -//---------------------------------------------------------------------- -inline bool FTerm::setVT100altChar() -{ return setVT100altChar(true); } - -//---------------------------------------------------------------------- -inline bool FTerm::unsetVT100altChar() -{ return setVT100altChar(false); } - -//---------------------------------------------------------------------- -inline bool FTerm::isVT100altChar() -{ return vt100_state; } - //---------------------------------------------------------------------- inline bool FTerm::setUTF8() { return setUTF8(true); } diff --git a/src/ftextview.cpp b/src/ftextview.cpp index afa56d28..8471ad01 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -126,10 +126,20 @@ void FTextView::drawText() uInt len = line.getLength(); for (i=0; i < len; i++) - if ( wcwidth(line_str[i]) == 1 ) // only 1 column per character - print (line_str[i]); + { + wchar_t ch = line_str[i]; + bool utf8 = (Encoding == fc::UTF8) ? true : false; + + // only printable and 1 column per character + if ( ( (utf8 && iswprint(wint_t(ch))) + || (!utf8 && ch < 256 && isprint(ch)) ) + && wcwidth(ch) == 1 ) + { + print (ch); + } else print ('.'); + } for (; i < uInt(width - nf_offset - 2); i++) print (' '); } @@ -180,7 +190,8 @@ void FTextView::adjustSize() //---------------------------------------------------------------------- void FTextView::hide() { - int fg, bg, n, size; + int n, size; + short fg, bg; char* blank; FWidget::hide(); diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 6bf91899..30420ff3 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -226,9 +226,9 @@ void FToggleButton::drawLabel() setReverse(true); if ( isEnabled() ) - setColor(wc.label_fg, wc.label_bg); + setColor (wc.label_fg, wc.label_bg); else - setColor(wc.label_inactive_fg, wc.label_inactive_bg); + setColor (wc.label_inactive_fg, wc.label_inactive_bg); for (int z=0; z < int(length); z++) { @@ -346,7 +346,8 @@ void FToggleButton::onKeyPress (FKeyEvent* ev) //---------------------------------------------------------------------- void FToggleButton::hide() { - int fg, bg, size; + int size; + short fg, bg; char* blank; FWidget::hide(); diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 971961cf..6a7e19aa 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1134,13 +1134,23 @@ void FWidget::redraw() if ( isRootWidget() ) { // draw windows - char_data default_char; - default_char.code = ' '; - default_char.fg_color = fc::Black; - default_char.bg_color = fc::Black; - default_char.bold = 0; - default_char.reverse = 0; - default_char.underline = 0; + FOptiAttr::char_data default_char; + default_char.code = ' '; + default_char.fg_color = fc::Black; + default_char.bg_color = fc::Black; + default_char.bold = 0; + default_char.dim = 0; + default_char.italic = 0; + default_char.underline = 0; + default_char.blink = 0; + default_char.reverse = 0; + default_char.standout = 0; + default_char.invisible = 0; + default_char.protect = 0; + default_char.crossed_out = 0; + default_char.dbl_underline = 0; + default_char.alt_charset = 0; + default_char.pc_charset = 0; if ( window_list && ! window_list->empty() ) { @@ -1451,6 +1461,14 @@ bool FWidget::setFocus(bool on) return focus = (on) ? true : false; } +//---------------------------------------------------------------------- +void FWidget::setColor (register short fg, register short bg) +{ + // Changes colors + next_attribute.fg_color = fg; + next_attribute.bg_color = bg; +} + //---------------------------------------------------------------------- void FWidget::setX (int x, bool adjust) { @@ -1739,14 +1757,24 @@ void FWidget::clrscr() { term_area* area; FWindow* area_widget; - char_data default_char; + FOptiAttr::char_data default_char; - default_char.code = ' '; - default_char.fg_color = uChar(fg_color); - default_char.bg_color = uChar(bg_color); - default_char.bold = bold; - default_char.reverse = reverse; - default_char.underline = underline; + default_char.code = ' '; + default_char.fg_color = next_attribute.fg_color; + default_char.bg_color = next_attribute.bg_color; + default_char.bold = next_attribute.bold; + default_char.dim = next_attribute.dim; + default_char.italic = next_attribute.italic; + default_char.underline = next_attribute.underline; + default_char.blink = next_attribute.blink; + default_char.reverse = next_attribute.reverse; + default_char.standout = next_attribute.standout; + default_char.invisible = next_attribute.invisible; + default_char.protect = next_attribute.protect; + default_char.crossed_out = next_attribute.crossed_out; + default_char.dbl_underline = next_attribute.dbl_underline; + default_char.alt_charset = next_attribute.alt_charset; + default_char.pc_charset = next_attribute.pc_charset; area_widget = FWindow::getWindowWidget(this); @@ -1782,7 +1810,7 @@ void FWidget::clrscr() //---------------------------------------------------------------------- void FWidget::drawShadow() { - FTerm::char_data ch; + FOptiAttr::char_data ch; int x1, x2, y1, y2; bool trans_shadow = ((flags & TRANS_SHADOW) != 0); @@ -1812,18 +1840,37 @@ void FWidget::drawShadow() { ch = getCoveredCharacter (x2+x, y1, this); setColor (ch.fg_color, ch.bg_color); - if ( ch.reverse ) - setReverse(true); + if ( ch.bold ) - setBold(true); + setBold (true); + if ( ch.dim ) + setDim (true); + if ( ch.italic ) + setItalic (true); if ( ch.underline ) - setUnderline(true); + setUnderline (true); + if ( ch.blink ) + setBlink (true); + if ( ch.reverse ) + setReverse (true); + if ( ch.standout ) + setStandout (true); + if ( ch.invisible ) + setInvisible (true); + if ( ch.protect ) + setProtected (true); + if ( ch.crossed_out ) + setCrossedOut (true); + if ( ch.dbl_underline ) + setDoubleUnderline (true); + if ( ch.alt_charset ) + setAltCharset (true); + if ( ch.pc_charset ) + setPCcharset (true); print (ch.code); - setReverse(false); - setBold(false); - setUnderline(false); + setNormal(); } setColor (wc.shadow_bg, wc.shadow_fg); @@ -1852,18 +1899,37 @@ void FWidget::drawShadow() { ch = getCoveredCharacter (x1+x, y2+1, this); setColor (ch.fg_color, ch.bg_color); - if ( ch.reverse ) - setReverse(true); + if ( ch.bold ) - setBold(true); + setBold (true); + if ( ch.dim ) + setDim (true); + if ( ch.italic ) + setItalic (true); if ( ch.underline ) - setUnderline(true); + setUnderline (true); + if ( ch.blink ) + setBlink (true); + if ( ch.reverse ) + setReverse (true); + if ( ch.standout ) + setStandout (true); + if ( ch.invisible ) + setInvisible (true); + if ( ch.protect ) + setProtected (true); + if ( ch.crossed_out ) + setCrossedOut (true); + if ( ch.dbl_underline ) + setDoubleUnderline (true); + if ( ch.alt_charset ) + setAltCharset (true); + if ( ch.pc_charset ) + setPCcharset (true); print (ch.code); - setReverse(false); - setBold(false); - setUnderline(false); + setNormal(); } setColor (wc.shadow_bg, wc.shadow_fg); @@ -1916,7 +1982,7 @@ void FWidget::drawShadow() for (int i=1; i <= width && x1+i <= xmax; i++) { ch = getCoveredCharacter (x1+i, y2+1, this); - setColor(wc.shadow_fg, ch.bg_color); + setColor (wc.shadow_fg, ch.bg_color); if ( isTeraTerm() ) print (0xdf); // ▀ else @@ -1929,7 +1995,7 @@ void FWidget::drawShadow() //---------------------------------------------------------------------- void FWidget::clearShadow() { - FTerm::char_data ch; + FOptiAttr::char_data ch; int x1, x2, y1, y2; if ( isMonochron() ) diff --git a/src/fwidget.h b/src/fwidget.h index 4e8b64e6..0340df3f 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -141,85 +141,85 @@ class FWidget : public FObject, public FTerm static struct widget_colors { - uChar term_fg; - uChar term_bg; - uChar list_fg; - uChar list_bg; - uChar selected_list_fg; - uChar selected_list_bg; - uChar current_element_focus_fg; - uChar current_element_focus_bg; - uChar current_element_fg; - uChar current_element_bg; - uChar current_inc_search_element_fg; - uChar selected_current_element_focus_fg; - uChar selected_current_element_focus_bg; - uChar selected_current_element_fg; - uChar selected_current_element_bg; - uChar label_fg; - uChar label_bg; - uChar label_inactive_fg; - uChar label_inactive_bg; - uChar label_hotkey_fg; - uChar label_hotkey_bg; - uChar label_emphasis_fg; - uChar label_ellipsis_fg; - uChar inputfield_active_focus_fg; - uChar inputfield_active_focus_bg; - uChar inputfield_active_fg; - uChar inputfield_active_bg; - uChar inputfield_inactive_fg; - uChar inputfield_inactive_bg; - uChar dialog_fg; - uChar dialog_emphasis_fg; - uChar dialog_bg; - uChar error_box_fg; - uChar error_box_emphasis_fg; - uChar error_box_bg; - uChar shadow_fg; - uChar shadow_bg; - uChar toggle_button_active_focus_fg; - uChar toggle_button_active_focus_bg; - uChar toggle_button_active_fg; - uChar toggle_button_active_bg; - uChar toggle_button_inactive_fg; - uChar toggle_button_inactive_bg; - uChar button_active_focus_fg; - uChar button_active_focus_bg; - uChar button_active_fg; - uChar button_active_bg; - uChar button_inactive_fg; - uChar button_inactive_bg; - uChar button_hotkey_fg; - uChar titlebar_active_fg; - uChar titlebar_active_bg; - uChar titlebar_inactive_fg; - uChar titlebar_inactive_bg; - uChar titlebar_button_fg; - uChar titlebar_button_bg; - uChar menu_active_focus_fg; - uChar menu_active_focus_bg; - uChar menu_active_fg; - uChar menu_active_bg; - uChar menu_inactive_fg; - uChar menu_inactive_bg; - uChar menu_hotkey_fg; - uChar menu_hotkey_bg; - uChar statusbar_fg; - uChar statusbar_bg; - uChar statusbar_hotkey_fg; - uChar statusbar_hotkey_bg; - uChar statusbar_separator_fg; - uChar statusbar_active_fg; - uChar statusbar_active_bg; - uChar statusbar_active_hotkey_fg; - uChar statusbar_active_hotkey_bg; - uChar scrollbar_fg; - uChar scrollbar_bg; - uChar scrollbar_button_fg; - uChar scrollbar_button_bg; - uChar progressbar_fg; - uChar progressbar_bg; + short term_fg; + short term_bg; + short list_fg; + short list_bg; + short selected_list_fg; + short selected_list_bg; + short current_element_focus_fg; + short current_element_focus_bg; + short current_element_fg; + short current_element_bg; + short current_inc_search_element_fg; + short selected_current_element_focus_fg; + short selected_current_element_focus_bg; + short selected_current_element_fg; + short selected_current_element_bg; + short label_fg; + short label_bg; + short label_inactive_fg; + short label_inactive_bg; + short label_hotkey_fg; + short label_hotkey_bg; + short label_emphasis_fg; + short label_ellipsis_fg; + short inputfield_active_focus_fg; + short inputfield_active_focus_bg; + short inputfield_active_fg; + short inputfield_active_bg; + short inputfield_inactive_fg; + short inputfield_inactive_bg; + short dialog_fg; + short dialog_emphasis_fg; + short dialog_bg; + short error_box_fg; + short error_box_emphasis_fg; + short error_box_bg; + short shadow_fg; + short shadow_bg; + short toggle_button_active_focus_fg; + short toggle_button_active_focus_bg; + short toggle_button_active_fg; + short toggle_button_active_bg; + short toggle_button_inactive_fg; + short toggle_button_inactive_bg; + short button_active_focus_fg; + short button_active_focus_bg; + short button_active_fg; + short button_active_bg; + short button_inactive_fg; + short button_inactive_bg; + short button_hotkey_fg; + short titlebar_active_fg; + short titlebar_active_bg; + short titlebar_inactive_fg; + short titlebar_inactive_bg; + short titlebar_button_fg; + short titlebar_button_bg; + short menu_active_focus_fg; + short menu_active_focus_bg; + short menu_active_fg; + short menu_active_bg; + short menu_inactive_fg; + short menu_inactive_bg; + short menu_hotkey_fg; + short menu_hotkey_bg; + short statusbar_fg; + short statusbar_bg; + short statusbar_hotkey_fg; + short statusbar_hotkey_bg; + short statusbar_separator_fg; + short statusbar_active_fg; + short statusbar_active_bg; + short statusbar_active_hotkey_fg; + short statusbar_active_hotkey_bg; + short scrollbar_fg; + short scrollbar_bg; + short scrollbar_button_fg; + short scrollbar_button_bg; + short progressbar_fg; + short progressbar_bg; } wc; // widget_colors wc; @@ -258,8 +258,8 @@ class FWidget : public FObject, public FTerm bool ignore_padding; bool window_object; int flags; - int foregroundColor; - int backgroundColor; + short foregroundColor; + short backgroundColor; static uInt modal_dialogs; private: @@ -396,8 +396,8 @@ class FWidget : public FObject, public FTerm bool ignorePadding(); bool acceptPadding(); - int getForegroundColor() const; - int getBackgroundColor() const; + short getForegroundColor() const; + short getBackgroundColor() const; int getX() const; int getY() const; const FPoint getPos() const; @@ -418,8 +418,9 @@ class FWidget : public FObject, public FTerm const FRect& getGeometryGlobal() const; const FRect& getGeometryGlobalShadow() const; FPoint globalToLocalPos (const FPoint&); - void setForegroundColor (int); - void setBackgroundColor (int); + void setForegroundColor (short); + void setBackgroundColor (short); + void setColor (short, short); void setX (int, bool = true); void setY (int, bool = true); virtual void setPos (const FPoint&, bool = true); @@ -448,6 +449,8 @@ class FWidget : public FObject, public FTerm static void gotoxy (register int, register int); void clrscr(); + static void setNormal(); + static bool setBold (register bool); static bool setBold(); static bool unsetBold(); @@ -463,15 +466,55 @@ class FWidget : public FObject, public FTerm static bool unsetItalic(); static bool isItalic(); + static bool setUnderline (register bool); + static bool setUnderline(); + static bool unsetUnderline(); + static bool isUnderline(); + + static bool setBlink (register bool); + static bool setBlink(); + static bool unsetBlink(); + static bool isBlink(); + static bool setReverse (register bool); static bool setReverse(); static bool unsetReverse(); static bool isReverse(); - static bool setUnderline (register bool); - static bool setUnderline(); - static bool unsetUnderline(); - static bool isUnderline(); + static bool setStandout (register bool); + static bool setStandout(); + static bool unsetStandout(); + static bool isStandout(); + + static bool setInvisible (register bool); + static bool setInvisible(); + static bool unsetInvisible(); + static bool isInvisible(); + + static bool setProtected (register bool); + static bool setProtected(); + static bool unsetProtected(); + static bool isProtected(); + + static bool setCrossedOut (register bool); + static bool setCrossedOut(); + static bool unsetCrossedOut(); + static bool isCrossedOut(); + + static bool setDoubleUnderline (register bool); + static bool setDoubleUnderline(); + static bool unsetDoubleUnderline(); + static bool isDoubleUnderline(); + + static bool setAltCharset (register bool); + static bool setAltCharset(); + static bool unsetAltCharset(); + static bool isAltCharset(); + + static bool setPCcharset (register bool); + static bool setPCcharset(); + static bool unsetPCcharset(); + static bool isPCcharset(); void drawShadow(); void clearShadow(); @@ -601,11 +644,11 @@ inline void FWidget::unsetFocusable() { focusable = false; } //---------------------------------------------------------------------- -inline int FWidget::getForegroundColor() const +inline short FWidget::getForegroundColor() const { return foregroundColor; } //---------------------------------------------------------------------- -inline int FWidget::getBackgroundColor() const +inline short FWidget::getBackgroundColor() const { return backgroundColor; } //---------------------------------------------------------------------- @@ -640,16 +683,16 @@ inline FPoint FWidget::globalToLocalPos (const FPoint& gPos) } //---------------------------------------------------------------------- -inline void FWidget::setForegroundColor (int color) +inline void FWidget::setForegroundColor (short color) { - if ( color >> 8 == 0 ) // valid colors 0..254 + if ( color == -1 || color >> 8 == 0 ) // valid colors -1..254 foregroundColor = color; } //---------------------------------------------------------------------- -inline void FWidget::setBackgroundColor (int color) +inline void FWidget::setBackgroundColor (short color) { - if ( color >> 8 == 0 ) // valid colors 0..254 + if ( color == -1 || color >> 8 == 0 ) // valid colors -1..254 backgroundColor = color; } @@ -747,9 +790,30 @@ inline void FWidget::gotoxy (const FPoint& pos) inline void FWidget::gotoxy (register int x, register int y) { cursor->setPoint(x,y); } +//---------------------------------------------------------------------- +inline void FWidget::setNormal() +{ + next_attribute.bold = \ + next_attribute.dim = \ + next_attribute.italic = \ + next_attribute.underline = \ + next_attribute.blink = \ + next_attribute.reverse = \ + next_attribute.standout = \ + next_attribute.invisible = \ + next_attribute.protect = \ + next_attribute.crossed_out = \ + next_attribute.dbl_underline = \ + next_attribute.alt_charset = \ + next_attribute.pc_charset = false; + + next_attribute.fg_color = -1; + next_attribute.bg_color = -1; +} + //---------------------------------------------------------------------- inline bool FWidget::setBold (register bool on) -{ return (bold = on); } +{ return (next_attribute.bold = on); } //---------------------------------------------------------------------- inline bool FWidget::setBold() @@ -761,11 +825,11 @@ inline bool FWidget::unsetBold() //---------------------------------------------------------------------- inline bool FWidget::isBold() -{ return bold; } +{ return next_attribute.bold; } //---------------------------------------------------------------------- inline bool FWidget::setDim (register bool on) -{ return (dim = on); } +{ return (next_attribute.dim = on); } //---------------------------------------------------------------------- inline bool FWidget::setDim() @@ -777,11 +841,11 @@ inline bool FWidget::unsetDim() //---------------------------------------------------------------------- inline bool FWidget::isDim() -{ return dim; } +{ return next_attribute.dim; } //---------------------------------------------------------------------- inline bool FWidget::setItalic (register bool on) -{ return (italic = on); } +{ return (next_attribute.italic = on); } //---------------------------------------------------------------------- inline bool FWidget::setItalic() @@ -793,27 +857,11 @@ inline bool FWidget::unsetItalic() //---------------------------------------------------------------------- inline bool FWidget::isItalic() -{ return italic; } - -//---------------------------------------------------------------------- -inline bool FWidget::setReverse (register bool on) -{ return (reverse = on); } - -//---------------------------------------------------------------------- -inline bool FWidget::setReverse() -{ return setReverse(true); } - -//---------------------------------------------------------------------- -inline bool FWidget::unsetReverse() -{ return setReverse(false); } - -//---------------------------------------------------------------------- -inline bool FWidget::isReverse() -{ return reverse; } +{ return next_attribute.italic; } //---------------------------------------------------------------------- inline bool FWidget::setUnderline (register bool on) -{ return (underline = on); } +{ return (next_attribute.underline = on); } //---------------------------------------------------------------------- inline bool FWidget::setUnderline() @@ -825,7 +873,151 @@ inline bool FWidget::unsetUnderline() //---------------------------------------------------------------------- inline bool FWidget::isUnderline() -{ return underline; } +{ return next_attribute.underline; } + +//---------------------------------------------------------------------- +inline bool FWidget::setBlink (register bool on) +{ return (next_attribute.blink = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setBlink() +{ return setBlink(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetBlink() +{ return setBlink(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isBlink() +{ return next_attribute.blink; } + +//---------------------------------------------------------------------- +inline bool FWidget::setReverse (register bool on) +{ return (next_attribute.reverse = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setReverse() +{ return setReverse(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetReverse() +{ return setReverse(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isReverse() +{ return next_attribute.reverse; } + +//---------------------------------------------------------------------- +inline bool FWidget::setStandout (register bool on) +{ return (next_attribute.standout = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setStandout() +{ return setStandout(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetStandout() +{ return setStandout(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isStandout() +{ return next_attribute.standout; } + +//---------------------------------------------------------------------- +inline bool FWidget::setInvisible (register bool on) +{ return (next_attribute.invisible = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setInvisible() +{ return setInvisible(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetInvisible() +{ return setInvisible(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isInvisible() +{ return next_attribute.invisible; } + +//---------------------------------------------------------------------- +inline bool FWidget::setProtected (register bool on) +{ return (next_attribute.protect = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setProtected() +{ return setProtected(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetProtected() +{ return setProtected(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isProtected() +{ return next_attribute.protect; } + +//---------------------------------------------------------------------- +inline bool FWidget::setCrossedOut (register bool on) +{ return (next_attribute.crossed_out = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setCrossedOut() +{ return setCrossedOut(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetCrossedOut() +{ return setCrossedOut(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isCrossedOut() +{ return next_attribute.crossed_out; } + +//---------------------------------------------------------------------- +inline bool FWidget::setDoubleUnderline (register bool on) +{ return (next_attribute.dbl_underline = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setDoubleUnderline() +{ return setDoubleUnderline(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetDoubleUnderline() +{ return setDoubleUnderline(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isDoubleUnderline() +{ return next_attribute.dbl_underline; } + +//---------------------------------------------------------------------- +inline bool FWidget::setAltCharset (register bool on) +{ return (next_attribute.alt_charset = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setAltCharset() +{ return setAltCharset(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetAltCharset() +{ return setAltCharset(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isAltCharset() +{ return next_attribute.alt_charset; } + +//---------------------------------------------------------------------- +inline bool FWidget::setPCcharset (register bool on) +{ return (next_attribute.pc_charset = on); } + +//---------------------------------------------------------------------- +inline bool FWidget::setPCcharset() +{ return setPCcharset(true); } + +//---------------------------------------------------------------------- +inline bool FWidget::unsetPCcharset() +{ return setPCcharset(false); } + +//---------------------------------------------------------------------- +inline bool FWidget::isPCcharset() +{ return next_attribute.pc_charset; } //---------------------------------------------------------------------- inline void FWidget::unsetDoubleFlatLine(int side) diff --git a/test/keyboard.cpp b/test/keyboard.cpp index d78273ce..1161096a 100644 --- a/test/keyboard.cpp +++ b/test/keyboard.cpp @@ -13,15 +13,17 @@ class keyboard : public FWidget protected: void onKeyPress (FKeyEvent*); void onAccel (FAccelEvent*); + void draw(); }; //---------------------------------------------------------------------- keyboard::keyboard (FWidget* parent) : FWidget(parent) { - setColor(fc::LightGray, fc::Black); - clrscr(); - updateTerminal(); + resetXTermForeground(); + resetXTermBackground(); + wc.term_fg = -1; + wc.term_bg = -1; } //---------------------------------------------------------------------- @@ -38,6 +40,18 @@ void keyboard::onAccel (FAccelEvent* ev) ev->accept(); } +//---------------------------------------------------------------------- +void keyboard::draw() +{ + setNormal(); + setColor(-1,-1); + clrscr(); + gotoxy (1,1); + print ("---------------\n"); + print ("Press Q to quit\n"); + print ("---------------\n"); + setCursorPos (1,5); +} //---------------------------------------------------------------------- // main part @@ -45,14 +59,9 @@ void keyboard::onAccel (FAccelEvent* ev) int main (int argc, char* argv[]) { FApplication app(argc, argv); - keyboard t(&app); - t.addAccelerator('q'); - app.setMainWidget(&t); - t.show(); - t.setTermXY(0,0); - t.flush_out(); - ::printf("---------------\n\r"); - ::printf("Press Q to quit\n\r"); - ::printf("---------------\n\r\n"); + keyboard key(&app); + key.addAccelerator('q'); + app.setMainWidget(&key); + key.show(); return app.exec(); } diff --git a/test/mandelbrot.cpp b/test/mandelbrot.cpp index 4ffa9054..5b672d35 100644 --- a/test/mandelbrot.cpp +++ b/test/mandelbrot.cpp @@ -46,9 +46,6 @@ void Mandelbrot::draw() FDialog::draw(); - if ( Encoding == fc::VT100 ) - unsetVT100altChar(); - x_min = -2.20; x_max = 1.00; y_min = -1.05; diff --git a/test/menu.cpp b/test/menu.cpp index 2cc6c907..24fa2d6e 100644 --- a/test/menu.cpp +++ b/test/menu.cpp @@ -196,7 +196,7 @@ void Menu::defaultCallback (FMenuList* mb) { for (uInt i=1; i <= mb->count(); i++) { - FMenuItem* item = mb->item(i); + FMenuItem* item = mb->item(int(i)); if ( item && item->isEnabled() diff --git a/test/term-attributes.cpp b/test/term-attributes.cpp index 43d8247b..002cf016 100644 --- a/test/term-attributes.cpp +++ b/test/term-attributes.cpp @@ -1,6 +1,7 @@ // File: term-attributes.cpp #include "fapp.h" +#include "fbutton.h" #include "fdialog.h" #include "fmessagebox.h" @@ -14,6 +15,15 @@ class AttribDlg : public FDialog { private: + FButton* next_button; + FButton* back_button; + + public: + short bgcolor; + + private: + AttribDlg (const AttribDlg&); // Disabled copy constructor + AttribDlg& operator = (const AttribDlg&); // and operator '=' void adjustSize(); public: @@ -21,14 +31,44 @@ class AttribDlg : public FDialog ~AttribDlg(); // destructor void onAccel (FAccelEvent*); void onClose (FCloseEvent*); + void cb_next (FWidget*, void*); + void cb_back (FWidget*, void*); }; #pragma pack(pop) //---------------------------------------------------------------------- AttribDlg::AttribDlg (FWidget* parent) : FDialog(parent) + , next_button() + , back_button() + , bgcolor(wc.label_bg) { - setText ("A terminal attributes test"); + resetXTermForeground(); + resetXTermBackground(); + setText ( "A terminal attributes test (" + + FString(getTermType()) + + ")"); + + next_button = new FButton("&Next >", this); + next_button->setGeometry(getWidth()-13, getHeight()-4, 10, 1); + next_button->setShadow(); + next_button->addAccelerator(fc::Fkey_right); + back_button = new FButton("< &Back", this); + back_button->setGeometry(getWidth()-25, getHeight()-4, 10, 1); + back_button->setShadow(); + back_button->addAccelerator(fc::Fkey_left); + + // Add function callbacks + next_button->addCallback + ( + "clicked", + _METHOD_CALLBACK (this, &AttribDlg::cb_next) + ); + back_button->addCallback + ( + "clicked", + _METHOD_CALLBACK (this, &AttribDlg::cb_back) + ); } //---------------------------------------------------------------------- @@ -56,12 +96,37 @@ void AttribDlg::onClose (FCloseEvent* ev) ev->ignore(); } +//---------------------------------------------------------------------- +void AttribDlg::cb_next (FWidget*, void*) +{ + if ( isMonochron() ) + return; + bgcolor++; + if ( bgcolor >= getMaxColor() ) + bgcolor = -1; + redraw(); +} + +//---------------------------------------------------------------------- +void AttribDlg::cb_back (FWidget*, void*) +{ + if ( isMonochron() ) + return; + bgcolor--; + if ( bgcolor < -1 ) + bgcolor = short(getMaxColor() - 1); + redraw(); +} + //---------------------------------------------------------------------- void AttribDlg::adjustSize() { - int h = parentWidget()->getHeight() - 2; int x = ((parentWidget()->getWidth() - getWidth()) / 2 ); - setGeometry(x, 2, 62, h, false); + int y = ((parentWidget()->getHeight() - getHeight()) / 2 ) + 1; + + setGeometry(x, y, 69, 21, false); + next_button->setGeometry(getWidth()-13, getHeight()-4, 10, 1, false); + back_button->setGeometry(getWidth()-25, getHeight()-4, 10, 1, false); FDialog::adjustSize(); } @@ -76,126 +141,191 @@ void AttribDlg::adjustSize() class AttribDemo : public FWidget { private: - int colors; + int colors; private: void printColorLine(); + void printAltCharset(); void draw(); public: - explicit AttribDemo (FWidget* parent = 0) // constructor - : FWidget(parent) - , colors(getMaxColor()) - { - if ( isMonochron() ) - colors = 1; - else if ( colors > 16 ) - colors = 16; - } - - ~AttribDemo() // destructor + explicit AttribDemo (FWidget* = 0); // constructor + ~AttribDemo() // destructor { } }; #pragma pack(pop) +//---------------------------------------------------------------------- +AttribDemo::AttribDemo (FWidget* parent) + : FWidget(parent) + , colors(getMaxColor()) +{ + if ( isMonochron() ) + colors = 1; + else if ( colors > 16 ) + colors = 16; + unsetFocusable(); +} + //---------------------------------------------------------------------- void AttribDemo::printColorLine() { - int bg = getTermBackgroundColor(); - for (int color=0; color < colors; color++) + AttribDlg* parent = static_cast(getParent()); + + for (short color=0; color < colors; color++) { - setColor(color, bg); + setColor (color, parent->bgcolor); print (" # "); } } +//---------------------------------------------------------------------- +void AttribDemo::printAltCharset() +{ + AttribDlg* parent = static_cast(getParent()); + + if ( ! isMonochron() ) + setColor (wc.label_fg, wc.label_bg); + + gotoxy (xpos + xmin - 1, ypos + ymin - 1); + print("alternate charset: "); + if ( parent->bgcolor == -1 ) + { + setColor (-1,-1); + } + else + { + if ( parent->bgcolor == 0 || parent->bgcolor == 16 ) + setColor (fc::White, parent->bgcolor); + else + setColor (fc::Black, parent->bgcolor); + } + setAltCharset(); + print("`abcdefghijklmnopqrstuvwxyz{|}~"); + unsetAltCharset(); + print(" "); +} + //---------------------------------------------------------------------- void AttribDemo::draw() { setUpdateVTerm(false); - int color_loop = 0; - std::vector background; - std::vector::iterator iter; - background.push_back(fc::White); - background.push_back(fc::Black); - background.push_back(-1); - iter = background.begin(); - while ( iter != background.end() ) + // test alternate character set + printAltCharset(); + + for (int y=0; y < parentWidget()->getHeight()-7; y++) { - for (int y=color_loop*7; y < parentWidget()->getHeight()-3; y++) + gotoxy ( xpos + xmin - 1, + ypos + ymin + y ); + + if ( ! isMonochron() ) + setColor (wc.label_fg, wc.label_bg); + + switch (y) { - if ( *iter == -1 ) + case 0: + print(" Dim: "); + setDim(); + printColorLine(); + unsetDim(); break; - else if ( *iter == fc::Black ) - { - if ( colors < 16 ) - setColor(fc::LightGray, fc::Black); - else - setColor(fc::White, fc::Black); - } - else - setColor(fc::Black, *iter); - gotoxy ( xpos + xmin - 1, - ypos + ymin - 1 + y ); + case 1: + print(" Normal: "); + setNormal(); + printColorLine(); + break; - switch (y - (color_loop*7)) - { - case 0: - print(" Dim: "); - setDim(); - printColorLine(); - unsetDim(); - break; + case 2: + print(" Bold: "); + setBold(); + printColorLine(); + unsetBold(); + break; - case 1: - print(" Normal: "); - printColorLine(); - break; + case 3: + print(" Bold+Dim: "); + setBold(); + setDim(); + printColorLine(); + unsetDim(); + unsetBold(); + break; - case 2: - print(" Bold: "); - setBold(); - printColorLine(); - unsetBold(); - break; + case 4: + print(" Italic: "); + setItalic(); + printColorLine(); + unsetItalic(); + break; - case 3: - print(" Bold+Dim: "); - setBold(); - setDim(); - printColorLine(); - unsetDim(); - unsetBold(); - break; + case 5: + print(" Underline: "); + setUnderline(); + printColorLine(); + unsetUnderline(); + break; - case 4: - print(" Italic: "); - setItalic(); - printColorLine(); - unsetItalic(); - break; + case 6: + print(" Double underline: "); + setDoubleUnderline(); + printColorLine(); + unsetDoubleUnderline(); + break; - case 5: - print(" Underline: "); - setUnderline(); - printColorLine(); - unsetUnderline(); - break; + case 7: + print(" Crossed-out: "); + setCrossedOut(); + printColorLine(); + unsetCrossedOut(); + break; - case 6: - print(" Reverse: "); - setReverse(); - printColorLine(); - unsetReverse(); - break; - } + case 8: + print(" Blink: "); + setBlink(); + printColorLine(); + unsetBlink(); + break; + + case 9: + print(" Reverse: "); + setReverse(); + printColorLine(); + unsetReverse(); + break; + + case 10: + print(" Standout: "); + setStandout(); + printColorLine(); + unsetStandout(); + break; + + case 11: + print(" Invisible: "); + setInvisible(); + printColorLine(); + unsetInvisible(); + break; + + case 12: + print(" Protected: "); + setProtected(); + printColorLine(); + unsetProtected(); + break; } - color_loop++; - ++iter; } + if ( ! isMonochron() ) + setColor(wc.label_fg, wc.label_bg); + gotoxy (xpos + xmin - 1, ypos + ymin + 13); + printf ( " Background color: %d ", + static_cast(getParent())->bgcolor ); + gotoxy (xpos + xmin + 14, ypos + ymin + 15); + print ("Change background color ->"); + setUpdateVTerm(true); } @@ -212,13 +342,12 @@ int main (int argc, char* argv[]) // the parent object "app" (FObject destructor). AttribDlg* dialog = new AttribDlg(&app); - dialog->setGeometry (6, 2, 62, 22); + dialog->setGeometry (6, 2, 69, 21); dialog->addAccelerator('q'); // press 'q' to quit dialog->setShadow(); AttribDemo* demo = new AttribDemo(dialog); - demo->ignorePadding(false); - demo->setGeometry (1,1,63,20); + demo->setGeometry (1,1,67,19); app.setMainWidget(dialog); dialog->show(); diff --git a/test/timer.cpp b/test/timer.cpp index 419a40ea..fbf00991 100644 --- a/test/timer.cpp +++ b/test/timer.cpp @@ -13,6 +13,7 @@ class timer : public FWidget protected: void onTimer (FTimerEvent*); void onAccel (FAccelEvent*); + void draw(); }; //---------------------------------------------------------------------- @@ -25,9 +26,10 @@ timer::timer (FWidget* parent) delTimer (id); addTimer (250); // 250-millisecond timer - setColor(fc::LightGray, fc::Black); - clrscr(); - updateTerminal(); + resetXTermForeground(); + resetXTermBackground(); + wc.term_fg = -1; + wc.term_bg = -1; } //---------------------------------------------------------------------- @@ -43,6 +45,19 @@ void timer::onAccel (FAccelEvent* ev) ev->accept(); } +//---------------------------------------------------------------------- +void timer::draw() +{ + setNormal(); + setColor(-1,-1); + clrscr(); + gotoxy (1,1); + print ("---------------\n"); + print ("Press Q to quit\n"); + print ("---------------\n"); + setCursorPos (1,4); +} + //---------------------------------------------------------------------- // main part @@ -54,10 +69,5 @@ int main (int argc, char* argv[]) t.addAccelerator('q'); app.setMainWidget(&t); t.show(); - t.setTermXY(0,0); - t.flush_out(); - ::printf("---------------\n\r"); - ::printf("Press Q to quit\n\r"); - ::printf("---------------\n\r\n"); return app.exec(); } diff --git a/test/ui.cpp b/test/ui.cpp index 9fc27894..6dfeb071 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -564,7 +564,7 @@ void MyDialog::cb_about (FWidget*, void*) FMessageBox info ( "About" , line + L" The Final Cut " + line + "\n\n" L"Version " + libver + "\n\n" - L"(c) 2015 by Markus Gans" + L"(c) 2016 by Markus Gans" , FMessageBox::Ok, 0, 0, this ); info.setCenterText(); info.show(); @@ -797,7 +797,7 @@ void MyDialog::adjustSize() int main (int argc, char* argv[]) { FString ver = F_VERSION; // library version - FString title = "The FINAL CUT " + ver + " (C) 2015 by Markus Gans"; + FString title = "The FINAL CUT " + ver + " (C) 2016 by Markus Gans"; if ( argv[1] && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )