Added special console options for FreeBSD, NetBSD and OpenBSD

This commit is contained in:
Markus Gans 2018-06-17 23:25:32 +02:00
parent ff3142c4aa
commit 32097d4bf0
10 changed files with 204 additions and 55 deletions

View File

@ -1,3 +1,6 @@
2017-06-17 Markus Gans <guru.mail@muenster.de>
* Added special console options for FreeBSD, NetBSD and OpenBSD
2017-06-12 Markus Gans <guru.mail@muenster.de> 2017-06-12 Markus Gans <guru.mail@muenster.de>
* Linux functions from FTerm moved into the FTermLinux class * Linux functions from FTerm moved into the FTermLinux class

View File

@ -336,21 +336,43 @@ class FTerm
public: public:
void setDefault() void setDefault()
{ {
terminal_detection = true;
cursor_optimisation = true; cursor_optimisation = true;
mouse_support = true;
terminal_detection = true;
color_change = true; color_change = true;
vgafont = false; vgafont = false;
newfont = false; newfont = false;
encoding = fc::UNKNOWN; encoding = fc::UNKNOWN;
#if defined(__FreeBSD__) || defined(__DragonFly__)
meta_sends_escape = true;
change_cursorstyle = true;
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
meta_sends_escape = true;
#endif
} }
uInt8 terminal_detection : 1;
uInt8 cursor_optimisation : 1; uInt8 cursor_optimisation : 1;
uInt8 mouse_support : 1;
uInt8 terminal_detection : 1;
uInt8 color_change : 1; uInt8 color_change : 1;
uInt8 vgafont : 1; uInt8 vgafont : 1;
uInt8 newfont : 1; uInt8 newfont : 1;
uInt8 : 3; // padding bits uInt8 : 2; // padding bits
fc::encoding encoding; fc::encoding encoding;
#if defined(__FreeBSD__) || defined(__DragonFly__)
uInt8 meta_sends_escape : 1;
uInt8 change_cursorstyle : 1;
uInt8 : 6; // padding bits
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
uInt8 meta_sends_escape : 1;
uInt8 : 7; // padding bits
#endif
} init_values; } init_values;
private: private:
@ -407,7 +429,7 @@ class FTerm
void initOSspecifics(); void initOSspecifics();
void finish(); void finish();
void finishOSspecifics1(); void finishOSspecifics1();
void finishOSspecifics2(); void finish_encoding();
static uInt cp437_to_unicode (uChar); static uInt cp437_to_unicode (uChar);
static int getMouseProtocolKey (char[]); static int getMouseProtocolKey (char[]);
static int getTermcapKey (char[], int); static int getTermcapKey (char[], int);

View File

@ -73,6 +73,10 @@ class FTermFreeBSD
// Mutators // Mutators
static void setCursorStyle (CursorStyle, bool); static void setCursorStyle (CursorStyle, bool);
static void enableChangeCursorStyle();
static void disableChangeCursorStyle();
static void enableMetaSendsEscape();
static void disableMetaSendsEscape();
// Methods // Methods
static void init(); static void init();
@ -96,10 +100,28 @@ class FTermFreeBSD
// Data Members // Data Members
static uInt bsd_alt_keymap; static uInt bsd_alt_keymap;
static CursorStyle cursor_style; static CursorStyle cursor_style;
static bool change_cursorstyle;
static bool meta_sends_escape;
}; };
#pragma pack(pop) #pragma pack(pop)
// FTermFreeBSD inline functions
//----------------------------------------------------------------------
#if defined(__FreeBSD__) || defined(__DragonFly__)
inline void FTermFreeBSD::enableChangeCursorStyle()
{ change_cursorstyle = true; }
//----------------------------------------------------------------------
inline void FTermFreeBSD::disableChangeCursorStyle()
{ change_cursorstyle = false; }
//----------------------------------------------------------------------
inline void FTermFreeBSD::enableMetaSendsEscape()
{ meta_sends_escape = true; }
//----------------------------------------------------------------------
inline void FTermFreeBSD::disableMetaSendsEscape()
{ meta_sends_escape = false; }
#endif // defined(__FreeBSD__) || defined(__DragonFly__)
#endif // FTERMFREEBSD_H #endif // FTERMFREEBSD_H

