2018-05-20 15:15:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ftermxterminal.cpp - Contains all xterm-specific terminal functions *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2018-05-20 15:15:42 +02:00
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2018-2020 Markus Gans *
|
2018-05-20 15:15:42 +02:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* 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 *
|
2018-05-20 15:15:42 +02:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2018-05-20 15:15:42 +02:00
|
|
|
* 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 *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
2019-08-07 11:47:03 +02:00
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
#include "final/fconfig.h" // includes _GNU_SOURCE for fd_set
|
|
|
|
#endif
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
#include "final/fapplication.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fc.h"
|
2020-05-16 22:24:36 +02:00
|
|
|
#include "final/flog.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fstring.h"
|
2018-05-20 15:15:42 +02:00
|
|
|
#include "final/fterm.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/ftermcap.h"
|
|
|
|
#include "final/ftermdetection.h"
|
2018-05-27 19:43:18 +02:00
|
|
|
#include "final/ftermfreebsd.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/ftermios.h"
|
2018-05-20 15:15:42 +02:00
|
|
|
#include "final/ftermxterminal.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fsize.h"
|
2018-05-20 15:15:42 +02:00
|
|
|
|
2020-06-06 21:10:06 +02:00
|
|
|
#define initCheck(ret_value) \
|
|
|
|
if ( ! isInitialized() ) \
|
|
|
|
{ \
|
|
|
|
if ( ! FApplication::isQuit() ) \
|
|
|
|
warnNotInitialized(); \
|
|
|
|
return ret_value; \
|
2020-05-16 22:24:36 +02:00
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
// static class attributes
|
2019-10-05 23:20:07 +02:00
|
|
|
bool FTermXTerminal::mouse_support{false};
|
|
|
|
FSystem* FTermXTerminal::fsystem{nullptr};
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FTermXTerminal
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FTermXTerminal::FTermXTerminal()
|
|
|
|
{
|
2019-07-01 01:07:54 +02:00
|
|
|
// Get FSystem object
|
|
|
|
fsystem = FTerm::getFSystem();
|
2018-05-20 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FTermXTerminal::~FTermXTerminal() // destructor
|
2019-10-01 23:14:00 +02:00
|
|
|
{ }
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
xterm_font = fontname;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setTitle (const FString& title)
|
|
|
|
{
|
|
|
|
// Set the xterm title
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
xterm_title = title;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermTitle();
|
|
|
|
}
|
|
|
|
|
2018-10-01 22:27:54 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FTermXTerminal::setTermSize (const FSize& size)
|
2018-10-01 22:27:54 +02:00
|
|
|
{
|
|
|
|
// Set xterm size to {term_width} x {term_height}
|
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
term_width = size.getWidth();
|
|
|
|
term_height = size.getHeight();
|
2018-10-01 22:27:54 +02:00
|
|
|
setXTermSize();
|
|
|
|
}
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setForeground (const FString& fg)
|
|
|
|
{
|
|
|
|
// Set the XTerm text foreground color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
foreground_color = fg;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermForeground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setBackground (const FString& bg)
|
|
|
|
{
|
|
|
|
// Set the XTerm text background color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
background_color = bg;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setCursorColor (const FString& cc)
|
|
|
|
{
|
|
|
|
// Set the text cursor color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
cursor_color = cc;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermCursorColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setMouseForeground (const FString& mfg)
|
|
|
|
{
|
|
|
|
// Set the mouse foreground color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
mouse_foreground_color = mfg;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermMouseForeground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setMouseBackground (const FString& mbg)
|
|
|
|
{
|
|
|
|
// Set the mouse background color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
mouse_background_color = mbg;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermMouseBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setHighlightBackground (const FString& hbg)
|
|
|
|
{
|
|
|
|
// Set the highlight background color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
highlight_background_color = hbg;
|
2018-05-20 15:15:42 +02:00
|
|
|
setXTermHighlightBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
void FTermXTerminal::setMouseSupport (bool enable)
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
// activate/deactivate the xterm mouse support
|
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
if ( enable )
|
2018-05-20 15:15:42 +02:00
|
|
|
enableXTermMouse();
|
|
|
|
else
|
|
|
|
disableXTermMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
void FTermXTerminal::metaSendsESC (bool enable)
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
// activate/deactivate the xterm meta key sends escape prefix
|
|
|
|
|
2018-12-22 23:50:10 +01:00
|
|
|
if ( enable )
|
2018-05-20 15:15:42 +02:00
|
|
|
enableXTermMetaSendsESC();
|
|
|
|
else
|
|
|
|
disableXTermMetaSendsESC();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-05-27 00:50:11 +02:00
|
|
|
void FTermXTerminal::init()
|
|
|
|
{
|
|
|
|
term_detection = FTerm::getFTermDetection();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-20 15:15:42 +02:00
|
|
|
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
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
foreground_color.clear();
|
2018-05-20 15:15:42 +02:00
|
|
|
resetXTermForeground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetBackground()
|
|
|
|
{
|
|
|
|
// Reset the XTerm text background color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
background_color.clear();
|
2018-05-20 15:15:42 +02:00
|
|
|
resetXTermBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetCursorColor()
|
|
|
|
{
|
|
|
|
// Reset the text cursor color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
cursor_color.clear();
|
2018-05-20 15:15:42 +02:00
|
|
|
resetXTermCursorColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetMouseForeground()
|
|
|
|
{
|
|
|
|
// Reset the mouse foreground color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
mouse_foreground_color.clear();
|
2018-05-20 15:15:42 +02:00
|
|
|
resetXTermMouseForeground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetMouseBackground()
|
|
|
|
{
|
|
|
|
// Reset the mouse background color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
mouse_background_color.clear();
|
2018-05-20 15:15:42 +02:00
|
|
|
resetXTermMouseBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetHighlightBackground()
|
|
|
|
{
|
|
|
|
// Reset the highlight background color
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
highlight_background_color.clear();
|
2018-05-20 15:15:42 +02:00
|
|
|
resetXTermHighlightBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetDefaults()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
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()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isUrxvtTerminal() )
|
|
|
|
&& ! term_detection->isRxvtTerminal() )
|
|
|
|
{
|
|
|
|
FTermios::setCaptureSendCharacters();
|
|
|
|
xterm_font = captureXTermFont();
|
|
|
|
xterm_title = captureXTermTitle();
|
|
|
|
FTermios::unsetCaptureSendCharacters();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FTermXTerminal
|
2020-05-16 22:24:36 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-07-12 15:25:21 +02:00
|
|
|
void FTermXTerminal::warnNotInitialized() const
|
2020-05-16 22:24:36 +02:00
|
|
|
{
|
|
|
|
*FApplication::getLog() << FLog::Warn
|
|
|
|
<< "The FTermXTerminal object has "
|
|
|
|
<< "not yet been initialized! "
|
|
|
|
<< "Please call the init() method first."
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermCursorStyle()
|
|
|
|
{
|
|
|
|
// Set the xterm cursor style
|
|
|
|
|
2019-07-28 23:12:01 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
|
2018-05-27 19:43:18 +02:00
|
|
|
if ( FTermFreeBSD::isFreeBSDConsole() )
|
2018-05-20 15:15:42 +02:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isGnomeTerminal()
|
|
|
|
&& ! term_detection->hasSetCursorStyleSupport() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( term_detection->isKdeTerminal() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( TCAP(fc::t_cursor_style)
|
|
|
|
|| term_detection->isXTerminal()
|
2019-09-28 03:13:06 +02:00
|
|
|
|| term_detection->isCygwinTerminal()
|
2018-05-20 15:15:42 +02:00
|
|
|
|| term_detection->isMinttyTerm()
|
|
|
|
|| term_detection->hasSetCursorStyleSupport() )
|
|
|
|
{
|
|
|
|
FTerm::putstringf (CSI "%d q", cursor_style);
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermTitle()
|
|
|
|
{
|
|
|
|
// Set the xterm title
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
2019-09-28 03:13:06 +02:00
|
|
|
|| term_detection->isCygwinTerminal()
|
2018-05-20 15:15:42 +02:00
|
|
|
|| term_detection->isMinttyTerm()
|
|
|
|
|| term_detection->isPuttyTerminal()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "0;%s" BEL, xterm_title.c_str());
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-01 22:27:54 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermSize()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-10-01 22:27:54 +02:00
|
|
|
if ( term_detection->isXTerminal() )
|
|
|
|
{
|
2018-10-15 01:34:57 +02:00
|
|
|
FTerm::putstringf ( CSI "8;%lu;%lut"
|
|
|
|
, uLong(term_height)
|
|
|
|
, uLong(term_width) );
|
2018-10-01 22:27:54 +02:00
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermFont()
|
|
|
|
{
|
|
|
|
// Change the XTerm font (needs the allowFontOps resource)
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| term_detection->isUrxvtTerminal()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "50;%s" BEL, xterm_font.c_str() );
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermForeground()
|
|
|
|
{
|
|
|
|
// Set the XTerm text foreground color
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| term_detection->isMinttyTerm()
|
|
|
|
|| term_detection->isMltermTerminal()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "10;%s" BEL, foreground_color.c_str());
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermBackground()
|
|
|
|
{
|
|
|
|
// Set the XTerm text background color
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| term_detection->isMinttyTerm()
|
|
|
|
|| term_detection->isMltermTerminal()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "11;%s" BEL, background_color.c_str());
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermCursorColor()
|
|
|
|
{
|
|
|
|
// Set the text cursor color
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| term_detection->isMinttyTerm()
|
|
|
|
|| term_detection->isUrxvtTerminal()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "12;%s" BEL, cursor_color.c_str());
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermMouseForeground()
|
|
|
|
{
|
|
|
|
// Set the mouse foreground color
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| term_detection->isUrxvtTerminal()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "13;%s" BEL, mouse_foreground_color.c_str());
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermMouseBackground()
|
|
|
|
{
|
|
|
|
// Set the mouse background color
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "14;%s" BEL, mouse_background_color.c_str());
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTermHighlightBackground()
|
|
|
|
{
|
|
|
|
// Set the highlight background color
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| term_detection->isUrxvtTerminal()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-10-01 23:14:00 +02:00
|
|
|
FTerm::putstringf (OSC "17;%s" BEL, highlight_background_color.c_str());
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::setXTerm8ColorDefaults()
|
|
|
|
{
|
|
|
|
// Redefinition of the XTerm default colors
|
|
|
|
// for the final cut 8 color theme
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isPuttyTerminal() )
|
|
|
|
return;
|
|
|
|
|
2019-08-11 20:07:39 +02:00
|
|
|
setXTermDefaultsMouseCursor();
|
2018-05-20 15:15:42 +02:00
|
|
|
|
2019-08-11 20:07:39 +02:00
|
|
|
if ( canSetXTermBackground() )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isPuttyTerminal() )
|
|
|
|
return;
|
|
|
|
|
2019-08-11 20:07:39 +02:00
|
|
|
setXTermDefaultsMouseCursor();
|
|
|
|
|
|
|
|
if ( canSetXTermBackground() )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FTermXTerminal::setXTermDefaultsMouseCursor()
|
|
|
|
{
|
2018-05-20 15:15:42 +02:00
|
|
|
setMouseBackground("rgb:ffff/ffff/ffff"); // white
|
|
|
|
setMouseForeground ("rgb:0000/0000/0000"); // black
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( ! term_detection->isGnomeTerminal() )
|
|
|
|
setCursorColor("rgb:ffff/ffff/ffff"); // white
|
2019-08-11 20:07:39 +02:00
|
|
|
}
|
2018-05-20 15:15:42 +02:00
|
|
|
|
2019-08-11 20:07:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FTermXTerminal::canSetXTermBackground()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck(false);
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( xterm_default_colors
|
|
|
|
&& ! (term_detection->isMinttyTerm()
|
2018-09-14 22:42:56 +02:00
|
|
|
|| term_detection->isMltermTerminal()
|
2018-05-20 15:15:42 +02:00
|
|
|
|| term_detection->isRxvtTerminal()
|
|
|
|
|| term_detection->isScreenTerm()) )
|
2019-08-11 20:07:39 +02:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2018-05-20 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetXTermColorMap()
|
|
|
|
{
|
|
|
|
// Reset the entire color table
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( term_detection->isMinttyTerm() )
|
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
FTerm::putstring (ESC "c"); // Full Reset (RIS)
|
2019-01-12 09:11:22 +01:00
|
|
|
}
|
|
|
|
else if ( canResetColor() )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-09-28 03:13:06 +02:00
|
|
|
FTerm::putstring (OSC "104" BEL);
|
2018-05-20 15:15:42 +02:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetXTermForeground()
|
|
|
|
{
|
|
|
|
// Reset the XTerm text foreground color
|
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( canResetColor() )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
oscPrefix();
|
|
|
|
FTerm::putstring (OSC "110" BEL);
|
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetXTermBackground()
|
|
|
|
{
|
|
|
|
// Reset the XTerm text background color
|
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( canResetColor() )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
oscPrefix();
|
|
|
|
FTerm::putstring (OSC "111" BEL);
|
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetXTermCursorColor()
|
|
|
|
{
|
|
|
|
// Reset the text cursor color
|
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( canResetColor() )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
oscPrefix();
|
|
|
|
FTerm::putstring (OSC "112" BEL);
|
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetXTermMouseForeground()
|
|
|
|
{
|
|
|
|
// Reset the mouse foreground color
|
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( canResetColor() )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
oscPrefix();
|
|
|
|
FTerm::putstring (OSC "113" BEL);
|
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetXTermMouseBackground()
|
|
|
|
{
|
|
|
|
// Reset the mouse background color
|
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( canResetColor() )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
|
|
|
oscPrefix();
|
|
|
|
FTerm::putstring (OSC "114" BEL);
|
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::resetXTermHighlightBackground()
|
|
|
|
{
|
|
|
|
// Reset the highlight background color
|
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( canResetColor() )
|
|
|
|
{
|
|
|
|
oscPrefix();
|
2019-09-28 03:13:06 +02:00
|
|
|
FTerm::putstring (OSC "117" BEL);
|
2019-01-12 09:11:22 +01:00
|
|
|
oscPostfix();
|
|
|
|
std::fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FTermXTerminal::canResetColor()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck(false);
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isGnomeTerminal()
|
|
|
|
&& term_detection->getGnomeTerminalID() < 3502 )
|
2019-01-12 09:11:22 +01:00
|
|
|
return false;
|
2018-05-20 15:15:42 +02:00
|
|
|
|
2019-01-12 09:11:22 +01:00
|
|
|
if ( term_detection->isPuttyTerminal()
|
|
|
|
|| term_detection->isMltermTerminal() )
|
|
|
|
return false;
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| FTermcap::osc_support )
|
2019-01-12 09:11:22 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2018-05-20 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::oscPrefix()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
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()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isScreenTerm()
|
|
|
|
|| term_detection->isTmuxTerm() )
|
|
|
|
{
|
|
|
|
// GNU Screen/tmux string terminator
|
|
|
|
FTerm::putstring (ESC "\\");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-10-01 23:14:00 +02:00
|
|
|
const FString FTermXTerminal::captureXTermFont()
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck(FString{});
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isXTerminal()
|
|
|
|
|| term_detection->isScreenTerm()
|
|
|
|
|| FTermcap::osc_support )
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
fd_set ifds{};
|
|
|
|
struct timeval tv{};
|
2020-02-02 22:34:27 +01:00
|
|
|
const int stdin_no = FTermios::getStdIn();
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
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
|
2020-02-19 21:59:13 +01:00
|
|
|
if ( select(stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
char temp[150]{};
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t n = std::strlen(temp);
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
// BEL + '\0' = string terminator
|
|
|
|
if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' )
|
|
|
|
temp[n - 1] = '\0';
|
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
return FString{temp};
|
2018-05-20 15:15:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
return FString{};
|
2018-05-20 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-10-01 23:14:00 +02:00
|
|
|
const FString FTermXTerminal::captureXTermTitle()
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
initCheck(FString{});
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
if ( term_detection->isKdeTerminal() )
|
2019-10-01 23:14:00 +02:00
|
|
|
return FString{};
|
2018-05-20 15:15:42 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
fd_set ifds{};
|
|
|
|
struct timeval tv{};
|
2020-02-02 22:34:27 +01:00
|
|
|
const int stdin_no = FTermios::getStdIn();
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
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
|
2020-02-19 21:59:13 +01:00
|
|
|
if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 )
|
2018-05-20 15:15:42 +02:00
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
char temp[512]{};
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
if ( std::scanf("\033]l%509[^\n]s", temp) == 1 )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t n = std::strlen(temp);
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
// Esc + \ = OSC string terminator
|
|
|
|
if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' )
|
|
|
|
{
|
|
|
|
if ( n < 4 )
|
2019-10-01 23:14:00 +02:00
|
|
|
return FString{};
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
temp[n - 2] = '\0';
|
2019-10-01 23:14:00 +02:00
|
|
|
return FString{temp};
|
2018-05-20 15:15:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
return FString{};
|
2018-05-20 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::enableXTermMouse()
|
|
|
|
{
|
2018-06-12 16:37:48 +02:00
|
|
|
// Activate the xterm mouse support
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
if ( mouse_support )
|
2019-10-05 23:20:07 +02:00
|
|
|
return; // The mouse is already activated
|
2018-05-20 15:15:42 +02:00
|
|
|
|
2019-07-01 01:07:54 +02:00
|
|
|
if ( ! fsystem )
|
|
|
|
fsystem = FTerm::getFSystem();
|
|
|
|
|
2018-05-20 15:15:42 +02:00
|
|
|
FTerm::putstring (CSI "?1001s" // save old highlight mouse tracking
|
2020-07-06 19:32:01 +02:00
|
|
|
CSI "?1000;" // enable x11 mouse tracking
|
|
|
|
"1002;" // enable cell motion mouse tracking
|
|
|
|
"1015;" // enable urxvt mouse mode
|
|
|
|
"1006h"); // enable SGR mouse mode
|
2018-05-20 15:15:42 +02:00
|
|
|
std::fflush(stdout);
|
|
|
|
mouse_support = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::disableXTermMouse()
|
|
|
|
{
|
2018-06-12 16:37:48 +02:00
|
|
|
// Deactivate the xterm mouse support
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
if ( ! mouse_support )
|
2019-10-05 23:20:07 +02:00
|
|
|
return; // The mouse was already deactivated
|
2018-05-20 15:15:42 +02:00
|
|
|
|
2020-07-06 19:32:01 +02:00
|
|
|
FTerm::putstring (CSI "?1006;" // disable SGR mouse mode
|
|
|
|
"1015;" // disable urxvt mouse mode
|
|
|
|
"1002;" // disable cell motion mouse tracking
|
|
|
|
"1000l" // disable x11 mouse tracking
|
2018-05-20 15:15:42 +02:00
|
|
|
CSI "?1001r"); // restore old highlight mouse tracking
|
|
|
|
std::fflush(stdout);
|
|
|
|
mouse_support = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermXTerminal::enableXTermMetaSendsESC()
|
|
|
|
{
|
2018-06-12 16:37:48 +02:00
|
|
|
// Activate the xterm meta key sends escape prefix
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2018-06-12 16:37:48 +02:00
|
|
|
// Deactivate the xterm meta key sends escape prefix
|
2018-05-20 15:15:42 +02:00
|
|
|
|
|
|
|
if ( ! meta_sends_esc )
|
|
|
|
return;
|
|
|
|
|
|
|
|
FTerm::putstring (CSI "?1036r"); // restore meta key sends escape
|
|
|
|
std::fflush(stdout);
|
|
|
|
meta_sends_esc = false;
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|