Bug fixing in FString and FTermDetection

This commit is contained in:
Markus Gans 2021-06-06 00:07:39 +02:00
parent 7d426ae25c
commit e38d604544
15 changed files with 259 additions and 226 deletions

View File

@ -1,3 +1,6 @@
2021-06-06 Markus Gans <guru.mail@muenster.de>
* Bug fixing in FString and FTermDetection
2021-06-03 Markus Gans <guru.mail@muenster.de> 2021-06-03 Markus Gans <guru.mail@muenster.de>
* Some FString optimizations * Some FString optimizations

View File

@ -190,7 +190,7 @@ void RotoZoomer::generateReport()
finalcut::FStringStream rep; finalcut::FStringStream rep;
dimension_str << getDesktopWidth() dimension_str << getDesktopWidth()
<< "x" << getDesktopHeight(); << "x" << getDesktopHeight();
int elapsed_ms = int(duration_cast<milliseconds>(end - start).count()); auto elapsed_ms = int(duration_cast<milliseconds>(end - start).count());
time_str << double(elapsed_ms) / 1000 << "s"; time_str << double(elapsed_ms) / 1000 << "s";
fps_str << double(loops) * 1000.0 / double(elapsed_ms); fps_str << double(loops) * 1000.0 / double(elapsed_ms);

View File

@ -141,7 +141,7 @@ bool FLabel::setEnable (bool enable)
void FLabel::setText (const FString& txt) void FLabel::setText (const FString& txt)
{ {
text.setString(txt); text.setString(txt);
multiline_text = text.split("\r\n"); multiline_text = text.split("\n");
if ( int(multiline_text.size()) > 1 ) if ( int(multiline_text.size()) > 1 )
multiline = true; multiline = true;

View File

@ -460,10 +460,7 @@ long FString::toLong() const
const FString s{trim()}; const FString s{trim()};
const wchar_t* p = s.string.c_str(); const wchar_t* p = s.string.c_str();
if ( ! p ) if ( s.isEmpty() )
throw std::invalid_argument ("null value");
if ( ! *p )
throw std::invalid_argument ("empty value"); throw std::invalid_argument ("empty value");
if ( *p == L'-' ) if ( *p == L'-' )
@ -513,10 +510,7 @@ uLong FString::toULong() const
const FString s{trim()}; const FString s{trim()};
const wchar_t* p = s.string.c_str(); const wchar_t* p = s.string.c_str();
if ( ! p ) if ( s.isEmpty() )
throw std::invalid_argument ("null value");
if ( ! *p )
throw std::invalid_argument ("empty value"); throw std::invalid_argument ("empty value");
if ( *p == L'-' ) if ( *p == L'-' )
@ -612,14 +606,15 @@ FString FString::rtrim() const
if ( isEmpty() ) if ( isEmpty() )
return *this; return *this;
const auto first = string.begin(); const auto r_end = string.rend();
auto iter = string.end() - 1; auto r_iter = string.rbegin();
while ( iter != first && std::iswspace(std::wint_t(*iter)) ) while ( r_iter != r_end && std::iswspace(std::wint_t(*r_iter)) )
--iter; ++r_iter;
if ( first != iter ) if ( r_iter != r_end )
return std::wstring(first, iter + 1); return std::wstring( make_reverse_iterator(r_end)
, make_reverse_iterator(r_iter) );
else else
return {}; return {};
} }

View File

@ -2166,8 +2166,8 @@ bool FTerm::init_terminal() const
initBaudRate(); initBaudRate();
// Terminal detection // Terminal detection
FTermDetection::detect(); auto& term_detection = FTerm::getFTermDetection();
const auto& term_detection = FTerm::getFTermDetection(); term_detection.detect();
setTermType (term_detection.getTermType()); setTermType (term_detection.getTermType());
return true; return true;
} }

View File

