From b05873babb72ce55280b99dda70d42ad05fa53b7 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 20 May 2018 15:15:42 +0200 Subject: [PATCH] Methods outsourcing from FTerm to FTermXTerminal --- ChangeLog | 3 + README.md | 38 +- doc/class-diagram.txt | 38 +- doc/class_template.cpp | 51 ++ doc/class_template.h | 128 +++++ examples/ui.cpp | 11 +- fonts/README.txt | 45 ++ include/final/fc.h | 1 + include/final/fterm.h | 102 ++-- include/final/ftermxterminal.h | 218 ++++++++ include/final/fvterm.h | 29 +- src/Makefile.am | 2 + src/Makefile.clang | 2 + src/Makefile.gcc | 2 + src/Makefile.in | 11 +- src/flineedit.cpp | 14 +- src/fmouse.cpp | 17 +- src/fterm.cpp | 793 +++++++++------------------- src/ftermcapquirks.cpp | 2 +- src/ftermxterminal.cpp | 926 +++++++++++++++++++++++++++++++++ src/fvterm.cpp | 77 +-- src/fwidget.cpp | 17 +- src/test/fstring-test.cpp | 248 ++++----- 23 files changed, 1871 insertions(+), 904 deletions(-) create mode 100644 doc/class_template.cpp create mode 100644 doc/class_template.h create mode 100644 fonts/README.txt create mode 100644 include/final/ftermxterminal.h create mode 100644 src/ftermxterminal.cpp diff --git a/ChangeLog b/ChangeLog index ebc8d84d..6bd23b16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-05-20 Markus Gans + * Methods outsourcing from FTerm to FTermXTerminal + 2017-05-06 Markus Gans * Some protected data members in FTerm moved to private diff --git a/README.md b/README.md index b9f11a03..2dee49ee 100644 --- a/README.md +++ b/README.md @@ -123,25 +123,25 @@ Class digramm │ ┌─────────────┐ ├────┤ FMouseEvent │ │ └─────────────┘ - │ ┌─────────────┐ - ├────┤ FWheelEvent │ - │ └─────────────┘ - │ ┌─────────────┐ - ├────┤ FFocusEvent │ - │ └─────────────┘ - │ ┌─────────────┐ - ┌────────┐ ├────┤ FAccelEvent │ - │ FEvent │◄─┤ └─────────────┘ - └───┬────┘ │ ┌──────────────┐ - :1 ├────┤ FResizeEvent │ - : │ └──────────────┘ - : │ ┌────────────┐ - : ├────┤ FShowEvent │ - : │ └────────────┘ - : │ ┌────────────┐ - : ├────┤ FHideEvent │ - : │ └────────────┘ - 1┌───────────┐ : │ ┌─────────────┐ + 1┌────────────────┐ │ ┌─────────────┐ + ┌-----------┤ FTermDetection │ ├────┤ FWheelEvent │ + : └────────────────┘ │ └─────────────┘ + : 1┌────────────────┐ │ ┌─────────────┐ + ┌-----------┤ FTermcapQuirks │ ├────┤ FFocusEvent │ + : └────────────────┘ │ └─────────────┘ + : 1┌──────────┐ │ ┌─────────────┐ + ┌-----------┤ FTermcap │ ┌────────┐ ├────┤ FAccelEvent │ + : └──────────┘ │ FEvent │◄─┤ └─────────────┘ + : 1┌──────────┐ └───┬────┘ │ ┌──────────────┐ + ┌-----------┤ FTermios │ :1 ├────┤ FResizeEvent │ + : └──────────┘ : │ └──────────────┘ + : 1┌────────────────┐ : │ ┌────────────┐ + ┌-----------┤ FTermXTerminal │ : ├────┤ FShowEvent │ + : └────────────────┘ : │ └────────────┘ + : 1┌───────────────┐ : │ ┌────────────┐ + ┌-----------┤ FColorPalette │ : ├────┤ FHideEvent │ + : └───────────────┘ : │ └────────────┘ + : 1┌───────────┐ : │ ┌─────────────┐ ┌-----------┤ FOptiMove │ : ├────┤ FCloseEvent │ : └───────────┘ : │ └─────────────┘ : 1┌───────────┐ : │ ┌─────────────┐ diff --git a/doc/class-diagram.txt b/doc/class-diagram.txt index 111d1556..07430abf 100644 --- a/doc/class-diagram.txt +++ b/doc/class-diagram.txt @@ -8,25 +8,25 @@ │ ┌─────────────┐ ├────┤ FMouseEvent │ │ └─────────────┘ - │ ┌─────────────┐ - ├────┤ FWheelEvent │ - │ └─────────────┘ - │ ┌─────────────┐ - ├────┤ FFocusEvent │ - │ └─────────────┘ - │ ┌─────────────┐ - ┌────────┐ ├────┤ FAccelEvent │ - │ FEvent │◄─┤ └─────────────┘ - └───┬────┘ │ ┌──────────────┐ - :1 ├────┤ FResizeEvent │ - : │ └──────────────┘ - : │ ┌────────────┐ - : ├────┤ FShowEvent │ - : │ └────────────┘ - : │ ┌────────────┐ - : ├────┤ FHideEvent │ - : │ └────────────┘ - 1┌───────────┐ : │ ┌─────────────┐ + 1┌────────────────┐ │ ┌─────────────┐ + ┌-----------┤ FTermDetection │ ├────┤ FWheelEvent │ + : └────────────────┘ │ └─────────────┘ + : 1┌────────────────┐ │ ┌─────────────┐ + ┌-----------┤ FTermcapQuirks │ ├────┤ FFocusEvent │ + : └────────────────┘ │ └─────────────┘ + : 1┌──────────┐ │ ┌─────────────┐ + ┌-----------┤ FTermcap │ ┌────────┐ ├────┤ FAccelEvent │ + : └──────────┘ │ FEvent │◄─┤ └─────────────┘ + : 1┌──────────┐ └───┬────┘ │ ┌──────────────┐ + ┌-----------┤ FTermios │ :1 ├────┤ FResizeEvent │ + : └──────────┘ : │ └──────────────┘ + : 1┌────────────────┐ : │ ┌────────────┐ + ┌-----------┤ FTermXTerminal │ : ├────┤ FShowEvent │ + : └────────────────┘ : │ └────────────┘ + : 1┌───────────────┐ : │ ┌────────────┐ + ┌-----------┤ FColorPalette │ : ├────┤ FHideEvent │ + : └───────────────┘ : │ └────────────┘ + : 1┌───────────┐ : │ ┌─────────────┐ ┌-----------┤ FOptiMove │ : ├────┤ FCloseEvent │ : └───────────┘ : │ └─────────────┘ : 1┌───────────┐ : │ ┌─────────────┐ diff --git a/doc/class_template.cpp b/doc/class_template.cpp new file mode 100644 index 00000000..99d53d1a --- /dev/null +++ b/doc/class_template.cpp @@ -0,0 +1,51 @@ +/*********************************************************************** +* fclassname.cpp - [brief description] * +* * +* This file is part of the Final Cut widget toolkit * +* * +* Copyright [year] [Maintainer] * +* * +* The Final Cut is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Lesser General Public License * +* as published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* The Final Cut is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +#include "final/fclassname.h" + +// static class attributes + + +//---------------------------------------------------------------------- +// class fClassName +//---------------------------------------------------------------------- + +// constructors and destructor +//---------------------------------------------------------------------- +fClassName::fClassName() +{ } + +//---------------------------------------------------------------------- +fClassName::~fClassName() // destructor +{ } + +// public methods of fClassName +//---------------------------------------------------------------------- + + +// protected methods of fClassName +//---------------------------------------------------------------------- + + +// private methods of fClassName +//---------------------------------------------------------------------- + diff --git a/doc/class_template.h b/doc/class_template.h new file mode 100644 index 00000000..d5528f6a --- /dev/null +++ b/doc/class_template.h @@ -0,0 +1,128 @@ +/*********************************************************************** +* fclassname.h - [brief description] * +* * +* This file is part of the Final Cut widget toolkit * +* * +* Copyright [year] [Maintainer] * +* * +* The Final Cut is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Lesser General Public License * +* as published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* The Final Cut is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +/* Standalone class + * ════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ fClassName ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +#ifndef FCLASSNAME_H +#define FCLASSNAME_H + +#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) + #error "Only can be included directly." +#endif + +//#include ... + + +//---------------------------------------------------------------------- +// class fClassName +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class fClassName +{ + public: + // Using-declaration + + // Typedefs and Enumerations + + // Constants + + // Constructors + fClassName(); + + // Destructor + ~fClassName(); + + // Overloaded operators + + // Accessors + + // Inquiries + + // Methods + + // Event handlers + + // Callback methods + + // Data Members + + protected: + // Typedefs and Enumerations + + // Constants + + // Accessors + + // Inquiries + + // Methods + + // Event handlers + + // Callback methods + + // Data Members + + private: + // Typedefs and Enumerations + + // Constants + + // Disable copy constructor + fClassName (const fClassName&); + + // Disable assignment operator (=) + fClassName& operator = (const fClassName&); + + // Accessors + + // Inquiries + + // Methods + + // Event handlers + + // Callback methods + + // Data Members + + // Friend class + +}; +#pragma pack(pop) + +// fClassName inline functions +//---------------------------------------------------------------------- + + +#endif // FCLASSNAME_H + + diff --git a/examples/ui.cpp b/examples/ui.cpp index c2c94615..c755ddd0 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -39,6 +39,7 @@ class ProgressDialog : public FDialog public: // Constructor explicit ProgressDialog (FWidget* = 0); + // Destructor ~ProgressDialog(); @@ -194,6 +195,7 @@ class TextWindow : public FDialog public: // Constructor explicit TextWindow (FWidget* = 0); + // Destructor ~TextWindow(); @@ -205,6 +207,7 @@ class TextWindow : public FDialog // Disable assignment operator (=) TextWindow& operator = (const TextWindow&); + // Method void adjustSize(); // Data Members @@ -969,8 +972,8 @@ void MyDialog::cb_setTitlebar (FWidget* widget, data_ptr) FLineEdit* lineedit = static_cast(widget); FString title; *lineedit >> title; - setXTermTitle(title);; - setText(title); + setTermTitle (title); + setText (title); redraw(); } @@ -1072,8 +1075,8 @@ int main (int argc, char* argv[]) // Create the application object app FApplication app(argc, argv); - app.setXTermDefaultColors(true); - app.setXTermTitle (title); + app.redefineDefaultColors(true); + app.setTermTitle (title); // Force vt100 encoding //app.setEncoding("VT100"); diff --git a/fonts/README.txt b/fonts/README.txt new file mode 100644 index 00000000..98fd789d --- /dev/null +++ b/fonts/README.txt @@ -0,0 +1,45 @@ +How can I use the new graphical font under the Linux text console? +------------------------------------------------------------------ + +Simply start your program with the parameter `--newfont`. + + +How can I use the new graphical font under X11? +----------------------------------------------- + +The use of the new graphical font under X11 is only possible with +the terminal emulators xterm or urxvt, because only these terminal +emulators can change the font by using an escape sequence. +For an xterm, the "Allow Font Ops" option must be set. + +Install the gzip compressed X11 pcf bitmap font 8x16graph.pcf.gz on your xserver: +--------------------------------------------------------------------------------- + +1. Create as user root the font directory + + mkdir /usr/share/fonts/X11/misc/finalcut/ + + +2. Copy the files 8x16graph.pcf.gz, fonts.dir and fonts.alias + into the just created directory + + cp 8x16graph.pcf.gz fonts.dir fonts.alias /usr/share/fonts/X11/misc/finalcut/ + + +3. Add the new dir to X font path + + xset fp+ /usr/share/fonts/X11/misc/finalcut/ + + (You can insert this command into the ~/.xinitrc to make the + font path permanently usable) + + +4. Check if the font is available to the xserver + + xlsfonts | grep 8x16graph + + +5. Start your program with the parameter --newfont + + ui --newfont + diff --git a/include/final/fc.h b/include/final/fc.h index 9d8a63fd..be7e771a 100644 --- a/include/final/fc.h +++ b/include/final/fc.h @@ -963,6 +963,7 @@ enum scrollBarMode // Xterm cursor style enum xtermCursorStyle { + unknown_cursor_style = -1, blinking_block = 0, blinking_block_default = 1, steady_block = 2, diff --git a/include/final/fterm.h b/include/final/fterm.h index 5e49cff4..f75194cb 100644 --- a/include/final/fterm.h +++ b/include/final/fterm.h @@ -23,14 +23,38 @@ /* Base class * ══════════ * - * ▕▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▔▔▔▔▏ - * ▕ FTerm ▏-┬- - - -▕ FOptiMove ▏ - * ▕▁▁▁▁▁▁▁▏ : ▕▁▁▁▁▁▁▁▁▁▁▁▏ + * ▕▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FTerm ▏-┬- - - -▕ FTermios ▏ + * ▕▁▁▁▁▁▁▁▏ : ▕▁▁▁▁▁▁▁▁▁▁▏ + * : + * : 1▕▔▔▔▔▔▔▔▔▔▔▏ + * :- - - -▕ FTermcap ▏ + * : ▕▁▁▁▁▁▁▁▁▁▁▏ + * : + * : 1▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * :- - - -▕ FTermcapQuirks ▏ + * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * : + * : 1▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * :- - - -▕ FTermDetection ▏ + * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * : + * : 1▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * :- - - -▕ FTermXTerminal ▏ + * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * : + * : 1▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * :- - - -▕ FColorPalette ▏ + * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ * : * : 1▕▔▔▔▔▔▔▔▔▔▔▔▏ * :- - - -▕ FOptiAttr ▏ * : ▕▁▁▁▁▁▁▁▁▁▁▁▏ * : + * : 1▕▔▔▔▔▔▔▔▔▔▔▔▏ + * :- - - -▕ FOptiMove ▏ + * : ▕▁▁▁▁▁▁▁▁▁▁▁▏ + * : * : *▕▔▔▔▔▔▔▔▔▔▏ * :- - - -▕ FString ▏ * : ▕▁▁▁▁▁▁▁▁▁▏ @@ -123,6 +147,7 @@ #include "final/ftermcapquirks.h" #include "final/ftermdetection.h" #include "final/ftermios.h" +#include "final/ftermxterminal.h" //---------------------------------------------------------------------- @@ -190,6 +215,7 @@ class FTerm #endif // Inquiries + static bool isCursorHidden(); static bool isKeypressTimeout (timeval*); static bool isNormal (char_data*&); static bool isRaw(); @@ -223,11 +249,14 @@ class FTerm // Mutators static void setTermType (char[]); + static void setInsertCursor (bool on); + static void setInsertCursor(); + static void unsetInsertCursor(); static bool setCursorOptimisation (bool); - static void setXTermDefaultColors (bool); + static void redefineDefaultColors (bool); #if defined(__linux__) - static void setLinuxConsoleCursorStyle \ + static char* setLinuxConsoleCursorStyle \ (fc::linuxConsoleCursorStyle, bool); #endif @@ -253,31 +282,14 @@ class FTerm static bool setNewFont(); static bool setOldFont(); static char* moveCursor (int, int, int, int); + static char* cursorsVisibility (bool); static void printMoveDurations(); static char* enableCursor(); static char* disableCursor(); static void detectTermSize(); static void setTermSize (int, int); + static void setTermTitle(const FString&); static void setKDECursor (fc::kdeKonsoleCursorShape); - static const FString* getXTermFont(); - static const FString* getXTermTitle(); - static void setXTermCursorStyle (fc::xtermCursorStyle); - static void setXTermTitle (const FString&); - static void setXTermForeground (const FString&); - static void setXTermBackground (const FString&); - static void setXTermCursorColor (const FString&); - static void setXTermMouseForeground (const FString&); - static void setXTermMouseBackground (const FString&); - static void setXTermHighlightBackground (const FString&); - static void setXTermDefaults(); - static void resetXTermColors(); - static void resetXTermForeground(); - static void resetXTermBackground(); - static void resetXTermCursorColor(); - static void resetXTermMouseForeground(); - static void resetXTermMouseBackground(); - static void resetXTermHighlightBackground(); - static void resetXTermDefaults(); static void saveColorMap(); static void resetColorMap(); static void setPalette (short, int, int, int); @@ -331,21 +343,13 @@ class FTerm static uInt getCursorAddressLengths(); // Methods -#if defined(__linux__) - static void initLinuxConsoleCharMap(); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) - static void initFreeBSDConsoleCharMap(); -#endif - + static void initScreenSettings(); static bool charEncodable (uInt); static uInt charEncode (uInt); static uInt charEncode (uInt, fc::encoding); static char* changeAttribute ( char_data*& , char_data*& ); static void changeTermSizeFinished(); - static void xtermMetaSendsESC (bool); static void exitWithMessage (std::string) #if defined(__clang__) || defined(__GNUC__) __attribute__((noreturn)) @@ -428,6 +432,7 @@ class FTerm static int setUnicodeMap (struct unimapdesc*); static int getUnicodeMap (); static void initLinuxConsole(); + static void initLinuxConsoleCharMap(); #endif #if defined(__FreeBSD__) || defined(__DragonFly__) @@ -436,6 +441,7 @@ class FTerm static bool setFreeBSDAlt2Meta(); static bool resetFreeBSDAlt2Meta(); static void initFreeBSDConsole(); + static void initFreeBSDConsoleCharMap(); #endif #if defined(__NetBSD__) || defined(__OpenBSD__) @@ -474,11 +480,12 @@ class FTerm static void init_tab_quirks(); static void redefineColorPalette(); static void restoreColorPalette(); + static void setInsertCursorStyle(); + static void setOverwriteCursorStyle(); static void enableMouse(); static void disableMouse(); static void useAlternateScreenBuffer(); static void useNormalScreenBuffer(); - static void captureXTermFontAndTitle(); void allocationValues(); void deallocationValues(); void init(); @@ -504,7 +511,7 @@ class FTerm static bool shadow_character; static bool half_block_character; static bool cursor_optimisation; - static bool xterm_default_colors; + static bool hidden_cursor; static bool use_alternate_screen; static bool input_data_pending; static bool non_blocking_stdin; @@ -554,9 +561,10 @@ class FTerm static FOptiMove* opti_move; static FOptiAttr* opti_attr; static FTermDetection* term_detection; + static FTermXTerminal* xterm; static FMouseControl* mouse; - static const FString* xterm_font; - static const FString* xterm_title; + static const FString* save_xterm_font; + static const FString* save_xterm_title; static struct colorEnv { @@ -582,8 +590,8 @@ class FTerm { void setDefault() { - terminal_id_type = -1; - terminal_id_version = -1; + terminal_id_type = -1; + terminal_id_version = -1; terminal_id_hardware = -1; } @@ -649,6 +657,10 @@ inline int FTerm::getFramebufferBpp() { return framebuffer_bpp; } #endif +//---------------------------------------------------------------------- +inline bool FTerm::isCursorHidden() +{ return hidden_cursor; } + //---------------------------------------------------------------------- inline bool FTerm::isKeypressTimeout (timeval* time) { return FObject::isTimeout (time, key_timeout); } @@ -762,12 +774,16 @@ inline bool FTerm::isUTF8() { return utf8_state; } //---------------------------------------------------------------------- -inline bool FTerm::setCursorOptimisation (bool on) -{ return cursor_optimisation = ( on ) ? true : false; } +inline void FTerm::setInsertCursor() +{ setInsertCursor(true); } //---------------------------------------------------------------------- -inline void FTerm::setXTermDefaultColors (bool on) -{ xterm_default_colors = on; } +inline void FTerm::unsetInsertCursor() +{ setInsertCursor(false); } + +//---------------------------------------------------------------------- +inline bool FTerm::setCursorOptimisation (bool on) +{ return cursor_optimisation = ( on ) ? true : false; } //---------------------------------------------------------------------- inline void FTerm::setKeypressTimeout (const long timeout) diff --git a/include/final/ftermxterminal.h b/include/final/ftermxterminal.h new file mode 100644 index 00000000..925d5332 --- /dev/null +++ b/include/final/ftermxterminal.h @@ -0,0 +1,218 @@ +/*********************************************************************** +* ftermxterminal.h - Contains all xterm-specific terminal functions * +* * +* This file is part of the Final Cut widget toolkit * +* * +* Copyright 2018 Markus Gans * +* * +* The Final Cut is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Lesser General Public License * +* as published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* The Final Cut is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +/* Standalone class + * ════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FTermXTerminal ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +#ifndef FTERMXTERMINAL_H +#define FTERMXTERMINAL_H + +#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) + #error "Only can be included directly." +#endif + +#include "final/fc.h" +#include "final/fstring.h" +#include "final/ftermcap.h" +#include "final/ftermdetection.h" + + +//---------------------------------------------------------------------- +// class FTermXTerminal +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FTermXTerminal +{ + public: + // Constructors + FTermXTerminal(); + + // Destructor + ~FTermXTerminal(); + + // Mutators + static void setTermcapMap (FTermcap::tcap_map*); + static void setFTermDetection (FTermDetection*); + static void redefineDefaultColors (bool); + static void setCursorStyle (fc::xtermCursorStyle); + static void setFont (const FString&); + static void setTitle (const FString&); + static void setForeground (const FString&); + static void setBackground (const FString&); + static void setCursorColor (const FString&); + static void setMouseForeground (const FString&); + static void setMouseBackground (const FString&); + static void setHighlightBackground (const FString&); + static void setMouseSupport (bool); + static void setMouseSupport(); + static void unsetMouseSupport(); + static void metaSendsESC (bool); + + // Accessors + static fc::xtermCursorStyle getCursorStyle(); + static const FString* getFont(); + static const FString* getTitle(); + static const FString* getForeground(); + static const FString* getBackground(); + static const FString* getCursorColor(); + static const FString* getMouseForeground(); + static const FString* getMouseBackground(); + static const FString* getHighlightBackground(); + + // Inquiries + static bool hasFont(); + static bool hasTitle(); + + // Methods + static void setDefaults(); + static void resetColorMap(); + static void resetForeground(); + static void resetBackground(); + static void resetCursorColor(); + static void resetMouseForeground(); + static void resetMouseBackground(); + static void resetHighlightBackground(); + static void resetDefaults(); + static void captureFontAndTitle(); + + private: + // Methods + static void setXTermCursorStyle(); + static void setXTermFont(); + static void setXTermTitle(); + static void setXTermForeground(); + static void setXTermBackground(); + static void setXTermCursorColor(); + static void setXTermMouseForeground(); + static void setXTermMouseBackground(); + static void setXTermHighlightBackground(); + static void setXTerm8ColorDefaults(); + static void setXTerm16ColorDefaults(); + static void resetXTermColorMap(); + static void resetXTermForeground(); + static void resetXTermBackground(); + static void resetXTermCursorColor(); + static void resetXTermMouseForeground(); + static void resetXTermMouseBackground(); + static void resetXTermHighlightBackground(); + static void oscPrefix(); + static void oscPostfix(); + static const FString* captureXTermFont(); + static const FString* captureXTermTitle(); + static void enableXTermMouse(); + static void disableXTermMouse(); + static void enableXTermMetaSendsESC(); + static void disableXTermMetaSendsESC(); + + // Data Members + static FTermcap::tcap_map* tcap; + static FTermDetection* term_detection; + static fc::xtermCursorStyle cursor_style; + static const FString* xterm_font; + static const FString* xterm_title; + static const FString* foreground_color; + static const FString* background_color; + static const FString* cursor_color; + static const FString* mouse_foreground_color; + static const FString* mouse_background_color; + static const FString* highlight_background_color; + static bool mouse_support; + static bool meta_sends_esc; + static bool xterm_default_colors; +}; +#pragma pack(pop) + +// FTermXTerminal inline functions +//---------------------------------------------------------------------- +inline void FTermXTerminal::setTermcapMap (FTermcap::tcap_map* tc) +{ tcap = tc; } + +//---------------------------------------------------------------------- +inline void FTermXTerminal::setFTermDetection (FTermDetection* td) +{ term_detection = td; } + +//---------------------------------------------------------------------- +inline void FTermXTerminal::redefineDefaultColors (bool on) +{ xterm_default_colors = on; } + +//---------------------------------------------------------------------- +inline fc::xtermCursorStyle FTermXTerminal::getCursorStyle() +{ return cursor_style; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getFont() +{ return xterm_font; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getTitle() +{ return xterm_title; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getForeground() +{ return foreground_color; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getBackground() +{ return background_color; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getCursorColor() +{ return cursor_color; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getMouseForeground() +{ return mouse_foreground_color; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getMouseBackground() +{ return mouse_background_color; } + +//---------------------------------------------------------------------- +inline const FString* FTermXTerminal::getHighlightBackground() +{ return highlight_background_color; } + +//---------------------------------------------------------------------- +inline bool FTermXTerminal::hasFont() +{ return bool(xterm_font && xterm_font->getLength() > 2); } + +//---------------------------------------------------------------------- +inline bool FTermXTerminal::hasTitle() +{ return bool(xterm_title && xterm_title->getLength() > 0); } + +//---------------------------------------------------------------------- +inline void FTermXTerminal::setMouseSupport() +{ setMouseSupport (true); } + +//---------------------------------------------------------------------- +inline void FTermXTerminal::unsetMouseSupport() +{ setMouseSupport (false); } + + +#endif // FTERMXTERMINAL_H diff --git a/include/final/fvterm.h b/include/final/fvterm.h index e23c7b28..9a52c89e 100644 --- a/include/final/fvterm.h +++ b/include/final/fvterm.h @@ -129,9 +129,9 @@ class FVTerm : public FTerm // Mutators static void setTermXY (register int, register int); - static bool hideCursor (bool); - static bool hideCursor(); - static bool showCursor(); + static void hideCursor (bool); + static void hideCursor(); + static void showCursor(); void setPrintCursor (const FPoint&); void setPrintCursor (register int, register int); void setColor (short, short); @@ -202,7 +202,6 @@ class FVTerm : public FTerm static bool unsetInheritBackground(); // Inquiries - static bool isCursorHidden(); static bool isBold(); static bool isDim(); static bool isItalic(); @@ -275,11 +274,6 @@ class FVTerm : public FTerm bool hasChildPrintArea() const; bool isVirtualWindow() const; - // Mutator - static void setInsertCursorStyle (bool on); - static void setInsertCursorStyle(); - static void unsetInsertCursorStyle(); - // Methods void createArea ( const FRect& , const FPoint& @@ -443,7 +437,6 @@ class FVTerm : public FTerm static char_data i_ch; // inherit background character static FPoint* term_pos; // terminal cursor position static termcap_map* tcap; - static bool hidden_cursor; static bool terminal_update_complete; static bool terminal_update_pending; static bool force_terminal_update; @@ -552,11 +545,11 @@ inline FVTerm::char_data FVTerm::getAttribute() { return next_attribute; } //---------------------------------------------------------------------- -inline bool FVTerm::hideCursor() +inline void FVTerm::hideCursor() { return hideCursor(true); } //---------------------------------------------------------------------- -inline bool FVTerm::showCursor() +inline void FVTerm::showCursor() { return hideCursor(false); } //---------------------------------------------------------------------- @@ -774,10 +767,6 @@ inline bool FVTerm::setInheritBackground() inline bool FVTerm::unsetInheritBackground() { return setInheritBackground(false); } -//---------------------------------------------------------------------- -inline bool FVTerm::isCursorHidden() -{ return hidden_cursor; } - //---------------------------------------------------------------------- inline bool FVTerm::isBold() { return next_attribute.attr.bit.bold; } @@ -858,14 +847,6 @@ inline bool FVTerm::hasChildPrintArea() const inline bool FVTerm::isVirtualWindow() const { return vwin; } -//---------------------------------------------------------------------- -inline void FVTerm::setInsertCursorStyle() -{ setInsertCursorStyle(true); } - -//---------------------------------------------------------------------- -inline void FVTerm::unsetInsertCursorStyle() -{ setInsertCursorStyle(false); } - //---------------------------------------------------------------------- inline void FVTerm::setPrintArea (term_area* area) { print_area = area; } diff --git a/src/Makefile.am b/src/Makefile.am index 8654917e..89bb60b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,7 @@ libfinal_la_SOURCES = \ ftextview.cpp \ fstatusbar.cpp \ ftermcapquirks.cpp \ + ftermxterminal.cpp \ ftermdetection.cpp \ ftermios.cpp \ fterm.cpp \ @@ -104,6 +105,7 @@ finalcutinclude_HEADERS = \ ../include/final/ftcap_map.h \ ../include/final/ftermcap.h \ ../include/final/ftermcapquirks.h \ + ../include/final/ftermxterminal.h \ ../include/final/ftermdetection.h \ ../include/final/ftermios.h \ ../include/final/fterm.h \ diff --git a/src/Makefile.clang b/src/Makefile.clang index df41f611..8d85252e 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -47,6 +47,7 @@ INCLUDE_HEADERS = \ ftermios.h \ ftermdetection.h \ ftermcapquirks.h \ + ftermxterminal.h \ fvterm.h \ ftextview.h \ ftogglebutton.h \ @@ -101,6 +102,7 @@ OBJS = \ ftermios.o \ ftermdetection.o \ ftermcapquirks.o \ + ftermxterminal.o \ fvterm.o \ fevent.o \ foptiattr.o \ diff --git a/src/Makefile.gcc b/src/Makefile.gcc index 2bfd71e0..412073ad 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -47,6 +47,7 @@ INCLUDE_HEADERS = \ ftermios.h \ ftermdetection.h \ ftermcapquirks.h \ + ftermxterminal.h \ fvterm.h \ ftextview.h \ ftogglebutton.h \ @@ -101,6 +102,7 @@ OBJS = \ ftermios.o \ ftermdetection.o \ ftermcapquirks.o \ + ftermxterminal.o \ fvterm.o \ fevent.o \ foptiattr.o \ diff --git a/src/Makefile.in b/src/Makefile.in index 9c046add..9d2fd131 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -136,10 +136,10 @@ am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \ fdialoglistmenu.lo fmenubar.lo fmenuitem.lo fradiomenuitem.lo \ fcheckmenuitem.lo fmenulist.lo fdialog.lo fscrollview.lo \ fwindow.lo fmessagebox.lo ftooltip.lo ffiledialog.lo \ - ftextview.lo fstatusbar.lo ftermcapquirks.lo ftermdetection.lo \ - ftermios.lo fterm.lo fvterm.lo fevent.lo foptiattr.lo \ - foptimove.lo ftermbuffer.lo fapplication.lo fcolorpalette.lo \ - fwidgetcolors.lo fwidget.lo fobject.lo + ftextview.lo fstatusbar.lo ftermcapquirks.lo ftermxterminal.lo \ + ftermdetection.lo ftermios.lo fterm.lo fvterm.lo fevent.lo \ + foptiattr.lo foptimove.lo ftermbuffer.lo fapplication.lo \ + fcolorpalette.lo fwidgetcolors.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@) @@ -414,6 +414,7 @@ libfinal_la_SOURCES = \ ftextview.cpp \ fstatusbar.cpp \ ftermcapquirks.cpp \ + ftermxterminal.cpp \ ftermdetection.cpp \ ftermios.cpp \ fterm.cpp \ @@ -475,6 +476,7 @@ finalcutinclude_HEADERS = \ ../include/final/ftcap_map.h \ ../include/final/ftermcap.h \ ../include/final/ftermcapquirks.h \ + ../include/final/ftermxterminal.h \ ../include/final/ftermdetection.h \ ../include/final/ftermios.h \ ../include/final/fterm.h \ @@ -603,6 +605,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftermcapquirks.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftermdetection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftermios.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftermxterminal.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftextview.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftogglebutton.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftooltip.Plo@am__quote@ diff --git a/src/flineedit.cpp b/src/flineedit.cpp index f5fbc3b0..a2dfec1b 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -69,7 +69,7 @@ FLineEdit::FLineEdit (const FString& txt, FWidget* parent) FLineEdit::~FLineEdit() // destructor { if ( ! insert_mode ) - setInsertCursorStyle(); + setInsertCursor(); } // FLineEdit operators @@ -611,16 +611,16 @@ void FLineEdit::onAccel (FAccelEvent* ev) void FLineEdit::onHide (FHideEvent*) { if ( ! insert_mode ) - setInsertCursorStyle(); + setInsertCursor(); } //---------------------------------------------------------------------- void FLineEdit::onFocusIn (FFocusEvent*) { if ( insert_mode ) - setInsertCursorStyle(); + setInsertCursor(); else - unsetInsertCursorStyle(); + unsetInsertCursor(); if ( getStatusBar() ) { @@ -640,7 +640,7 @@ void FLineEdit::onFocusOut (FFocusEvent*) } if ( ! insert_mode ) - setInsertCursorStyle(); + setInsertCursor(); } @@ -885,9 +885,9 @@ inline void FLineEdit::keyInsert() insert_mode = not insert_mode; if ( insert_mode ) - setInsertCursorStyle(); + setInsertCursor(); else - unsetInsertCursorStyle(); + unsetInsertCursor(); } //---------------------------------------------------------------------- diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 76f7d795..ff9adb54 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -28,6 +28,7 @@ #include "final/fmouse.h" #include "final/fterm.h" +#include "final/ftermxterminal.h" //---------------------------------------------------------------------- @@ -1632,23 +1633,11 @@ FMouse* FMouseControl::getMouseWithEvent() void FMouseControl::xtermMouse (bool on) { // activate/deactivate the xterm mouse support + if ( ! use_xterm_mouse ) return; - if ( on ) - putstring (CSI "?1001s" // save old highlight mouse tracking - CSI "?1000h" // enable x11 mouse tracking - CSI "?1002h" // enable cell motion mouse tracking - CSI "?1015h" // enable urxvt mouse mode - CSI "?1006h"); // enable SGR mouse mode - else - putstring (CSI "?1006l" // disable SGR mouse mode - CSI "?1015l" // disable urxvt mouse mode - CSI "?1002l" // disable cell motion mouse tracking - CSI "?1000l" // disable x11 mouse tracking - CSI "?1001r"); // restore old highlight mouse tracking - - std::fflush(stdout); + FTermXTerminal::setMouseSupport (on); } //---------------------------------------------------------------------- diff --git a/src/fterm.cpp b/src/fterm.cpp index 1d3df6e8..41a174bb 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -66,7 +66,7 @@ bool FTerm::utf8_input; bool FTerm::utf8_state; bool FTerm::utf8_console; bool FTerm::utf8_linux_terminal; -bool FTerm::force_vt100; +bool FTerm::force_vt100; // VT100 line drawing bool FTerm::vt100_console; bool FTerm::ascii_console; bool FTerm::NewFont; @@ -74,7 +74,7 @@ bool FTerm::VGAFont; bool FTerm::shadow_character; bool FTerm::half_block_character; bool FTerm::cursor_optimisation; -bool FTerm::xterm_default_colors; +bool FTerm::hidden_cursor; bool FTerm::use_alternate_screen = true; char FTerm::termtype[256] = {}; char FTerm::termfilename[256] = {}; @@ -87,11 +87,12 @@ FRect* FTerm::term = 0; char FTerm::exit_message[8192] = ""; fc::encoding FTerm::term_encoding; -const FString* FTerm::xterm_font = 0; -const FString* FTerm::xterm_title = 0; +const FString* FTerm::save_xterm_font = 0; +const FString* FTerm::save_xterm_title = 0; FOptiMove* FTerm::opti_move = 0; FOptiAttr* FTerm::opti_attr = 0; FTermDetection* FTerm::term_detection = 0; +FTermXTerminal* FTerm::xterm = 0; FMouseControl* FTerm::mouse = 0; std::map* FTerm::vt100_alt_char = 0; std::map* \ @@ -257,23 +258,40 @@ void FTerm::setTermType (char term_name[]) , std::strlen(term_name) + 1 ); } +//---------------------------------------------------------------------- +void FTerm::setInsertCursor (bool on) +{ + if ( on ) + setInsertCursorStyle(); + else + setOverwriteCursorStyle(); +} + +//---------------------------------------------------------------------- +void FTerm::redefineDefaultColors (bool on) +{ + xterm->redefineDefaultColors (on); +} + #if defined(__linux__) //---------------------------------------------------------------------- -void FTerm::setLinuxConsoleCursorStyle ( fc::linuxConsoleCursorStyle style - , bool hidden ) +char* FTerm::setLinuxConsoleCursorStyle ( fc::linuxConsoleCursorStyle style + , bool hidden ) { // Set cursor style in linux console + static char buf[16] = { }; + if ( ! isLinuxTerm() ) - return; + return buf; linux_console_cursor_style = style; if ( hidden ) - return; + return buf; - putstringf (CSI "?%dc", style); - std::fflush(stdout); + std::sprintf (buf, CSI "?%dc", style); + return buf; } #endif @@ -405,10 +423,7 @@ bool FTerm::setVGAFont() if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) { // Set font in xterm to vga - oscPrefix(); - putstring (OSC "50;vga" BEL); - oscPostfix(); - std::fflush(stdout); + xterm->setFont("vga"); NewFont = false; pc_charset_console = true; term_encoding = fc::PC; @@ -477,10 +492,7 @@ bool FTerm::setNewFont() { NewFont = true; // Set font in xterm to 8x16graph - oscPrefix(); - putstring (OSC "50;8x16graph" BEL); - oscPostfix(); - std::fflush(stdout); + xterm->setFont("8x16graph"); pc_charset_console = true; term_encoding = fc::PC; @@ -544,22 +556,17 @@ bool FTerm::setOldFont() if ( isXTerminal() || isScreenTerm() || isUrxvtTerminal() || FTermcap::osc_support ) { - if ( xterm_font && xterm_font->getLength() > 2 ) + if ( save_xterm_font && save_xterm_font->getLength() > 2 ) { // restore saved xterm font - oscPrefix(); - putstringf (OSC "50;%s" BEL, xterm_font->c_str() ); - oscPostfix(); + xterm->setFont(*save_xterm_font); } else { // Set font in xterm to vga - oscPrefix(); - putstring (OSC "50;vga" BEL); - oscPostfix(); + xterm->setFont("vga"); } - std::fflush(stdout); retval = true; } #if defined(__linux__) @@ -608,6 +615,34 @@ char* FTerm::moveCursor (int xold, int yold, int xnew, int ynew) return tgoto(TCAP(fc::t_cursor_address), xnew, ynew); } +//---------------------------------------------------------------------- +char* FTerm::cursorsVisibility (bool on) +{ + // Hides or shows the input cursor on the terminal + + char* visibility_str = 0; + + if ( on == hidden_cursor ) + return 0; + + if ( on ) + { + visibility_str = disableCursor(); + + if ( visibility_str ) + hidden_cursor = true; // global state + } + else + { + visibility_str = enableCursor(); + + if ( visibility_str ) + hidden_cursor = false; // global state + } + + return visibility_str; +} + //---------------------------------------------------------------------- void FTerm::printMoveDurations() { @@ -617,15 +652,30 @@ void FTerm::printMoveDurations() //---------------------------------------------------------------------- char* FTerm::enableCursor() { + static const std::size_t SIZE = 32; + static char enable_str[SIZE] = { }; char*& vs = TCAP(fc::t_cursor_visible); char*& ve = TCAP(fc::t_cursor_normal); if ( ve ) - return ve; + std::strncpy (enable_str, ve, SIZE - 1); else if ( vs ) - return vs; + std::strncpy (enable_str, vs, SIZE - 1); - return 0; +#if defined(__linux__) + if ( isLinuxTerm() ) + { + char* lcur; + lcur = setLinuxConsoleCursorStyle (getLinuxConsoleCursorStyle(), false); + std::strncat (enable_str, lcur, SIZE - std::strlen(enable_str) - 1); + } +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) + setFreeBSDConsoleCursorStyle (getFreeBSDConsoleCursorStyle(), false); +#endif + + return enable_str; } //---------------------------------------------------------------------- @@ -690,6 +740,12 @@ void FTerm::setTermSize (int term_width, int term_height) } } +//---------------------------------------------------------------------- +void FTerm::setTermTitle (const FString& title) +{ + xterm->setTitle (title); +} + //---------------------------------------------------------------------- void FTerm::setKDECursor (fc::kdeKonsoleCursorShape style) { @@ -704,419 +760,6 @@ void FTerm::setKDECursor (fc::kdeKonsoleCursorShape style) } } -//---------------------------------------------------------------------- -const FString* FTerm::getXTermFont() -{ - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - fd_set ifds; - struct timeval tv; - int stdin_no = FTermios::getStdIn(); - - oscPrefix(); - putstring (OSC "50;?" BEL); // get font - oscPostfix(); - std::fflush(stdout); - - FD_ZERO(&ifds); - FD_SET(stdin_no, &ifds); - tv.tv_sec = 0; - tv.tv_usec = 150000; // 150 ms - - // Read the terminal answer - if ( select(stdin_no + 1, &ifds, 0, 0, &tv) > 0 ) - { - char temp[150] = {}; - - if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 ) - { - FString* xtermfont; - std::size_t n = std::strlen(temp); - - // BEL + '\0' = string terminator - if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' ) - temp[n - 1] = '\0'; - - try - { - xtermfont = new FString(temp); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return 0; - } - - return xtermfont; - } - } - } - - return 0; -} - -//---------------------------------------------------------------------- -const FString* FTerm::getXTermTitle() -{ - if ( isKdeTerminal() ) - return 0; - - fd_set ifds; - struct timeval tv; - int stdin_no = FTermios::getStdIn(); - - putstring (CSI "21t"); // get title - std::fflush(stdout); - - FD_ZERO(&ifds); - FD_SET(stdin_no, &ifds); - tv.tv_sec = 0; - tv.tv_usec = 150000; // 150 ms - - // read the terminal answer - if ( select (stdin_no + 1, &ifds, 0, 0, &tv) > 0 ) - { - char temp[512] = {}; - - if ( std::scanf("\033]l%509[^\n]s", temp) == 1 ) - { - std::size_t n = std::strlen(temp); - - // Esc + \ = OSC string terminator - if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' ) - { - FString* xtermtitle; - - if ( n < 4 ) - return 0; - - temp[n - 2] = '\0'; - - try - { - xtermtitle = new FString(temp); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return 0; - } - - return xtermtitle; - } - } - } - - return 0; -} - -//---------------------------------------------------------------------- -void FTerm::setXTermCursorStyle (fc::xtermCursorStyle style) -{ - // Set the xterm cursor style - - if ( (isGnomeTerminal() && ! term_detection->hasSetCursorStyleSupport()) - || isKdeTerminal() ) - return; - -#if defined(__FreeBSD__) || defined(__DragonFly__) - if ( isFreeBSDConsole() ) - return; -#endif - - if ( TCAP(fc::t_cursor_style) - || isXTerminal() - || isMinttyTerm() - || term_detection->hasSetCursorStyleSupport() ) - { - putstringf (CSI "%d q", style); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermTitle (const FString& title) -{ - // Set the xterm title - if ( isXTerminal() || isScreenTerm() - || isMinttyTerm() || isPuttyTerminal() - || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "0;%s" BEL, title.c_str()); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermForeground (const FString& fg) -{ - // Set the VT100 text foreground color - if ( isXTerminal() || isScreenTerm() - || isMinttyTerm() || isMltermTerminal() - || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "10;%s" BEL, fg.c_str()); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermBackground (const FString& bg) -{ - // Set the VT100 text background color - if ( isXTerminal() || isScreenTerm() - || isMinttyTerm() || isMltermTerminal() - || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "11;%s" BEL, bg.c_str()); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermCursorColor (const FString& cc) -{ - // Set the text cursor color - if ( isXTerminal() || isScreenTerm() - || isMinttyTerm() || isUrxvtTerminal() - || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "12;%s" BEL, cc.c_str()); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermMouseForeground (const FString& mfg) -{ - // Set the mouse foreground color - if ( isXTerminal() || isScreenTerm() - || isUrxvtTerminal() || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "13;%s" BEL, mfg.c_str()); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermMouseBackground (const FString& mbg) -{ - // Set the mouse background color - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "14;%s" BEL, mbg.c_str()); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermHighlightBackground (const FString& hbg) -{ - // Set the highlight background color - if ( isXTerminal() || isScreenTerm() - || isUrxvtTerminal() || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "17;%s" BEL, hbg.c_str()); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::setXTermDefaults() -{ - if ( isPuttyTerminal() ) - return; - - setXTermMouseBackground("rgb:ffff/ffff/ffff"); - setXTermMouseForeground ("rgb:0000/0000/0000"); - - if ( ! isGnomeTerminal() ) - setXTermCursorColor("rgb:ffff/ffff/ffff"); - - if ( xterm_default_colors - && ! (isMinttyTerm() || isRxvtTerminal() || isScreenTerm()) ) - { - // mintty and rxvt can't reset these settings - setXTermBackground("rgb:8080/a4a4/ecec"); - setXTermForeground("rgb:0000/0000/0000"); - setXTermHighlightBackground("rgb:8686/8686/8686"); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermColors() -{ - // Reset the entire color table - - if ( isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) - return; - - if ( isPuttyTerminal() ) - return; - - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "104" BEL); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermForeground() -{ - // Reset the VT100 text foreground color - - if ( isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) - return; - - if ( isPuttyTerminal() ) - return; - - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - oscPrefix(); - putstring (OSC "110" BEL); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermBackground() -{ - // Reset the VT100 text background color - - if ( isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) - return; - - if ( isPuttyTerminal() ) - return; - - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - oscPrefix(); - putstring (OSC "111" BEL); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermCursorColor() -{ - // Reset the text cursor color - - if ( isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) - return; - - if ( isPuttyTerminal() ) - return; - - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - oscPrefix(); - putstring (OSC "112" BEL); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermMouseForeground() -{ - // Reset the mouse foreground color - - if ( isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) - return; - - if ( isPuttyTerminal() ) - return; - - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - oscPrefix(); - putstring (OSC "113" BEL); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermMouseBackground() -{ - // Reset the mouse background color - - if ( isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) - return; - - if ( isPuttyTerminal() ) - return; - - if ( isXTerminal() || isScreenTerm() || FTermcap::osc_support ) - { - oscPrefix(); - putstring (OSC "114" BEL); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermHighlightBackground() -{ - // Reset the highlight background color - - if ( isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) - return; - - if ( isPuttyTerminal() ) - return; - - if ( isXTerminal() || isScreenTerm() - || isUrxvtTerminal() || FTermcap::osc_support ) - { - oscPrefix(); - putstringf (OSC "117" BEL); - oscPostfix(); - std::fflush(stdout); - } -} - -//---------------------------------------------------------------------- -void FTerm::resetXTermDefaults() -{ - if ( isPuttyTerminal() ) - return; - - setXTermCursorColor("rgb:b1b1/b1b1/b1b1"); - resetXTermMouseForeground(); - resetXTermMouseBackground(); - resetXTermCursorColor(); - - if ( xterm_default_colors ) - { - resetXTermForeground(); - resetXTermBackground(); - resetXTermHighlightBackground(); - } -} - //---------------------------------------------------------------------- void FTerm::saveColorMap() { @@ -1250,8 +893,8 @@ void FTerm::setEncoding (fc::encoding enc) term_encoding = enc; assert ( term_encoding == fc::UTF8 - || term_encoding == fc::VT100 - || term_encoding == fc::PC + || term_encoding == fc::VT100 // VT100 line drawing + || term_encoding == fc::PC // CP-437 || term_encoding == fc::ASCII ); // Set the new Fputchar function pointer @@ -1462,71 +1105,25 @@ int FTerm::UTF8decode (const char utf8[]) // protected methods of FTerm //---------------------------------------------------------------------- -#if defined(__linux__) -void FTerm::initLinuxConsoleCharMap() +void FTerm::initScreenSettings() { - uInt c1, c2, c3, c4, c5; - - if ( NewFont || VGAFont ) - return; - - if ( screen_unicode_map.entry_ct != 0 ) - { - for (int i = 0; i <= fc::lastCharItem; i++ ) - { - bool found = false; - - for (uInt n = 0; n < screen_unicode_map.entry_ct; n++) - { - if ( fc::character[i][fc::UTF8] == screen_unicode_map.entries[n].unicode ) - { - found = true; - break; - } - } - - if ( ! found ) - fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; - } - } - - c1 = fc::UpperHalfBlock; - c2 = fc::LowerHalfBlock; - c3 = fc::FullBlock; - - if ( charEncode(c1, fc::PC) == charEncode(c1, fc::ASCII) - || charEncode(c2, fc::PC) == charEncode(c2, fc::ASCII) - || charEncode(c3, fc::PC) == charEncode(c3, fc::ASCII) ) - { - shadow_character = false; - } - - c4 = fc::RightHalfBlock; - c5 = fc::LeftHalfBlock; - - if ( charEncode(c4, fc::PC) == charEncode(c4, fc::ASCII) - || charEncode(c5, fc::PC) == charEncode(c5, fc::ASCII) ) - { - half_block_character = false; - } -} +#if defined(__linux__) + // Important: Do not use setNewFont() or setVGAFont() after + // the console character mapping has been initialized + initLinuxConsoleCharMap(); #endif #if defined(__FreeBSD__) || defined(__DragonFly__) -//---------------------------------------------------------------------- -void FTerm::initFreeBSDConsoleCharMap() -{ - // A FreeBSD console can't show ASCII codes from 0x00 to 0x1b - - if ( ! isFreeBSDConsole() ) - return; - - for (int i = 0; i <= fc::lastCharItem; i++ ) - if ( fc::character[i][fc::PC] < 0x1c ) - fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; -} + initFreeBSDConsoleCharMap(); #endif + // set xterm underline cursor + xterm->setCursorStyle (fc::blinking_underline); + + // set xterm color settings to defaults + xterm->setDefaults(); +} + //---------------------------------------------------------------------- bool FTerm::charEncodable (uInt c) { @@ -1562,20 +1159,6 @@ char* FTerm::changeAttribute ( char_data*& term_attr return opti_attr->changeAttribute (term_attr, next_attr); } -//---------------------------------------------------------------------- -void FTerm::xtermMetaSendsESC (bool on) -{ - // activate/deactivate the xterm meta key sends escape prefix - - if ( on ) - putstring (CSI "?1036s" // save meta key sends escape - CSI "?1036h"); // enable meta key sends escape - else - putstring (CSI "?1036r"); // restore meta key sends escape - - std::fflush(stdout); -} - //---------------------------------------------------------------------- void FTerm::exitWithMessage (std::string message) { @@ -2062,6 +1645,55 @@ void FTerm::initLinuxConsole() std::abort(); } } + +//---------------------------------------------------------------------- +void FTerm::initLinuxConsoleCharMap() +{ + uInt c1, c2, c3, c4, c5; + + if ( NewFont || VGAFont ) + return; + + if ( screen_unicode_map.entry_ct != 0 ) + { + for (int i = 0; i <= fc::lastCharItem; i++ ) + { + bool found = false; + + for (uInt n = 0; n < screen_unicode_map.entry_ct; n++) + { + if ( fc::character[i][fc::UTF8] == screen_unicode_map.entries[n].unicode ) + { + found = true; + break; + } + } + + if ( ! found ) + fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; + } + } + + c1 = fc::UpperHalfBlock; + c2 = fc::LowerHalfBlock; + c3 = fc::FullBlock; + + if ( charEncode(c1, fc::PC) == charEncode(c1, fc::ASCII) + || charEncode(c2, fc::PC) == charEncode(c2, fc::ASCII) + || charEncode(c3, fc::PC) == charEncode(c3, fc::ASCII) ) + { + shadow_character = false; + } + + c4 = fc::RightHalfBlock; + c5 = fc::LeftHalfBlock; + + if ( charEncode(c4, fc::PC) == charEncode(c4, fc::ASCII) + || charEncode(c5, fc::PC) == charEncode(c5, fc::ASCII) ) + { + half_block_character = false; + } +} #endif #if defined(__FreeBSD__) || defined(__DragonFly__) @@ -2132,6 +1764,19 @@ void FTerm::initFreeBSDConsole() setFreeBSDConsoleCursorStyle (fc::destructive_cursor, true); } } + +//---------------------------------------------------------------------- +void FTerm::initFreeBSDConsoleCharMap() +{ + // A FreeBSD console can't show ASCII codes from 0x00 to 0x1b + + if ( ! isFreeBSDConsole() ) + return; + + for (int i = 0; i <= fc::lastCharItem; i++ ) + if ( fc::character[i][fc::PC] < 0x1c ) + fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; +} #endif #if defined(__NetBSD__) || defined(__OpenBSD__) @@ -2205,6 +1850,7 @@ void FTerm::init_global_values() cursor_optimisation = true; // Preset to false + hidden_cursor = \ utf8_console = \ utf8_input = \ utf8_state = \ @@ -2214,16 +1860,19 @@ void FTerm::init_global_values() NewFont = \ VGAFont = \ ascii_console = \ - force_vt100 = \ - xterm_default_colors = false; + force_vt100 = false; // Assertion: programm start in cooked mode - input_data_pending = \ - non_blocking_stdin = false; + input_data_pending = \ + non_blocking_stdin = false; // Init arrays with '\0' std::fill_n (exit_message, sizeof(exit_message), '\0'); + // Initialize xterm object + xterm->setTermcapMap(tcap); + xterm->setFTermDetection(term_detection); + // Initialize the structs color_env.setDefault(); secondary_da.setDefault(); @@ -2260,13 +1909,13 @@ void FTerm::oscPostfix() //---------------------------------------------------------------------- void FTerm::init_alt_charset() { - // Read the used vt100 pairs + // Read the used VT100 pairs if ( TCAP(fc::t_acs_chars) ) { for (int n = 0; TCAP(fc::t_acs_chars)[n]; n += 2) { - // insert the vt100 key/value pairs into a map + // insert the VT100 key/value pairs into a map uChar p1 = uChar(TCAP(fc::t_acs_chars)[n]); uChar p2 = uChar(TCAP(fc::t_acs_chars)[n + 1]); (*vt100_alt_char)[p1] = p2; @@ -2279,7 +1928,7 @@ void FTerm::init_alt_charset() utf8_char = 1 }; - // Update array 'character' with discovered vt100 pairs + // Update array 'character' with discovered VT100 pairs for (int n = 0; n <= fc::lastKeyItem; n++ ) { uChar keyChar = uChar(fc::vt100_key_to_utf8[n][vt100_key]); @@ -2297,7 +1946,7 @@ void FTerm::init_alt_charset() if ( altChar ) fc::character[item][fc::VT100] = altChar; // update alternate character set else - fc::character[item][fc::VT100] = 0; // delete vt100 char in character + fc::character[item][fc::VT100] = 0; // delete VT100 char in character } } } @@ -2547,10 +2196,10 @@ void FTerm::init_termcap_numerics() FTermcap::max_color = std::max( FTermcap::max_color , tgetnum(C_STR("Co")) ); - if ( FTermcap::max_color < 0 ) + if ( getMaxColor() < 0 ) FTermcap::max_color = 1; - if ( FTermcap::max_color < 8 ) + if ( getMaxColor() < 8 ) monochron = true; else monochron = false; @@ -2800,7 +2449,7 @@ void FTerm::init_encoding() init_encoding_set(); - if ( isRxvtTerminal() ) + if ( isRxvtTerminal() && ! isUrxvtTerminal() ) force_vt100 = true; // This rxvt terminal does not support utf-8 init_term_encoding(); @@ -2825,8 +2474,8 @@ inline void FTerm::init_encoding_set() (*encoding_set)["UTF8"] = fc::UTF8; (*encoding_set)["UTF-8"] = fc::UTF8; - (*encoding_set)["VT100"] = fc::VT100; - (*encoding_set)["PC"] = fc::PC; + (*encoding_set)["VT100"] = fc::VT100; // VT100 line drawing + (*encoding_set)["PC"] = fc::PC; // CP-437 (*encoding_set)["ASCII"] = fc::ASCII; } @@ -2887,7 +2536,7 @@ void FTerm::init_individual_term_encoding() //---------------------------------------------------------------------- bool FTerm::init_force_vt100_encoding() { - if ( force_vt100 ) + if ( force_vt100 ) // Force VT100 line drawing { vt100_console = true; term_encoding = fc::VT100; @@ -2943,7 +2592,7 @@ void FTerm::redefineColorPalette() resetColorMap(); saveColorMap(); - if ( FTermcap::max_color >= 16 ) + if ( getMaxColor() >= 16 ) FColorPalette::set16ColorPalette (FTerm::setPalette); else // 8 colors FColorPalette::set8ColorPalette (FTerm::setPalette); @@ -2962,15 +2611,51 @@ void FTerm::restoreColorPalette() return; // Reset screen settings - if ( FTermcap::max_color >= 16 ) + if ( getMaxColor() >= 16 ) FColorPalette::reset16ColorPalette (FTerm::setPalette); else // 8 colors FColorPalette::reset8ColorPalette (FTerm::setPalette); - resetXTermColors(); + xterm->resetColorMap(); resetColorMap(); } +//---------------------------------------------------------------------- +void FTerm::setInsertCursorStyle() +{ + xterm->setCursorStyle (fc::blinking_underline); + setKDECursor(fc::UnderlineCursor); + +#if defined(__linux__) + setLinuxConsoleCursorStyle (fc::underscore_cursor, isCursorHidden()); +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) + setFreeBSDConsoleCursorStyle (fc::destructive_cursor, isCursorHidden()); +#endif + + if ( isUrxvtTerminal() ) + xterm->setCursorColor ("rgb:ffff/ffff/ffff"); +} + +//---------------------------------------------------------------------- +void FTerm::setOverwriteCursorStyle() +{ + xterm->setCursorStyle (fc::steady_block); + setKDECursor(fc::BlockCursor); + +#if defined(__linux__) + setLinuxConsoleCursorStyle (fc::full_block_cursor, isCursorHidden()); +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) + setFreeBSDConsoleCursorStyle (fc::normal_cursor, isCursorHidden()); +#endif + + if ( isUrxvtTerminal() ) + xterm->setCursorColor ("rgb:eeee/0000/0000"); +} + //---------------------------------------------------------------------- void FTerm::enableMouse() { @@ -3047,18 +2732,6 @@ void FTerm::useNormalScreenBuffer() } } -//---------------------------------------------------------------------- -void FTerm::captureXTermFontAndTitle() -{ - if ( (isXTerminal() || isUrxvtTerminal()) && ! isRxvtTerminal() ) - { - FTermios::setCaptureSendCharacters(); - xterm_font = getXTermFont(); - xterm_title = getXTermTitle(); - FTermios::unsetCaptureSendCharacters(); - } -} - //---------------------------------------------------------------------- inline void FTerm::allocationValues() { @@ -3067,6 +2740,7 @@ inline void FTerm::allocationValues() opti_move = new FOptiMove(); opti_attr = new FOptiAttr(); term_detection = new FTermDetection(); + xterm = new FTermXTerminal(); mouse = new FMouseControl(); term = new FRect(0, 0, 0, 0); vt100_alt_char = new std::map; @@ -3088,11 +2762,11 @@ inline void FTerm::deallocationValues() if ( vt100_alt_char ) delete vt100_alt_char; - if ( xterm_title ) - delete xterm_title; + if ( save_xterm_title ) + delete save_xterm_title; - if ( xterm_font ) - delete xterm_font; + if ( save_xterm_font ) + delete save_xterm_font; if ( term ) delete term; @@ -3100,6 +2774,9 @@ inline void FTerm::deallocationValues() if ( mouse ) delete mouse; + if ( xterm ) + delete xterm; + if ( term_detection ) delete term_detection; @@ -3168,7 +2845,7 @@ void FTerm::init() // Activate meta key sends escape if ( isXTerminal() ) - xtermMetaSendsESC(true); + xterm->metaSendsESC(true); // switch to application escape key mode if ( isMinttyTerm() ) @@ -3191,7 +2868,9 @@ void FTerm::init() } // Save the used xterm font and window title - captureXTermFontAndTitle(); + xterm->captureFontAndTitle(); + save_xterm_font = new FString(*(xterm->getFont())); + save_xterm_title = new FString(*(xterm->getTitle())); if ( isKdeTerminal() ) setKDECursor(fc::UnderlineCursor); @@ -3254,8 +2933,8 @@ void FTerm::finish() // Set default signal handler resetSignalHandler(); - if ( xterm_title && isXTerminal() && ! isRxvtTerminal() ) - setXTermTitle (*xterm_title); + if ( save_xterm_title && isXTerminal() && ! isRxvtTerminal() ) + setTermTitle (*save_xterm_title); // Restore the saved termios settings FTermios::restoreTTYsettings(); @@ -3275,10 +2954,10 @@ void FTerm::finish() } // Reset xterm color settings to default values - resetXTermDefaults(); + xterm->resetDefaults(); // Set xterm full block cursor - setXTermCursorStyle(fc::steady_block); + xterm->setCursorStyle (fc::steady_block); // Restore the color palette if ( init_values.color_change ) @@ -3303,7 +2982,7 @@ void FTerm::finish() // Deactivate meta key sends escape if ( isXTerminal() ) - xtermMetaSendsESC(false); + xterm->metaSendsESC(false); useNormalScreenBuffer(); diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index ddcf8c12..b8d9f068 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -179,7 +179,7 @@ void FTermcapQuirks::init_termcap_linux_quirks() /* Same settings are used by cygwin */ // Set ansi foreground and background color - if ( FTermcap::max_color > 8 ) + if ( FTerm::getMaxColor() > 8 ) { TCAP(fc::t_set_a_foreground) = \ C_STR(CSI "3%p1%{8}%m%d%?%p1%{7}%>%t;1%e;22%;m"); diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp new file mode 100644 index 00000000..69a953b6 --- /dev/null +++ b/src/ftermxterminal.cpp @@ -0,0 +1,926 @@ +/*********************************************************************** +* ftermxterminal.cpp - Contains all xterm-specific terminal functions * +* * +* This file is part of the Final Cut widget toolkit * +* * +* Copyright 2018 Markus Gans * +* * +* The Final Cut is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Lesser General Public License * +* as published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* The Final Cut is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +#include "final/fterm.h" +#include "final/ftermxterminal.h" + +// static class attributes +bool FTermXTerminal::mouse_support; +bool FTermXTerminal::meta_sends_esc; +bool FTermXTerminal::xterm_default_colors; +FTermcap::tcap_map* FTermXTerminal::tcap = 0; +FTermDetection* FTermXTerminal::term_detection = 0; +fc::xtermCursorStyle FTermXTerminal::cursor_style = fc::unknown_cursor_style; +const FString* FTermXTerminal::xterm_font = 0; +const FString* FTermXTerminal::xterm_title = 0; +const FString* FTermXTerminal::foreground_color = 0; +const FString* FTermXTerminal::background_color = 0; +const FString* FTermXTerminal::cursor_color = 0; +const FString* FTermXTerminal::mouse_foreground_color = 0; +const FString* FTermXTerminal::mouse_background_color = 0; +const FString* FTermXTerminal::highlight_background_color = 0; + + +//---------------------------------------------------------------------- +// class FTermXTerminal +//---------------------------------------------------------------------- + +// constructors and destructor +//---------------------------------------------------------------------- +FTermXTerminal::FTermXTerminal() +{ + // Preset to false + mouse_support = \ + meta_sends_esc = \ + xterm_default_colors = false; +} + +//---------------------------------------------------------------------- +FTermXTerminal::~FTermXTerminal() // destructor +{ + if ( highlight_background_color ) + delete highlight_background_color; + + if ( mouse_background_color ) + delete mouse_background_color; + + if ( mouse_foreground_color ) + delete mouse_foreground_color; + + if ( cursor_color ) + delete cursor_color; + + if ( background_color ) + delete background_color; + + if ( foreground_color ) + delete foreground_color; + + if ( xterm_title ) + delete xterm_title; + + if ( xterm_font ) + delete xterm_font; +} + + +// public methods of FTermXTerminal +//---------------------------------------------------------------------- +void FTermXTerminal::setCursorStyle (fc::xtermCursorStyle style) +{ + // Set the xterm cursor style + + cursor_style = style; + setXTermCursorStyle(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setFont (const FString& fontname) +{ + // Change the XTerm font (needs the allowFontOps resource) + + if ( xterm_font ) + delete xterm_font; + + xterm_font = new FString(fontname); + setXTermFont(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setTitle (const FString& title) +{ + // Set the xterm title + + if ( xterm_title ) + delete xterm_title; + + xterm_title = new FString(title); + setXTermTitle(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setForeground (const FString& fg) +{ + // Set the XTerm text foreground color + + if ( foreground_color ) + delete foreground_color; + + foreground_color = new FString(fg); + setXTermForeground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setBackground (const FString& bg) +{ + // Set the XTerm text background color + + if ( background_color ) + delete background_color; + + background_color = new FString(bg); + setXTermBackground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setCursorColor (const FString& cc) +{ + // Set the text cursor color + + if ( cursor_color ) + delete cursor_color; + + cursor_color = new FString(cc); + setXTermCursorColor(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setMouseForeground (const FString& mfg) +{ + // Set the mouse foreground color + + if ( mouse_foreground_color ) + delete mouse_foreground_color; + + mouse_foreground_color = new FString(mfg); + setXTermMouseForeground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setMouseBackground (const FString& mbg) +{ + // Set the mouse background color + + if ( mouse_background_color ) + delete mouse_background_color; + + mouse_background_color = new FString(mbg); + setXTermMouseBackground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setHighlightBackground (const FString& hbg) +{ + // Set the highlight background color + + if ( highlight_background_color ) + delete highlight_background_color; + + highlight_background_color = new FString(hbg); + setXTermHighlightBackground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setMouseSupport (bool on) +{ + // activate/deactivate the xterm mouse support + + if ( on ) + enableXTermMouse(); + else + disableXTermMouse(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::metaSendsESC (bool on) +{ + // activate/deactivate the xterm meta key sends escape prefix + + if ( on ) + enableXTermMetaSendsESC(); + else + disableXTermMetaSendsESC(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setDefaults() +{ + // Redefinition of the XTerm default colors + // for the final cut color theme + + if ( FTerm::getMaxColor() >= 16 ) + setXTerm16ColorDefaults(); + else + setXTerm8ColorDefaults(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetColorMap() +{ + // Reset the entire color table + + resetXTermColorMap(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetForeground() +{ + // Reset the XTerm text foreground color + + if ( foreground_color ) + delete foreground_color; + + foreground_color = 0; + resetXTermForeground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetBackground() +{ + // Reset the XTerm text background color + + if ( background_color ) + delete background_color; + + background_color = 0; + resetXTermBackground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetCursorColor() +{ + // Reset the text cursor color + + if ( cursor_color ) + delete cursor_color; + + cursor_color = 0; + resetXTermCursorColor(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetMouseForeground() +{ + // Reset the mouse foreground color + + if ( mouse_foreground_color ) + delete mouse_foreground_color; + + mouse_foreground_color = 0; + resetXTermMouseForeground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetMouseBackground() +{ + // Reset the mouse background color + + if ( mouse_background_color ) + delete mouse_background_color; + + mouse_background_color = 0; + resetXTermMouseBackground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetHighlightBackground() +{ + // Reset the highlight background color + + if ( highlight_background_color ) + delete highlight_background_color; + + highlight_background_color = 0; + resetXTermHighlightBackground(); +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetDefaults() +{ + if ( term_detection->isPuttyTerminal() ) + return; + + // Redefines the cursor color if resetCursorColor() doesn't work + setCursorColor("rgb:b1b1/b1b1/b1b1"); + // Reset mouse color to default + resetMouseForeground(); + resetMouseBackground(); + // Reset text cursor color to default + resetCursorColor(); + + if ( xterm_default_colors ) + { + // Reset text foreground, text background, and mouse text highlight + // colors to default values + resetForeground(); + resetBackground(); + resetHighlightBackground(); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::captureFontAndTitle() +{ + if ( ( term_detection->isXTerminal() + || term_detection->isUrxvtTerminal() ) + && ! term_detection->isRxvtTerminal() ) + { + if ( xterm_font ) + delete xterm_font; + + if ( xterm_title ) + delete xterm_title; + + FTermios::setCaptureSendCharacters(); + xterm_font = captureXTermFont(); + xterm_title = captureXTermTitle(); + FTermios::unsetCaptureSendCharacters(); + } +} + + +// private methods of FTermXTerminal +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermCursorStyle() +{ + // Set the xterm cursor style + +#if defined(__FreeBSD__) || defined(__DragonFly__) + if ( FTerm::isFreeBSDConsole() ) + return; +#endif + + if ( term_detection->isGnomeTerminal() + && ! term_detection->hasSetCursorStyleSupport() ) + return; + + if ( term_detection->isKdeTerminal() ) + return; + + if ( TCAP(fc::t_cursor_style) + || term_detection->isXTerminal() + || term_detection->isMinttyTerm() + || term_detection->hasSetCursorStyleSupport() ) + { + FTerm::putstringf (CSI "%d q", cursor_style); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermTitle() +{ + // Set the xterm title + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isMinttyTerm() + || term_detection->isPuttyTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "0;%s" BEL, xterm_title->c_str()); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermFont() +{ + // Change the XTerm font (needs the allowFontOps resource) + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isUrxvtTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "50;%s" BEL, xterm_font->c_str() ); + oscPostfix(); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermForeground() +{ + // Set the XTerm text foreground color + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isMinttyTerm() + || term_detection->isMltermTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "10;%s" BEL, foreground_color->c_str()); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermBackground() +{ + // Set the XTerm text background color + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isMinttyTerm() + || term_detection->isMltermTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "11;%s" BEL, background_color->c_str()); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermCursorColor() +{ + // Set the text cursor color + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isMinttyTerm() + || term_detection->isUrxvtTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "12;%s" BEL, cursor_color->c_str()); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermMouseForeground() +{ + // Set the mouse foreground color + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isUrxvtTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "13;%s" BEL, mouse_foreground_color->c_str()); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermMouseBackground() +{ + // Set the mouse background color + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "14;%s" BEL, mouse_background_color->c_str()); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTermHighlightBackground() +{ + // Set the highlight background color + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isUrxvtTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "17;%s" BEL, highlight_background_color->c_str()); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTerm8ColorDefaults() +{ + // Redefinition of the XTerm default colors + // for the final cut 8 color theme + + if ( term_detection->isPuttyTerminal() ) + return; + + setMouseBackground("rgb:ffff/ffff/ffff"); // white + setMouseForeground ("rgb:0000/0000/0000"); // black + + if ( ! term_detection->isGnomeTerminal() ) + setCursorColor("rgb:ffff/ffff/ffff"); // white + + if ( xterm_default_colors + && ! (term_detection->isMinttyTerm() + || term_detection->isRxvtTerminal() + || term_detection->isScreenTerm()) ) + { + // mintty and rxvt can't reset these settings + setBackground("rgb:2222/2222/b2b2"); // blue + setForeground("rgb:0000/0000/0000"); // black + setHighlightBackground("rgb:8787/8787/8787"); // gray53 + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::setXTerm16ColorDefaults() +{ + // Redefinition of the XTerm default colors + // for the final cut 16 color theme + + if ( term_detection->isPuttyTerminal() ) + return; + + setMouseBackground("rgb:ffff/ffff/ffff"); // white + setMouseForeground ("rgb:0000/0000/0000"); // black + + if ( ! term_detection->isGnomeTerminal() ) + setCursorColor("rgb:ffff/ffff/ffff"); // white + + if ( xterm_default_colors + && ! (term_detection->isMinttyTerm() + || term_detection->isRxvtTerminal() + || term_detection->isScreenTerm()) ) + { + // mintty and rxvt can't reset these settings + setBackground("rgb:8080/a4a4/ecec"); // very light blue + setForeground("rgb:0000/0000/0000"); // black + setHighlightBackground("rgb:8787/8787/8787"); // gray53 + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetXTermColorMap() +{ + // Reset the entire color table + + if ( term_detection->isGnomeTerminal() + && term_detection->getGnomeTerminalID() < 3502 ) + return; + + if ( term_detection->isPuttyTerminal() ) + return; + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "104" BEL); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetXTermForeground() +{ + // Reset the XTerm text foreground color + + if ( term_detection->isGnomeTerminal() + && term_detection->getGnomeTerminalID() < 3502 ) + return; + + if ( term_detection->isPuttyTerminal() ) + return; + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstring (OSC "110" BEL); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetXTermBackground() +{ + // Reset the XTerm text background color + + if ( term_detection->isGnomeTerminal() + && term_detection->getGnomeTerminalID() < 3502 ) + return; + + if ( term_detection->isPuttyTerminal() ) + return; + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstring (OSC "111" BEL); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetXTermCursorColor() +{ + // Reset the text cursor color + + if ( term_detection->isGnomeTerminal() + && term_detection->getGnomeTerminalID() < 3502 ) + return; + + if ( term_detection->isPuttyTerminal() ) + return; + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstring (OSC "112" BEL); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetXTermMouseForeground() +{ + // Reset the mouse foreground color + + if ( term_detection->isGnomeTerminal() + && term_detection->getGnomeTerminalID() < 3502 ) + return; + + if ( term_detection->isPuttyTerminal() ) + return; + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstring (OSC "113" BEL); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetXTermMouseBackground() +{ + // Reset the mouse background color + + if ( term_detection->isGnomeTerminal() + && term_detection->getGnomeTerminalID() < 3502 ) + return; + + if ( term_detection->isPuttyTerminal() ) + return; + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstring (OSC "114" BEL); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::resetXTermHighlightBackground() +{ + // Reset the highlight background color + + if ( term_detection->isGnomeTerminal() + && term_detection->getGnomeTerminalID() < 3502 ) + return; + + if ( term_detection->isPuttyTerminal() ) + return; + + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || term_detection->isUrxvtTerminal() + || FTermcap::osc_support ) + { + oscPrefix(); + FTerm::putstringf (OSC "117" BEL); + oscPostfix(); + std::fflush(stdout); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::oscPrefix() +{ + if ( term_detection->isTmuxTerm() ) + { + // tmux device control string + FTerm::putstring (ESC "Ptmux;" ESC); + } + else if ( term_detection->isScreenTerm() ) + { + // GNU Screen device control string + FTerm::putstring (ESC "P"); + } +} + +//---------------------------------------------------------------------- +void FTermXTerminal::oscPostfix() +{ + if ( term_detection->isScreenTerm() + || term_detection->isTmuxTerm() ) + { + // GNU Screen/tmux string terminator + FTerm::putstring (ESC "\\"); + } +} + +//---------------------------------------------------------------------- +const FString* FTermXTerminal::captureXTermFont() +{ + if ( term_detection->isXTerminal() + || term_detection->isScreenTerm() + || FTermcap::osc_support ) + { + fd_set ifds; + struct timeval tv; + int stdin_no = FTermios::getStdIn(); + + oscPrefix(); + FTerm::putstring (OSC "50;?" BEL); // get font + oscPostfix(); + std::fflush(stdout); + + FD_ZERO(&ifds); + FD_SET(stdin_no, &ifds); + tv.tv_sec = 0; + tv.tv_usec = 150000; // 150 ms + + // Read the terminal answer + if ( select(stdin_no + 1, &ifds, 0, 0, &tv) > 0 ) + { + char temp[150] = {}; + + if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 ) + { + FString* xtermfont; + std::size_t n = std::strlen(temp); + + // BEL + '\0' = string terminator + if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' ) + temp[n - 1] = '\0'; + + try + { + xtermfont = new FString(temp); + } + catch (const std::bad_alloc& ex) + { + std::cerr << "not enough memory to alloc " << ex.what() << std::endl; + return 0; + } + + return xtermfont; + } + } + } + + return 0; +} + +//---------------------------------------------------------------------- +const FString* FTermXTerminal::captureXTermTitle() +{ + if ( term_detection->isKdeTerminal() ) + return 0; + + fd_set ifds; + struct timeval tv; + int stdin_no = FTermios::getStdIn(); + + FTerm::putstring (CSI "21t"); // get title + std::fflush(stdout); + + FD_ZERO(&ifds); + FD_SET(stdin_no, &ifds); + tv.tv_sec = 0; + tv.tv_usec = 150000; // 150 ms + + // read the terminal answer + if ( select (stdin_no + 1, &ifds, 0, 0, &tv) > 0 ) + { + char temp[512] = {}; + + if ( std::scanf("\033]l%509[^\n]s", temp) == 1 ) + { + std::size_t n = std::strlen(temp); + + // Esc + \ = OSC string terminator + if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' ) + { + FString* xtermtitle; + + if ( n < 4 ) + return 0; + + temp[n - 2] = '\0'; + + try + { + xtermtitle = new FString(temp); + } + catch (const std::bad_alloc& ex) + { + std::cerr << "not enough memory to alloc " << ex.what() << std::endl; + return 0; + } + + return xtermtitle; + } + } + } + + return 0; +} + +//---------------------------------------------------------------------- +void FTermXTerminal::enableXTermMouse() +{ + // activate the xterm mouse support + + if ( mouse_support ) + return; + + FTerm::putstring (CSI "?1001s" // save old highlight mouse tracking + CSI "?1000h" // enable x11 mouse tracking + CSI "?1002h" // enable cell motion mouse tracking + CSI "?1015h" // enable urxvt mouse mode + CSI "?1006h"); // enable SGR mouse mode + std::fflush(stdout); + mouse_support = true; +} + +//---------------------------------------------------------------------- +void FTermXTerminal::disableXTermMouse() +{ + // deactivate the xterm mouse support + + if ( ! mouse_support ) + return; + + FTerm::putstring (CSI "?1006l" // disable SGR mouse mode + CSI "?1015l" // disable urxvt mouse mode + CSI "?1002l" // disable cell motion mouse tracking + CSI "?1000l" // disable x11 mouse tracking + CSI "?1001r"); // restore old highlight mouse tracking + std::fflush(stdout); + mouse_support = false; +} + +//---------------------------------------------------------------------- +void FTermXTerminal::enableXTermMetaSendsESC() +{ + // activate the xterm meta key sends escape prefix + + if ( meta_sends_esc ) + return; + + FTerm::putstring (CSI "?1036s" // save meta key sends escape + CSI "?1036h"); // enable meta key sends escape + std::fflush(stdout); + meta_sends_esc = true; +} + +//---------------------------------------------------------------------- +void FTermXTerminal::disableXTermMetaSendsESC() +{ + // deactivate the xterm meta key sends escape prefix + + if ( ! meta_sends_esc ) + return; + + FTerm::putstring (CSI "?1036r"); // restore meta key sends escape + std::fflush(stdout); + meta_sends_esc = false; +} diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 2806943c..98fb49e5 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -33,7 +33,6 @@ static FVTerm* init_object = 0; // static class attributes -bool FVTerm::hidden_cursor; bool FVTerm::terminal_update_complete; bool FVTerm::terminal_update_pending; bool FVTerm::force_terminal_update; @@ -131,46 +130,16 @@ void FVTerm::setTermXY (register int x, register int y) } //---------------------------------------------------------------------- -bool FVTerm::hideCursor (bool on) +void FVTerm::hideCursor (bool on) { // Hides or shows the input cursor on the terminal - if ( on == hidden_cursor ) - return hidden_cursor; - if ( on ) - { - char* hide_str = disableCursor(); + char* visibility_str = cursorsVisibility (on); - if ( hide_str ) - { - appendOutputBuffer (hide_str); - hidden_cursor = true; // global - } - } - else - { - char* show_str = enableCursor(); - - if ( show_str ) - { - appendOutputBuffer (show_str); - hidden_cursor = false; - } - } + if ( visibility_str ) + appendOutputBuffer(visibility_str); flush_out(); - -#if defined(__linux__) - if ( ! hidden_cursor && isLinuxTerm() ) - setLinuxConsoleCursorStyle (getLinuxConsoleCursorStyle(), false); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) - if ( ! hidden_cursor ) - setFreeBSDConsoleCursorStyle (getFreeBSDConsoleCursorStyle(), false); -#endif - - return hidden_cursor; } //---------------------------------------------------------------------- @@ -713,43 +682,6 @@ FVTerm::term_area* FVTerm::getPrintArea() return vdesktop; } -//---------------------------------------------------------------------- -void FVTerm::setInsertCursorStyle (bool on) -{ - if ( on ) - { - setXTermCursorStyle(fc::blinking_underline); - setKDECursor(fc::UnderlineCursor); - -#if defined(__linux__) - setLinuxConsoleCursorStyle (fc::underscore_cursor, isCursorHidden()); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) - setFreeBSDConsoleCursorStyle (fc::destructive_cursor, isCursorHidden()); -#endif - - if ( isUrxvtTerminal() ) - setXTermCursorColor("rgb:ffff/ffff/ffff"); - } - else - { - setXTermCursorStyle(fc::steady_block); - setKDECursor(fc::BlockCursor); - -#if defined(__linux__) - setLinuxConsoleCursorStyle (fc::full_block_cursor, isCursorHidden()); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) - setFreeBSDConsoleCursorStyle (fc::normal_cursor, isCursorHidden()); -#endif - - if ( isUrxvtTerminal() ) - setXTermCursorColor("rgb:eeee/0000/0000"); - } -} - //---------------------------------------------------------------------- void FVTerm::createArea ( const FRect& r , const FPoint& p @@ -2134,7 +2066,6 @@ void FVTerm::init() } // Preset to false - hidden_cursor = \ terminal_update_pending = \ force_terminal_update = \ stop_terminal_updates = false; diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 93c497aa..693aea81 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1160,21 +1160,8 @@ void FWidget::show() if ( ! init_desktop ) { -#if defined(__linux__) - // Important: Do not use setNewFont() or setVGAFont() after - // the console character mapping has been initialized - initLinuxConsoleCharMap(); -#endif - -#if defined(__FreeBSD__) || defined(__DragonFly__) - initFreeBSDConsoleCharMap(); -#endif - - // set xterm underline cursor - setXTermCursorStyle(fc::blinking_underline); - - // set xterm color settings to defaults - setXTermDefaults(); + // Sets the initial screen settings + initScreenSettings(); // draw the vdesktop FWidget* r = getRootWidget(); diff --git a/src/test/fstring-test.cpp b/src/test/fstring-test.cpp index 7536368f..71e358ee 100644 --- a/src/test/fstring-test.cpp +++ b/src/test/fstring-test.cpp @@ -150,8 +150,8 @@ void FStringTest::tearDown() //---------------------------------------------------------------------- void FStringTest::classNameTest() { - FString s; - const char* const classname = s.getClassName(); + FString str; + const char* const classname = str.getClassName(); CPPUNIT_ASSERT ( std::strcmp(classname, "FString") == 0 ); } @@ -1379,7 +1379,7 @@ void FStringTest::insertTest() void FStringTest::replaceTest() { const FString str = "Look behind you, a three-headed monkey!"; - FString s = str; + FString s1 = str; const FString from1 = "three"; const std::wstring from2 = L"three"; const wchar_t from3[] = L"three"; @@ -1395,184 +1395,184 @@ void FStringTest::replaceTest() const wchar_t to6 = '3'; const char to7 = '3'; - CPPUNIT_ASSERT ( s.replace(from1, to1) + CPPUNIT_ASSERT ( s1.replace(from1, to1) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from1, to2) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from1, to2) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from1, to3) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from1, to3) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from1, to4) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from1, to4) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from1, to5) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from1, to5) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from1, to6) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from1, to6) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from1, to7) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from1, to7) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from2, to1) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from2, to1) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from2, to2) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from2, to2) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from2, to3) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from2, to3) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from2, to4) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from2, to4) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from2, to5) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from2, to5) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from2, to6) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from2, to6) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from2, to7) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from2, to7) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from3, to1) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from3, to1) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from3, to2) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from3, to2) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from3, to3) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from3, to3) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from3, to4) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from3, to4) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from3, to5) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from3, to5) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from3, to6) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from3, to6) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from3, to7) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from3, to7) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from4, to1) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from4, to1) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from4, to2) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from4, to2) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from4, to3) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from4, to3) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from4, to4) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from4, to4) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from4, to5) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from4, to5) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from4, to6) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from4, to6) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from4, to7) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from4, to7) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from5, to1) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from5, to1) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from5, to2) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from5, to2) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from5, to3) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from5, to3) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from5, to4) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from5, to4) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from5, to5) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from5, to5) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from5, to6) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from5, to6) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from5, to7) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from5, to7) == "Look behind you, a 3-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from6, to1) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from6, to1) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from6, to2) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from6, to2) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from6, to3) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from6, to3) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from6, to4) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from6, to4) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from6, to5) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from6, to5) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from6, to6) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from6, to6) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from6, to7) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from6, to7) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from7, to1) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from7, to1) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from7, to2) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from7, to2) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from7, to3) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from7, to3) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from7, to4) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from7, to4) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from7, to5) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from7, to5) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from7, to6) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from7, to6) == "Look behind you3 a three-headed monkey!" ); - s = str; - CPPUNIT_ASSERT ( s.replace(from7, to7) + s1 = str; + CPPUNIT_ASSERT ( s1.replace(from7, to7) == "Look behind you3 a three-headed monkey!" ); - s = "A big ball and a small ball"; - CPPUNIT_ASSERT ( s.replace("ball", "globe") + s1 = "A big ball and a small ball"; + CPPUNIT_ASSERT ( s1.replace("ball", "globe") == "A big globe and a small globe" ); - s = "ABC"; + s1 = "ABC"; FString empty; - CPPUNIT_ASSERT ( s.replace('B', "") == "AC" ); - CPPUNIT_ASSERT ( s.replace(L'B', "") == "AC" ); - CPPUNIT_ASSERT ( s.replace(from1, empty) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(from3, empty) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(from5, to5) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(empty, to1) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(from6, empty) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace('B', "") == "AC" ); + CPPUNIT_ASSERT ( s1.replace(L'B', "") == "AC" ); + CPPUNIT_ASSERT ( s1.replace(from1, empty) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(from3, empty) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(from5, to5) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(empty, to1) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(from6, empty) == "ABC" ); empty = ""; - CPPUNIT_ASSERT ( s.replace(from1, empty) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(from3, empty) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(from5, to5) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(empty, to1) == "ABC" ); - CPPUNIT_ASSERT ( s.replace(from6, empty) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(from1, empty) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(from3, empty) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(from5, to5) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(empty, to1) == "ABC" ); + CPPUNIT_ASSERT ( s1.replace(from6, empty) == "ABC" ); - s.clear(); - CPPUNIT_ASSERT ( s.replace(from1, to1).isNull() ); - CPPUNIT_ASSERT ( s.replace(from1, to1).isEmpty() ); - CPPUNIT_ASSERT ( s.replace(from6, to1).isNull() ); - CPPUNIT_ASSERT ( s.replace(from6, to1).isEmpty() ); + s1.clear(); + CPPUNIT_ASSERT ( s1.replace(from1, to1).isNull() ); + CPPUNIT_ASSERT ( s1.replace(from1, to1).isEmpty() ); + CPPUNIT_ASSERT ( s1.replace(from6, to1).isNull() ); + CPPUNIT_ASSERT ( s1.replace(from6, to1).isEmpty() ); - CPPUNIT_ASSERT ( s.replace(from5, to5).isNull() ); - CPPUNIT_ASSERT ( s.replace(from5, to5).isEmpty() ); - CPPUNIT_ASSERT ( s.replace(from7, to7).isNull() ); - CPPUNIT_ASSERT ( s.replace(from7, to7).isEmpty() ); + CPPUNIT_ASSERT ( s1.replace(from5, to5).isNull() ); + CPPUNIT_ASSERT ( s1.replace(from5, to5).isEmpty() ); + CPPUNIT_ASSERT ( s1.replace(from7, to7).isNull() ); + CPPUNIT_ASSERT ( s1.replace(from7, to7).isEmpty() ); } //----------------------------------------------------------------------