View File

@ -210,6 +210,6 @@ inline bool FTermLinux::isVGAFontUsed()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermLinux::isNewFontUsed() inline bool FTermLinux::isNewFontUsed()
{ return NewFont; } { return NewFont; }
#endif #endif // defined(__linux__)
#endif // FTERMLINUX_H #endif // FTERMLINUX_H

View File

@ -59,7 +59,11 @@ class FTermOpenBSD
~FTermOpenBSD(); ~FTermOpenBSD();
// Inquiries // Inquiries
static bool isWSConsConsole(); static bool isBSDConsole();
// Mutators
static void disableMetaSendsEscape();
static void enableMetaSendsEscape();
// Methods // Methods
static void init(); static void init();
@ -74,15 +78,27 @@ class FTermOpenBSD
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__)
// Methods // Methods
static bool saveWSConsEncoding(); static bool saveBSDConsoleEncoding();
static bool setWSConsEncoding (kbd_t); static bool setBSDConsoleEncoding (kbd_t);
static bool setWSConsMetaEsc(); static bool setBSDConsoleMetaEsc();
static bool resetWSConsEncoding(); static bool resetBSDConsoleEncoding();
// Data Members // Data Members
static kbd_t wscons_keyboard_encoding; static kbd_t bsd_keyboard_encoding;
static bool meta_sends_escape;
#endif #endif
}; };
#pragma pack(pop) #pragma pack(pop)
// FTermOpenBSD inline functions
//----------------------------------------------------------------------
#if defined(__NetBSD__) || defined(__OpenBSD__)
inline void FTermOpenBSD::enableMetaSendsEscape()
{ meta_sends_escape = true; }
//----------------------------------------------------------------------
inline void FTermOpenBSD::disableMetaSendsEscape()
{ meta_sends_escape = false; }
#endif // defined(__NetBSD__) || defined(__OpenBSD__)
#endif // FTERMOPENBSD_H #endif // FTERMOPENBSD_H

View File