@ -50,27 +50,6 @@
namespace finalcut namespace finalcut
{ {
// static class attributes
FTermDetection::FTerminalType FTermDetection::terminal_type{};
FTermDetection::colorEnv FTermDetection::color_env{};
FTermDetection::kittyVersion FTermDetection::kitty_version{};
FTermDetection::secondaryDA FTermDetection::secondary_da{};
char FTermDetection::termtype[256]{};
char FTermDetection::ttytypename[256]{};
bool FTermDetection::decscusr_support{};
bool FTermDetection::terminal_detection{};
bool FTermDetection::color256{};
const FString* FTermDetection::answer_back{nullptr};
const FString* FTermDetection::sec_da{nullptr};
int FTermDetection::gnome_terminal_id{};
#if DEBUG
char FTermDetection::termtype_256color[256]{};
char FTermDetection::termtype_Answerback[256]{};
char FTermDetection::termtype_SecDA[256]{};
#endif // DEBUG
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FTermDetection // class FTermDetection
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -105,13 +84,13 @@ FTermDetection::~FTermDetection() // destructor
// public methods of FTermDetection // public methods of FTermDetection
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#if DEBUG #if DEBUG
const FString& FTermDetection::getAnswerbackString() const FString& FTermDetection::getAnswerbackString() const
{ {
return ( answer_back ) ? *answer_back : fc::emptyFString::get(); return ( answer_back ) ? *answer_back : fc::emptyFString::get();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString& FTermDetection::getSecDAString() const FString& FTermDetection::getSecDAString() const
{ {
return ( sec_da ) ? *sec_da : fc::emptyFString::get(); return ( sec_da ) ? *sec_da : fc::emptyFString::get();
} }
@ -330,9 +309,9 @@ void FTermDetection::termtypeAnalysis()
if ( std::strncmp(termtype, "screen", 6) == 0 ) if ( std::strncmp(termtype, "screen", 6) == 0 )
{ {
terminal_type.screen = true; terminal_type.screen = true;
std::string tmux = std::getenv("TMUX"); auto tmux = std::getenv("TMUX");
if ( tmux.length() != 0 ) if ( tmux && tmux[0] != '\0' )
terminal_type.tmux = true; terminal_type.tmux = true;
} }
@ -452,7 +431,7 @@ bool FTermDetection::get256colorEnvString()
color_env.string5 = std::getenv("KONSOLE_DBUS_SESSION"); color_env.string5 = std::getenv("KONSOLE_DBUS_SESSION");
color_env.string6 = std::getenv("KONSOLE_DCOP"); color_env.string6 = std::getenv("KONSOLE_DCOP");
color_env.string7 = std::getenv("COLORFGBG"); color_env.string7 = std::getenv("COLORFGBG");
color_env.string7 = std::getenv("KITTY_WINDOW_ID"); color_env.string8 = std::getenv("KITTY_WINDOW_ID");
if ( color_env.string1 != nullptr if ( color_env.string1 != nullptr
|| color_env.string2 != nullptr || color_env.string2 != nullptr
@ -780,7 +759,7 @@ int FTermDetection::str2int (const FString& s)
constexpr int ERROR = -1; constexpr int ERROR = -1;
if ( ! s ) if ( s.isEmpty() )
return ERROR; return ERROR;
try try

View File

@ -225,7 +225,7 @@ void FTextView::insert (const FString& str, int pos)
else else
s = FString{str}.rtrim().expandTabs(FTerm::getTabstop()); s = FString{str}.rtrim().expandTabs(FTerm::getTabstop());
auto text_split = s.split("\r\n"); auto text_split = s.split("\n");
for (auto&& line : text_split) // Line loop for (auto&& line : text_split) // Line loop
{ {
@ -274,13 +274,27 @@ void FTextView::insert (const FString& str, int pos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::replaceRange (const FString& str, int from, int to) void FTextView::replaceRange (const FString& str, int from, int to)
{
try
{
deleteRange (from, to);
}
catch (const std::out_of_range&)
{
throw std::out_of_range(""); // Invalid range
}
insert(str, from);
}
//----------------------------------------------------------------------
void FTextView::deleteRange (int from, int to)
{ {
if ( from > to || from >= int(getRows()) || to >= int(getRows()) ) if ( from > to || from >= int(getRows()) || to >= int(getRows()) )
return; throw std::out_of_range(""); // Invalid range
auto iter = data.begin(); auto iter = data.begin();
data.erase (iter + from, iter + to + 1); data.erase (iter + from, iter + to + 1);
insert(str, from);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -79,7 +79,12 @@ class FTermDetection final
uInt8 : 3; // padding bits uInt8 : 3; // padding bits
}; };
struct kittyVersion; // forward declaration struct kittyVersion
{
int primary{0};
int secondary{0};
};
// Constructors // Constructors
FTermDetection(); FTermDetection();
@ -94,137 +99,76 @@ class FTermDetection final
FTermDetection& operator = (const FTermDetection&) = delete; FTermDetection& operator = (const FTermDetection&) = delete;
// Accessor // Accessor
static FString getClassName(); FString getClassName() const;
static const char* getTermType(); const char* getTermType() const;
static int getGnomeTerminalID(); int getGnomeTerminalID() const;
static kittyVersion getKittyVersion(); kittyVersion getKittyVersion() const;
FTerminalType& getTermTypeStruct(); FTerminalType& getTermTypeStruct();
#if DEBUG #if DEBUG
static const FString& getAnswerbackString(); const FString& getAnswerbackString() const;
static const FString& getSecDAString(); const FString& getSecDAString() const;
static const char* getTermType_256color(); const char* getTermType_256color() const;
static const char* getTermType_Answerback(); const char* getTermType_Answerback() const;
static const char* getTermType_SecDA(); const char* getTermType_SecDA() const;
#endif #endif
// Inquiries // Inquiries
static bool isAnsiTerminal(); bool isAnsiTerminal() const;
static bool isXTerminal(); bool isXTerminal() const;
static bool isRxvtTerminal(); bool isRxvtTerminal() const;
static bool isUrxvtTerminal(); bool isUrxvtTerminal() const;
static bool isKdeTerminal(); bool isKdeTerminal() const;
static bool isGnomeTerminal(); bool isGnomeTerminal() const;
static bool isPuttyTerminal(); bool isPuttyTerminal() const;
static bool isWindowsTerminal(); bool isWindowsTerminal() const;
static bool isTeraTerm(); bool isTeraTerm() const;
static bool isCygwinTerminal(); bool isCygwinTerminal() const;
static bool isMinttyTerm(); bool isMinttyTerm() const;
static bool isLinuxTerm(); bool isLinuxTerm() const;
static bool isFreeBSDTerm(); bool isFreeBSDTerm() const;
static bool isNetBSDTerm(); bool isNetBSDTerm() const;
static bool isOpenBSDTerm(); bool isOpenBSDTerm() const;
static bool isSunTerminal(); bool isSunTerminal() const;
static bool isScreenTerm(); bool isScreenTerm() const;
static bool isTmuxTerm(); bool isTmuxTerm() const;
static bool isKtermTerminal(); bool isKtermTerminal() const;
static bool isMltermTerminal(); bool isMltermTerminal() const;
static bool isKittyTerminal(); bool isKittyTerminal() const;
static bool canDisplay256Colors(); bool canDisplay256Colors() const;
static bool hasTerminalDetection(); bool hasTerminalDetection() const;
static bool hasSetCursorStyleSupport(); bool hasSetCursorStyleSupport() const;
// Mutators // Mutators
static void setAnsiTerminal (bool = true); void setAnsiTerminal (bool = true);
static void setXTerminal (bool = true); void setXTerminal (bool = true);
static void setRxvtTerminal (bool = true); void setRxvtTerminal (bool = true);
static void setUrxvtTerminal (bool = true); void setUrxvtTerminal (bool = true);
static void setKdeTerminal (bool = true); void setKdeTerminal (bool = true);
static void setGnomeTerminal (bool = true); void setGnomeTerminal (bool = true);
static void setPuttyTerminal (bool = true); void setPuttyTerminal (bool = true);
static void setWindowsTerminal (bool = true); void setWindowsTerminal (bool = true);
static void setTeraTerm (bool = true); void setTeraTerm (bool = true);
static void setCygwinTerminal (bool = true); void setCygwinTerminal (bool = true);
static void setMinttyTerm (bool = true); void setMinttyTerm (bool = true);
static void setLinuxTerm (bool = true); void setLinuxTerm (bool = true);
static void setFreeBSDTerm (bool = true); void setFreeBSDTerm (bool = true);
static void setNetBSDTerm (bool = true); void setNetBSDTerm (bool = true);
static void setOpenBSDTerm (bool = true); void setOpenBSDTerm (bool = true);
static void setSunTerminal (bool = true); void setSunTerminal (bool = true);
static void setScreenTerm (bool = true); void setScreenTerm (bool = true);
static void setTmuxTerm (bool = true); void setTmuxTerm (bool = true);
static void setKtermTerminal (bool = true); void setKtermTerminal (bool = true);
static void setMltermTerminal (bool = true); void setMltermTerminal (bool = true);
static void setKittyTerminal (bool = true); void setKittyTerminal (bool = true);
static void setTerminalDetection (bool = true); void setTerminalDetection (bool = true);
static void setTtyTypeFileName (const char[]); void setTtyTypeFileName (const char[]);
// Methods // Methods
static void detect(); void detect();
private: private:
struct colorEnv; // forward declaration struct colorEnv
struct secondaryDA; // forward declaration
// Methods
static void deallocation();
static void getSystemTermType();
static bool getTTYtype();
#if F_HAVE_GETTTYNAM
static bool getTTYSFileEntry();
#endif
static void termtypeAnalysis();
static void detectTerminal();
static const char* init_256colorTerminal();
static bool get256colorEnvString();
static const char* termtype_256color_quirks();
static const char* determineMaxColor (const char[]);
static FString getXTermColorName (FColor);
static const char* parseAnswerbackMsg (const char[]);
static FString getAnswerbackMsg();
static const char* parseSecDA (const char[]);
static int str2int (const FString&);
static FString getSecDA();
static const char* secDA_Analysis (const char[]);
static const char* secDA_Analysis_0 (const char[]);
static const char* secDA_Analysis_1 (const char[]);
static const char* secDA_Analysis_24 (const char[]);
static const char* secDA_Analysis_32 (const char[]);
static const char* secDA_Analysis_65 (const char[]);
static const char* secDA_Analysis_67 (const char[]);
static const char* secDA_Analysis_77 (const char[]);
static const char* secDA_Analysis_82 ();
static const char* secDA_Analysis_83 (const char[]);
static const char* secDA_Analysis_84 (const char[]);
static const char* secDA_Analysis_85 ();
static const char* secDA_Analysis_vte (const char[]);
static const char* secDA_Analysis_kitty (const char[]);
// Data members
#if DEBUG
static char termtype_256color[256];
static char termtype_Answerback[256];
static char termtype_SecDA[256];
#endif
static char termtype[256];
static char ttytypename[256];
static bool decscusr_support;
static bool terminal_detection;
static bool color256;
static int gnome_terminal_id;
static const FString* answer_back;
static const FString* sec_da;
static FTerminalType terminal_type;
static colorEnv color_env;
static kittyVersion kitty_version;
static secondaryDA secondary_da;
};
//----------------------------------------------------------------------
// struct FTermDetection::colorEnv
//----------------------------------------------------------------------
struct FTermDetection::colorEnv
{ {
char* string1{nullptr}; char* string1{nullptr};
char* string2{nullptr}; char* string2{nullptr};
@ -236,41 +180,83 @@ struct FTermDetection::colorEnv
char* string8{nullptr}; char* string8{nullptr};
}; };
//---------------------------------------------------------------------- struct secondaryDA
// struct FTermDetection::KittyVersion
//----------------------------------------------------------------------
struct FTermDetection::kittyVersion
{
int primary{0};
int secondary{0};
};
//----------------------------------------------------------------------
// struct FTermDetection::secondaryDA
//----------------------------------------------------------------------
struct FTermDetection::secondaryDA
{ {
int terminal_id_type{-1}; int terminal_id_type{-1};
int terminal_id_version{-1}; int terminal_id_version{-1};
int terminal_id_hardware{-1}; int terminal_id_hardware{-1};
}; };
// Methods
void deallocation();
void getSystemTermType();
bool getTTYtype();
#if F_HAVE_GETTTYNAM
bool getTTYSFileEntry();
#endif
void termtypeAnalysis();
void detectTerminal();
const char* init_256colorTerminal();
bool get256colorEnvString();
const char* termtype_256color_quirks();
const char* determineMaxColor (const char[]);
FString getXTermColorName (FColor);
const char* parseAnswerbackMsg (const char[]);
FString getAnswerbackMsg();
const char* parseSecDA (const char[]);
int str2int (const FString&);
FString getSecDA();
const char* secDA_Analysis (const char[]);
const char* secDA_Analysis_0 (const char[]);
const char* secDA_Analysis_1 (const char[]);
const char* secDA_Analysis_24 (const char[]);
const char* secDA_Analysis_32 (const char[]);
const char* secDA_Analysis_65 (const char[]);
const char* secDA_Analysis_67 (const char[]);
const char* secDA_Analysis_77 (const char[]);
const char* secDA_Analysis_82 ();
const char* secDA_Analysis_83 (const char[]);
const char* secDA_Analysis_84 (const char[]);
const char* secDA_Analysis_85 ();
const char* secDA_Analysis_vte (const char[]);
const char* secDA_Analysis_kitty (const char[]);
// Data members
#if DEBUG
char termtype_256color[256]{};
char termtype_Answerback[256]{};
char termtype_SecDA[256]{};
#endif
char termtype[256]{};
char ttytypename[256]{};
bool decscusr_support{};
bool terminal_detection{};
bool color256{};
int gnome_terminal_id{};
const FString* answer_back{nullptr};
const FString* sec_da{nullptr};
FTerminalType terminal_type{};
colorEnv color_env{};
kittyVersion kitty_version{};
secondaryDA secondary_da{};
};
// FTermDetection inline functions // FTermDetection inline functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString FTermDetection::getClassName() inline FString FTermDetection::getClassName() const
{ return "FTermDetection"; } { return "FTermDetection"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FTermDetection::getTermType() inline const char* FTermDetection::getTermType() const
{ return termtype; } { return termtype; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline int FTermDetection::getGnomeTerminalID() inline int FTermDetection::getGnomeTerminalID() const
{ return gnome_terminal_id; } { return gnome_terminal_id; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FTermDetection::kittyVersion FTermDetection::getKittyVersion() inline FTermDetection::kittyVersion FTermDetection::getKittyVersion() const
{ return kitty_version; } { return kitty_version; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -279,112 +265,112 @@ inline FTermDetection::FTerminalType& FTermDetection::getTermTypeStruct()
#if DEBUG #if DEBUG
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FTermDetection::getTermType_256color() inline const char* FTermDetection::getTermType_256color() const
{ return termtype_256color; } { return termtype_256color; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FTermDetection::getTermType_Answerback() inline const char* FTermDetection::getTermType_Answerback() const
{ return termtype_Answerback; } { return termtype_Answerback; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FTermDetection::getTermType_SecDA() inline const char* FTermDetection::getTermType_SecDA() const
{ return termtype_SecDA; } { return termtype_SecDA; }
#endif #endif
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::canDisplay256Colors() inline bool FTermDetection::canDisplay256Colors() const
{ return color256; } { return color256; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::hasSetCursorStyleSupport() inline bool FTermDetection::hasSetCursorStyleSupport() const
{ return decscusr_support; } { return decscusr_support; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isXTerminal() inline bool FTermDetection::isXTerminal() const
{ return terminal_type.xterm; } { return terminal_type.xterm; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isAnsiTerminal() inline bool FTermDetection::isAnsiTerminal() const
{ return terminal_type.ansi; } { return terminal_type.ansi; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isRxvtTerminal() inline bool FTermDetection::isRxvtTerminal() const
{ return terminal_type.rxvt; } { return terminal_type.rxvt; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isUrxvtTerminal() inline bool FTermDetection::isUrxvtTerminal() const
{ return terminal_type.urxvt; } { return terminal_type.urxvt; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isMltermTerminal() inline bool FTermDetection::isMltermTerminal() const
{ return terminal_type.mlterm; } { return terminal_type.mlterm; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isKittyTerminal() inline bool FTermDetection::isKittyTerminal() const
{ return terminal_type.kitty; } { return terminal_type.kitty; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isPuttyTerminal() inline bool FTermDetection::isPuttyTerminal() const
{ return terminal_type.putty; } { return terminal_type.putty; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isWindowsTerminal() inline bool FTermDetection::isWindowsTerminal() const
{ return terminal_type.win_terminal; } { return terminal_type.win_terminal; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isKdeTerminal() inline bool FTermDetection::isKdeTerminal() const
{ return terminal_type.kde_konsole; } { return terminal_type.kde_konsole; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isGnomeTerminal() inline bool FTermDetection::isGnomeTerminal() const
{ return terminal_type.gnome_terminal; } { return terminal_type.gnome_terminal; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isKtermTerminal() inline bool FTermDetection::isKtermTerminal() const
{ return terminal_type.kterm; } { return terminal_type.kterm; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isTeraTerm() inline bool FTermDetection::isTeraTerm() const
{ return terminal_type.tera_term; } { return terminal_type.tera_term; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isCygwinTerminal() inline bool FTermDetection::isCygwinTerminal() const
{ return terminal_type.cygwin; } { return terminal_type.cygwin; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isMinttyTerm() inline bool FTermDetection::isMinttyTerm() const
{ return terminal_type.mintty; } { return terminal_type.mintty; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isLinuxTerm() inline bool FTermDetection::isLinuxTerm() const
{ return terminal_type.linux_con; } { return terminal_type.linux_con; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isFreeBSDTerm() inline bool FTermDetection::isFreeBSDTerm() const
{ return terminal_type.freebsd_con; } { return terminal_type.freebsd_con; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isNetBSDTerm() inline bool FTermDetection::isNetBSDTerm() const
{ return terminal_type.netbsd_con; } { return terminal_type.netbsd_con; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isOpenBSDTerm() inline bool FTermDetection::isOpenBSDTerm() const
{ return terminal_type.openbsd_con; } { return terminal_type.openbsd_con; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isSunTerminal() inline bool FTermDetection::isSunTerminal() const
{ return terminal_type.sun_con; } { return terminal_type.sun_con; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isScreenTerm() inline bool FTermDetection::isScreenTerm() const
{ return terminal_type.screen; } { return terminal_type.screen; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::isTmuxTerm() inline bool FTermDetection::isTmuxTerm() const
{ return terminal_type.tmux; } { return terminal_type.tmux; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermDetection::hasTerminalDetection() inline bool FTermDetection::hasTerminalDetection() const
{ return terminal_detection; } { return terminal_detection; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -251,10 +251,6 @@ void FTextView::insert (const std::initializer_list<T>& list, int pos)
} }
} }
//----------------------------------------------------------------------
inline void FTextView::deleteRange (int from, int to)
{ replaceRange (FString(), from, to); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTextView::deleteLine (int pos) inline void FTextView::deleteLine (int pos)
{ deleteRange (pos, pos); } { deleteRange (pos, pos); }

View File

@ -119,6 +119,12 @@ std::unique_ptr<T> make_unique (Args&&... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
} }
template<typename Iter>
constexpr std::reverse_iterator<Iter> make_reverse_iterator (Iter iter)
{
return std::reverse_iterator<Iter>(iter);
}
using charSubstitution = std::unordered_map<wchar_t, wchar_t>; using charSubstitution = std::unordered_map<wchar_t, wchar_t>;
struct FCharAttribute struct FCharAttribute

View File

@ -1246,6 +1246,9 @@ void FStringTest::convertToNumberTest()
str = "255"; str = "255";
CPPUNIT_ASSERT ( str.toUShort() == 255U ); CPPUNIT_ASSERT ( str.toUShort() == 255U );
str = "0";
CPPUNIT_ASSERT ( str.toInt() == 0 );
str = "-32768"; str = "-32768";
CPPUNIT_ASSERT ( str.toInt() == -32768 ); CPPUNIT_ASSERT ( str.toInt() == -32768 );
@ -1336,6 +1339,12 @@ void FStringTest::exceptionTest()
CPPUNIT_ASSERT_THROW ( finalcut::FString("abc").toULong() CPPUNIT_ASSERT_THROW ( finalcut::FString("abc").toULong()
, std::invalid_argument ); , std::invalid_argument );
CPPUNIT_ASSERT_THROW ( finalcut::FString("").toULong()
, std::invalid_argument );
CPPUNIT_ASSERT_THROW ( finalcut::FString().toULong()
, std::invalid_argument );
CPPUNIT_ASSERT_THROW ( finalcut::FString("abc")[4] CPPUNIT_ASSERT_THROW ( finalcut::FString("abc")[4]
, std::out_of_range ); , std::out_of_range );
@ -1479,6 +1488,20 @@ void FStringTest::trimTest()
CPPUNIT_ASSERT ( trim_str3.trim().isEmpty() ); CPPUNIT_ASSERT ( trim_str3.trim().isEmpty() );
CPPUNIT_ASSERT ( trim_str3.trim().getLength() == 0 ); CPPUNIT_ASSERT ( trim_str3.trim().getLength() == 0 );
CPPUNIT_ASSERT ( trim_str3.trim().capacity() < std::wstring().max_size() ); CPPUNIT_ASSERT ( trim_str3.trim().capacity() < std::wstring().max_size() );
const finalcut::FString trim_str4 = "x";
CPPUNIT_ASSERT ( trim_str4.ltrim() == "x" );
CPPUNIT_ASSERT ( ! trim_str4.ltrim().isEmpty() );
CPPUNIT_ASSERT ( trim_str4.ltrim().getLength() == 1 );
CPPUNIT_ASSERT ( trim_str4.ltrim().capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( trim_str4.rtrim() == "x" );
CPPUNIT_ASSERT ( ! trim_str4.rtrim().isEmpty() );
CPPUNIT_ASSERT ( trim_str4.rtrim().getLength() == 1 );
CPPUNIT_ASSERT ( trim_str4.rtrim().capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( trim_str4.trim() == "x" );
CPPUNIT_ASSERT ( ! trim_str4.trim().isEmpty() );
CPPUNIT_ASSERT ( trim_str4.trim().getLength() == 1 );
CPPUNIT_ASSERT ( trim_str4.trim().capacity() < std::wstring().max_size() );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -150,6 +150,7 @@ void FTermDetectionTest::ansiTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "ansi", 1); setenv ("TERM", "ansi", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -222,6 +223,7 @@ void FTermDetectionTest::xtermTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm", 1); setenv ("TERM", "xterm", 1);
setenv ("XTERM_VERSION", "XTerm(312)", 1); setenv ("XTERM_VERSION", "XTerm(312)", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
@ -286,6 +288,7 @@ void FTermDetectionTest::rxvtTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "rxvt-cygwin-native", 1); setenv ("TERM", "rxvt-cygwin-native", 1);
setenv ("COLORTERM", "rxvt-xpm", 1); setenv ("COLORTERM", "rxvt-xpm", 1);
setenv ("COLORFGBG", "default;default", 1); setenv ("COLORFGBG", "default;default", 1);
@ -351,6 +354,7 @@ void FTermDetectionTest::urxvtTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "rxvt-unicode-256color", 1); setenv ("TERM", "rxvt-unicode-256color", 1);
setenv ("COLORTERM", "rxvt-xpm", 1); setenv ("COLORTERM", "rxvt-xpm", 1);
setenv ("COLORFGBG", "default;default;0", 1); setenv ("COLORFGBG", "default;default;0", 1);
@ -415,6 +419,7 @@ void FTermDetectionTest::kdeKonsoleTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm-256color", 1); setenv ("TERM", "xterm-256color", 1);
setenv ("COLORTERM", "truecolor", 1); setenv ("COLORTERM", "truecolor", 1);
setenv ("KONSOLE_DBUS_SERVICE", "DCOPRef(konsole-11768,konsole)", 1); setenv ("KONSOLE_DBUS_SERVICE", "DCOPRef(konsole-11768,konsole)", 1);
@ -479,6 +484,7 @@ void FTermDetectionTest::gnomeTerminalTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm-256color", 1); setenv ("TERM", "xterm-256color", 1);
setenv ("COLORTERM", "truecolor", 1); setenv ("COLORTERM", "truecolor", 1);
setenv ("VTE_VERSION", "5202", 1); setenv ("VTE_VERSION", "5202", 1);
@ -543,6 +549,7 @@ void FTermDetectionTest::newerVteTerminalTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm-256color", 1); setenv ("TERM", "xterm-256color", 1);
setenv ("COLORTERM", "truecolor", 1); setenv ("COLORTERM", "truecolor", 1);
setenv ("VTE_VERSION", "5300", 1); setenv ("VTE_VERSION", "5300", 1);
@ -607,6 +614,7 @@ void FTermDetectionTest::puttyTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm", 1); setenv ("TERM", "xterm", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -672,6 +680,7 @@ void FTermDetectionTest::windowsTerminalTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm-256color", 1); setenv ("TERM", "xterm-256color", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -738,6 +747,7 @@ void FTermDetectionTest::teraTermTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm", 1); setenv ("TERM", "xterm", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -802,6 +812,7 @@ void FTermDetectionTest::cygwinTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "cygwin", 1); setenv ("TERM", "cygwin", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -866,6 +877,7 @@ void FTermDetectionTest::minttyTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm-256color", 1); setenv ("TERM", "xterm-256color", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -930,6 +942,7 @@ void FTermDetectionTest::linuxTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "linux", 1); setenv ("TERM", "linux", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -1001,6 +1014,7 @@ void FTermDetectionTest::freebsdTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm", 1); setenv ("TERM", "xterm", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -1075,6 +1089,7 @@ void FTermDetectionTest::netbsdTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "wsvt25", 1); setenv ("TERM", "wsvt25", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -1147,6 +1162,7 @@ void FTermDetectionTest::openbsdTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "vt220", 1); setenv ("TERM", "vt220", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -1218,6 +1234,7 @@ void FTermDetectionTest::sunTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "sun-color", 1); setenv ("TERM", "sun-color", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -1289,6 +1306,7 @@ void FTermDetectionTest::screenTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "screen", 1); setenv ("TERM", "screen", 1);
setenv ("TERMCAP", "SC|screen|VT 100/ANSI X3.64 virtual terminal:...", 1); setenv ("TERMCAP", "SC|screen|VT 100/ANSI X3.64 virtual terminal:...", 1);
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -1359,6 +1377,7 @@ void FTermDetectionTest::tmuxTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "screen", 1); setenv ("TERM", "screen", 1);
setenv ("TMUX", "/tmp/tmux-1000/default,7844,0", 1); setenv ("TMUX", "/tmp/tmux-1000/default,7844,0", 1);
setenv ("TMUX_PANE", "%0", 1); setenv ("TMUX_PANE", "%0", 1);
@ -1430,6 +1449,7 @@ void FTermDetectionTest::ktermTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "kterm", 1); setenv ("TERM", "kterm", 1);
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");
@ -1501,6 +1521,7 @@ void FTermDetectionTest::mltermTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "mlterm", 1); setenv ("TERM", "mlterm", 1);
setenv ("MLTERM", "3.8.4", 1); setenv ("MLTERM", "3.8.4", 1);
setenv ("COLORFGBG", "default;default", 1); setenv ("COLORFGBG", "default;default", 1);
@ -1573,6 +1594,7 @@ void FTermDetectionTest::kittyTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "xterm-kitty", 1); setenv ("TERM", "xterm-kitty", 1);
setenv ("KITTY_WINDOW_ID", "1", 1); setenv ("KITTY_WINDOW_ID", "1", 1);
setenv ("COLORTERM", "truecolor", 1); setenv ("COLORTERM", "truecolor", 1);
@ -1585,7 +1607,7 @@ void FTermDetectionTest::kittyTest()
unsetenv("TMUX"); unsetenv("TMUX");
detect.detect(); detect.detect();
CPPUNIT_ASSERT ( ! detect.isXTerminal() ); CPPUNIT_ASSERT ( detect.isXTerminal() );
CPPUNIT_ASSERT ( ! detect.isAnsiTerminal() ); CPPUNIT_ASSERT ( ! detect.isAnsiTerminal() );
CPPUNIT_ASSERT ( ! detect.isRxvtTerminal() ); CPPUNIT_ASSERT ( ! detect.isRxvtTerminal() );
CPPUNIT_ASSERT ( ! detect.isUrxvtTerminal() ); CPPUNIT_ASSERT ( ! detect.isUrxvtTerminal() );
@ -1675,6 +1697,7 @@ void FTermDetectionTest::ttytypeTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
unsetenv("TERM"); unsetenv("TERM");
unsetenv("TERMCAP"); unsetenv("TERMCAP");
unsetenv("COLORTERM"); unsetenv("COLORTERM");

View File

@ -657,6 +657,7 @@ void ftermfreebsdTest::freebsdConsoleTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
static constexpr int left_alt = 0x38; static constexpr int left_alt = 0x38;
finalcut::FTermFreeBSD freebsd; finalcut::FTermFreeBSD freebsd;
const auto& fsystem = finalcut::FTerm::getFSystem(); const auto& fsystem = finalcut::FTerm::getFSystem();

View File

@ -2109,6 +2109,7 @@ void FTermLinuxTest::linuxConsoleTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "linux", 1); setenv ("TERM", "linux", 1);
setenv ("COLUMNS", "90", 1); setenv ("COLUMNS", "90", 1);
setenv ("LINES", "30", 1); setenv ("LINES", "30", 1);
@ -2233,6 +2234,7 @@ void FTermLinuxTest::linuxConsoleLat15Test()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "linux", 1); setenv ("TERM", "linux", 1);
setenv ("COLUMNS", "90", 1); setenv ("COLUMNS", "90", 1);
setenv ("LINES", "30", 1); setenv ("LINES", "30", 1);
@ -2314,13 +2316,14 @@ void FTermLinuxTest::linuxCursorStyleTest()
// setupterm is needed for tputs in ncurses >= 6.1 // setupterm is needed for tputs in ncurses >= 6.1
setupterm (static_cast<char*>(0), 1, static_cast<int*>(0)); setupterm (static_cast<char*>(0), 1, static_cast<int*>(0));
const auto& term_detection = finalcut::FTerm::getFTermDetection(); auto& term_detection = finalcut::FTerm::getFTermDetection();
finalcut::FTermLinux linux; finalcut::FTermLinux linux;
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "linux", 1); setenv ("TERM", "linux", 1);
setenv ("COLUMNS", "90", 1); setenv ("COLUMNS", "90", 1);
setenv ("LINES", "30", 1); setenv ("LINES", "30", 1);
@ -2511,6 +2514,7 @@ void FTermLinuxTest::linuxColorPaletteTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "linux", 1); setenv ("TERM", "linux", 1);
setenv ("COLUMNS", "90", 1); setenv ("COLUMNS", "90", 1);
setenv ("LINES", "30", 1); setenv ("LINES", "30", 1);
@ -2778,13 +2782,14 @@ void FTermLinuxTest::linuxFontTest()
// setupterm is needed for tputs in ncurses >= 6.1 // setupterm is needed for tputs in ncurses >= 6.1
setupterm (static_cast<char*>(0), 1, static_cast<int*>(0)); setupterm (static_cast<char*>(0), 1, static_cast<int*>(0));
const auto& term_detection = finalcut::FTerm::getFTermDetection(); auto& term_detection = finalcut::FTerm::getFTermDetection();
finalcut::FTermLinux linux; finalcut::FTermLinux linux;
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
setenv ("TERM", "linux", 1); setenv ("TERM", "linux", 1);
setenv ("COLUMNS", "90", 1); setenv ("COLUMNS", "90", 1);
setenv ("LINES", "30", 1); setenv ("LINES", "30", 1);

View File

@ -380,6 +380,7 @@ void ftermopenbsdTest::netbsdConsoleTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
finalcut::FTermOpenBSD netbsd; finalcut::FTermOpenBSD netbsd;
setenv ("TERM", "wsvt25", 1); setenv ("TERM", "wsvt25", 1);
@ -484,6 +485,7 @@ void ftermopenbsdTest::openbsdConsoleTest()
if ( isConEmuChildProcess(pid) ) if ( isConEmuChildProcess(pid) )
{ {
// (gdb) set follow-fork-mode child
finalcut::FTermOpenBSD openbsd; finalcut::FTermOpenBSD openbsd;
setenv ("TERM", "vt220", 1); setenv ("TERM", "vt220", 1);