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>
* Linux functions from FTerm moved into the FTermLinux class

View File

@ -336,21 +336,43 @@ class FTerm
public:
void setDefault()
{
terminal_detection = true;
cursor_optimisation = true;
mouse_support = true;
terminal_detection = true;
color_change = true;
vgafont = false;
newfont = false;
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 mouse_support : 1;
uInt8 terminal_detection : 1;
uInt8 color_change : 1;
uInt8 vgafont : 1;
uInt8 newfont : 1;
uInt8 : 3; // padding bits
uInt8 : 2; // padding bits
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;
private:
@ -407,7 +429,7 @@ class FTerm
void initOSspecifics();
void finish();
void finishOSspecifics1();
void finishOSspecifics2();
void finish_encoding();
static uInt cp437_to_unicode (uChar);
static int getMouseProtocolKey (char[]);
static int getTermcapKey (char[], int);

View File

@ -73,6 +73,10 @@ class FTermFreeBSD
// Mutators
static void setCursorStyle (CursorStyle, bool);
static void enableChangeCursorStyle();
static void disableChangeCursorStyle();
static void enableMetaSendsEscape();
static void disableMetaSendsEscape();
// Methods
static void init();
@ -96,10 +100,28 @@ class FTermFreeBSD
// Data Members
static uInt bsd_alt_keymap;
static CursorStyle cursor_style;
static bool change_cursorstyle;
static bool meta_sends_escape;
};
#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

View File

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

View File

@ -59,7 +59,11 @@ class FTermOpenBSD
~FTermOpenBSD();
// Inquiries
static bool isWSConsConsole();
static bool isBSDConsole();
// Mutators
static void disableMetaSendsEscape();
static void enableMetaSendsEscape();
// Methods
static void init();
@ -74,15 +78,27 @@ class FTermOpenBSD
#if defined(__NetBSD__) || defined(__OpenBSD__)
// Methods
static bool saveWSConsEncoding();
static bool setWSConsEncoding (kbd_t);
static bool setWSConsMetaEsc();
static bool resetWSConsEncoding();
static bool saveBSDConsoleEncoding();
static bool setBSDConsoleEncoding (kbd_t);
static bool setBSDConsoleMetaEsc();
static bool resetBSDConsoleEncoding();
// Data Members
static kbd_t wscons_keyboard_encoding;
static kbd_t bsd_keyboard_encoding;
static bool meta_sends_escape;
#endif
};
#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

View File

@ -321,11 +321,13 @@ void FApplication::showParameterUsage()
<< " -h, --help "
<< " Display this help and exit" << std::endl
<< std::endl
<< "FinalCut Options:" << std::endl
<< "The Final Cut options:" << std::endl
<< " --encoding <name> "
<< " Sets the character encoding mode" << std::endl
<< " "
<< " {utf8, vt100, pc, ascii}" << std::endl
<< " --no-mouse "
<< " Disable mouse support" << std::endl
<< " --no-optimized-cursor "
<< " Disable cursor optimization" << std::endl
<< " --no-terminal-detection"
@ -335,7 +337,25 @@ void FApplication::showParameterUsage()
<< " --vgafont "
<< " Set the standard vga 8x16 font" << std::endl
<< " --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);
}
@ -402,20 +422,28 @@ void FApplication::cmd_options (const int& argc, char* argv[])
static struct option long_options[] =
{
{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-terminal-detection"), no_argument, 0, 0 },
{C_STR("no-color-change"), no_argument, 0, 0 },
{C_STR("vgafont"), 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 }
};
opterr = 0;
c = getopt_long ( argc
, argv
, ""
, long_options
, &idx );
c = getopt_long (argc, argv, "", long_options, &idx);
if ( c == -1 )
break;
@ -441,6 +469,9 @@ void FApplication::cmd_options (const int& argc, char* argv[])
+ 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 )
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 )
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)
{
#if defined(__linux__)
linux->setBeep (Hz, ms);
#endif
}
#else
void FTerm::setBeep (int, int)
{ }
#endif
//----------------------------------------------------------------------
void FTerm::resetBeep()
@ -1013,7 +1016,7 @@ void FTerm::initScreenSettings()
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
freebsd->initCharMap();
freebsd->initCharMap (fc::character);
#endif
// set xterm underline cursor
@ -2109,6 +2112,7 @@ void FTerm::init()
init_encoding();
// Enable the terminal mouse support
if ( init_values.mouse_support )
enableMouse();
// Activate meta key sends escape
@ -2184,10 +2188,25 @@ void FTerm::initOSspecifics()
#endif
#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
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
if ( init_values.meta_sends_escape )
openbsd->enableMetaSendsEscape();
else
openbsd->disableMetaSendsEscape();
openbsd->init(); // Initialize wscons console
#endif
}
@ -2243,6 +2262,7 @@ void FTerm::finish()
resetBeep();
// Disable the terminal mouse support
if ( init_values.mouse_support )
disableMouse();
// Deactivate meta key sends escape
@ -2258,7 +2278,7 @@ void FTerm::finish()
std::fflush(stdout);
}
finishOSspecifics2();
finish_encoding();
if ( NewFont || VGAFont )
setOldFont();
@ -2283,7 +2303,7 @@ void FTerm::finishOSspecifics1()
}
//----------------------------------------------------------------------
void FTerm::finishOSspecifics2()
void FTerm::finish_encoding()
{
#if defined(__linux__)
if ( isLinuxTerm() && utf8_console )
@ -2312,6 +2332,10 @@ uInt FTerm::cp437_to_unicode (uChar c)
inline int FTerm::getMouseProtocolKey (char 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);
// x11 mouse tracking

View File

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

View File

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

View File

@ -24,7 +24,8 @@
// static class attributes
#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
@ -44,9 +45,9 @@ FTermOpenBSD::~FTermOpenBSD() // destructor
// public methods of FTermOpenBSD
//----------------------------------------------------------------------
#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;
@ -59,31 +60,35 @@ bool FTermOpenBSD::isWSConsConsole()
//----------------------------------------------------------------------
void FTermOpenBSD::init()
{
// initialize wscons console
// initialize BSD workstation console
if ( ! isWSConsConsole() )
if ( ! isBSDConsole() )
return;
if ( meta_sends_escape )
{
// save current left alt key mapping
saveWSConsEncoding();
saveBSDConsoleEncoding();
// alt key generate ESC prefix
setWSConsMetaEsc();
setBSDConsoleMetaEsc();
}
}
//----------------------------------------------------------------------
void FTermOpenBSD::finish()
{
if ( ! isWSConsConsole() )
if ( ! isBSDConsole() )
return;
resetWSConsEncoding();
if ( meta_sends_escape )
resetBSDConsoleEncoding();
}
// private methods of FTermOpenBSD
//----------------------------------------------------------------------
bool FTermOpenBSD::saveWSConsEncoding()
bool FTermOpenBSD::saveBSDConsoleEncoding()
{
static kbd_t k_encoding;
int ret = ioctl(0, WSKBDIO_GETENCODING, &k_encoding);
@ -92,12 +97,12 @@ bool FTermOpenBSD::saveWSConsEncoding()
return false;
// save current encoding
wscons_keyboard_encoding = k_encoding;
bsd_keyboard_encoding = k_encoding;
return true;
}
//----------------------------------------------------------------------
bool FTermOpenBSD::setWSConsEncoding (kbd_t k_encoding)
bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding)
{
if ( ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 )
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
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