@ -321,11 +321,13 @@ void FApplication::showParameterUsage()
<< " -h, --help " << " -h, --help "
<< " Display this help and exit" << std::endl << " Display this help and exit" << std::endl
<< std::endl << std::endl
<< "FinalCut Options:" << std::endl << "The Final Cut options:" << std::endl
<< " --encoding <name> " << " --encoding <name> "
<< " Sets the character encoding mode" << std::endl << " Sets the character encoding mode" << std::endl
<< " " << " "
<< " {utf8, vt100, pc, ascii}" << std::endl << " {utf8, vt100, pc, ascii}" << std::endl
<< " --no-mouse "
<< " Disable mouse support" << std::endl
<< " --no-optimized-cursor " << " --no-optimized-cursor "
<< " Disable cursor optimization" << std::endl << " Disable cursor optimization" << std::endl
<< " --no-terminal-detection" << " --no-terminal-detection"
@ -335,7 +337,25 @@ void FApplication::showParameterUsage()
<< " --vgafont " << " --vgafont "
<< " Set the standard vga 8x16 font" << std::endl << " Set the standard vga 8x16 font" << std::endl
<< " --newfont " << " --newfont "
<< " Enables the graphical font" << std::endl; << " Enables the graphical font" << std::endl
#if defined(__FreeBSD__) || defined(__DragonFly__)
<< std::endl
<< "FreeBSD console options:" << std::endl
<< " --no-esc-for-alt-meta "
<< " Do not send a ESC prefix for the alt/meta key" << std::endl
<< " --no-cursorstyle-change"
<< " Do not change the current cursor style" << std::endl
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
<< std::endl
<< "NetBSD/OpenBSD console options:" << std::endl
<< " --no-esc-for-alt-meta "
<< " Do not send a ESC prefix for the alt/meta key" << std::endl
#endif
<< std::endl;
std::exit(EXIT_SUCCESS); std::exit(EXIT_SUCCESS);
} }
@ -402,20 +422,28 @@ void FApplication::cmd_options (const int& argc, char* argv[])
static struct option long_options[] = static struct option long_options[] =
{ {
{C_STR("encoding"), required_argument, 0, 0 }, {C_STR("encoding"), required_argument, 0, 0 },
{C_STR("no-mouse"), no_argument, 0, 0 },
{C_STR("no-optimized-cursor"), no_argument, 0, 0 }, {C_STR("no-optimized-cursor"), no_argument, 0, 0 },
{C_STR("no-terminal-detection"), no_argument, 0, 0 }, {C_STR("no-terminal-detection"), no_argument, 0, 0 },
{C_STR("no-color-change"), no_argument, 0, 0 }, {C_STR("no-color-change"), no_argument, 0, 0 },
{C_STR("vgafont"), no_argument, 0, 0 }, {C_STR("vgafont"), no_argument, 0, 0 },
{C_STR("newfont"), no_argument, 0, 0 }, {C_STR("newfont"), no_argument, 0, 0 },
#if defined(__FreeBSD__) || defined(__DragonFly__)
{C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 },
{C_STR("no-cursorstyle-change"), no_argument, 0, 0 },
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
{C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 },
#endif
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
opterr = 0; opterr = 0;
c = getopt_long ( argc c = getopt_long (argc, argv, "", long_options, &idx);
, argv
, ""
, long_options
, &idx );
if ( c == -1 ) if ( c == -1 )
break; break;
@ -441,6 +469,9 @@ void FApplication::cmd_options (const int& argc, char* argv[])
+ std::string(encoding.c_str()) ); + std::string(encoding.c_str()) );
} }
if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 )
init_values.mouse_support = false;
if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 ) if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 )
init_values.cursor_optimisation = false; init_values.cursor_optimisation = false;
@ -455,6 +486,19 @@ void FApplication::cmd_options (const int& argc, char* argv[])
if ( std::strcmp(long_options[idx].name, "newfont") == 0 ) if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
init_values.newfont = true; init_values.newfont = true;
#if defined(__FreeBSD__) || defined(__DragonFly__)
if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 )
init_values.meta_sends_escape = false;
if ( std::strcmp(long_options[idx].name, "no-cursorstyle-change") == 0 )
init_values.change_cursorstyle = false;
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 )
init_values.meta_sends_escape = false;
#endif
} }
} }
} }

View File

@ -731,12 +731,15 @@ void FTerm::setPalette (short index, int r, int g, int b)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#if defined(__linux__)
void FTerm::setBeep (int Hz, int ms) void FTerm::setBeep (int Hz, int ms)
{ {
#if defined(__linux__)
linux->setBeep (Hz, ms); linux->setBeep (Hz, ms);
#endif
} }
#else
void FTerm::setBeep (int, int)
{ }
#endif
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::resetBeep() void FTerm::resetBeep()
@ -1013,7 +1016,7 @@ void FTerm::initScreenSettings()
#endif #endif
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
freebsd->initCharMap(); freebsd->initCharMap (fc::character);
#endif #endif
// set xterm underline cursor // set xterm underline cursor
@ -2109,6 +2112,7 @@ void FTerm::init()
init_encoding(); init_encoding();
// Enable the terminal mouse support // Enable the terminal mouse support
if ( init_values.mouse_support )
enableMouse(); enableMouse();
// Activate meta key sends escape // Activate meta key sends escape
@ -2184,10 +2188,25 @@ void FTerm::initOSspecifics()
#endif #endif
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
if ( init_values.meta_sends_escape )
freebsd->enableMetaSendsEscape();
else
freebsd->disableMetaSendsEscape();
if ( init_values.change_cursorstyle )
freebsd->enableChangeCursorStyle();
else
freebsd->disableChangeCursorStyle();
freebsd->init(); // Initialize BSD console freebsd->init(); // Initialize BSD console
#endif #endif
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__)
if ( init_values.meta_sends_escape )
openbsd->enableMetaSendsEscape();
else
openbsd->disableMetaSendsEscape();
openbsd->init(); // Initialize wscons console openbsd->init(); // Initialize wscons console
#endif #endif
} }
@ -2243,6 +2262,7 @@ void FTerm::finish()
resetBeep(); resetBeep();
// Disable the terminal mouse support // Disable the terminal mouse support
if ( init_values.mouse_support )
disableMouse(); disableMouse();
// Deactivate meta key sends escape // Deactivate meta key sends escape
@ -2258,7 +2278,7 @@ void FTerm::finish()
std::fflush(stdout); std::fflush(stdout);
} }
finishOSspecifics2(); finish_encoding();
if ( NewFont || VGAFont ) if ( NewFont || VGAFont )
setOldFont(); setOldFont();
@ -2283,7 +2303,7 @@ void FTerm::finishOSspecifics1()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::finishOSspecifics2() void FTerm::finish_encoding()
{ {
#if defined(__linux__) #if defined(__linux__)
if ( isLinuxTerm() && utf8_console ) if ( isLinuxTerm() && utf8_console )
@ -2312,6 +2332,10 @@ uInt FTerm::cp437_to_unicode (uChar c)
inline int FTerm::getMouseProtocolKey (char buffer[]) inline int FTerm::getMouseProtocolKey (char buffer[])
{ {
// Looking for mouse string in the key buffer // Looking for mouse string in the key buffer
if ( ! init_values.mouse_support )
return -1;
register std::size_t buf_len = std::strlen(buffer); register std::size_t buf_len = std::strlen(buffer);
// x11 mouse tracking // x11 mouse tracking

View File

@ -808,7 +808,7 @@ inline char* FTermDetection::secDA_Analysis_24 (char current_termtype[])
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__)
if ( secondary_da.terminal_id_version == 20 if ( secondary_da.terminal_id_version == 20
&& FTermOpenBSD::isWSConsConsole() ) && FTermOpenBSD::isBSDConsole() )
{ {
// NetBSD/OpenBSD workstation console // NetBSD/OpenBSD workstation console
if ( std::strncmp(termtype, C_STR("wsvt25"), 6) == 0 ) if ( std::strncmp(termtype, C_STR("wsvt25"), 6) == 0 )

View File

@ -26,7 +26,9 @@
// static class attributes // static class attributes
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
uInt FTermFreeBSD::bsd_alt_keymap = 0; uInt FTermFreeBSD::bsd_alt_keymap = 0;
FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style; FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style = fc::normal_cursor;
bool FTermFreeBSD::change_cursorstyle = true;
bool FTermFreeBSD::meta_sends_escape = true;
#endif #endif
@ -59,6 +61,9 @@ void FTermFreeBSD::setCursorStyle (CursorStyle style, bool hidden)
if ( ! isFreeBSDConsole() ) if ( ! isFreeBSDConsole() )
return; return;
if ( ! change_cursorstyle )
return;
cursor_style = style; cursor_style = style;
if ( hidden ) if ( hidden )
@ -88,14 +93,20 @@ void FTermFreeBSD::init()
if ( ! isFreeBSDConsole() ) if ( ! isFreeBSDConsole() )
return; return;
if ( meta_sends_escape )
{
// save current left alt key mapping // save current left alt key mapping
saveFreeBSDAltKey(); saveFreeBSDAltKey();
// map meta key to left alt key // map meta key to left alt key
setFreeBSDAlt2Meta(); setFreeBSDAlt2Meta();
}
if ( change_cursorstyle )
{
// Initialize FreeBSD console cursor // Initialize FreeBSD console cursor
setCursorStyle (fc::destructive_cursor, true); setCursorStyle (fc::destructive_cursor, true);
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -119,7 +130,9 @@ void FTermFreeBSD::finish()
if ( ! isFreeBSDConsole() ) if ( ! isFreeBSDConsole() )
return; return;
if ( meta_sends_escape )
resetFreeBSDAlt2Meta(); resetFreeBSDAlt2Meta();
setCursorStyle (fc::normal_cursor, false); setCursorStyle (fc::normal_cursor, false);
} }

View File

@ -24,7 +24,8 @@
// static class attributes // static class attributes
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__)
kbd_t FTermOpenBSD::wscons_keyboard_encoding = 0; kbd_t FTermOpenBSD::bsd_keyboard_encoding = 0;
bool FTermOpenBSD::meta_sends_escape = true;
#endif #endif
@ -44,9 +45,9 @@ FTermOpenBSD::~FTermOpenBSD() // destructor
// public methods of FTermOpenBSD // public methods of FTermOpenBSD
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__)
bool FTermOpenBSD::isWSConsConsole() bool FTermOpenBSD::isBSDConsole()
{ {
// Check if it's a NetBSD/OpenBSD console // Check if it's a NetBSD/OpenBSD workstation console
static kbd_t kbdencoding; static kbd_t kbdencoding;
@ -59,31 +60,35 @@ bool FTermOpenBSD::isWSConsConsole()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermOpenBSD::init() void FTermOpenBSD::init()
{ {
// initialize wscons console // initialize BSD workstation console
if ( ! isWSConsConsole() ) if ( ! isBSDConsole() )
return; return;
if ( meta_sends_escape )
{
// save current left alt key mapping // save current left alt key mapping
saveWSConsEncoding(); saveBSDConsoleEncoding();
// alt key generate ESC prefix // alt key generate ESC prefix
setWSConsMetaEsc(); setBSDConsoleMetaEsc();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermOpenBSD::finish() void FTermOpenBSD::finish()
{ {
if ( ! isWSConsConsole() ) if ( ! isBSDConsole() )
return; return;
resetWSConsEncoding(); if ( meta_sends_escape )
resetBSDConsoleEncoding();
} }
// private methods of FTermOpenBSD // private methods of FTermOpenBSD
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::saveWSConsEncoding() bool FTermOpenBSD::saveBSDConsoleEncoding()
{ {
static kbd_t k_encoding; static kbd_t k_encoding;
int ret = ioctl(0, WSKBDIO_GETENCODING, &k_encoding); int ret = ioctl(0, WSKBDIO_GETENCODING, &k_encoding);
@ -92,12 +97,12 @@ bool FTermOpenBSD::saveWSConsEncoding()
return false; return false;
// save current encoding // save current encoding
wscons_keyboard_encoding = k_encoding; bsd_keyboard_encoding = k_encoding;
return true; return true;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::setWSConsEncoding (kbd_t k_encoding) bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding)
{ {
if ( ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 ) if ( ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 )
return false; return false;
@ -106,17 +111,17 @@ bool FTermOpenBSD::setWSConsEncoding (kbd_t k_encoding)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::setWSConsMetaEsc() bool FTermOpenBSD::setBSDConsoleMetaEsc()
{ {
static const kbd_t meta_esc = 0x20; // generate ESC prefix on ALT-key static const kbd_t meta_esc = 0x20; // generate ESC prefix on ALT-key
return setWSConsEncoding (wscons_keyboard_encoding | meta_esc); return setBSDConsoleEncoding (bsd_keyboard_encoding | meta_esc);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::resetWSConsEncoding() bool FTermOpenBSD::resetBSDConsoleEncoding()
{ {
return setWSConsEncoding (wscons_keyboard_encoding); return setBSDConsoleEncoding (bsd_keyboard_encoding);
} }
#endif #endif