Solved problem detecting terminal size on quick changes

This commit is contained in:
Markus Gans 2019-08-18 02:04:44 +02:00
parent 4075e6e1ed
commit ad2766e706
14 changed files with 157 additions and 51 deletions

View File

@ -1,3 +1,6 @@
2019-08-18 Markus Gans <guru.mail@muenster.de>
* Solved problem detecting terminal size on quick changes
2019-08-11 Markus Gans <guru.mail@muenster.de> 2019-08-11 Markus Gans <guru.mail@muenster.de>
* FRect has now got a scaleBy() method * FRect has now got a scaleBy() method
* Convert drawBorder() to a non-member function using FRect * Convert drawBorder() to a non-member function using FRect

View File

@ -226,7 +226,8 @@ void tcapString (const std::string& name, const char cap_str[])
#if DEBUG #if DEBUG
void debug (finalcut::FApplication& TermApp) void debug (finalcut::FApplication& TermApp)
{ {
finalcut::FTermDebugData& debug_data = TermApp.getFTermDebugData(); auto& fterm = TermApp.getFTerm();
auto& debug_data = fterm.getFTermDebugData();
const finalcut::FString& ab_s = debug_data.getAnswerbackString(); const finalcut::FString& ab_s = debug_data.getAnswerbackString();
const finalcut::FString& sec_da = debug_data.getSecDAString(); const finalcut::FString& sec_da = debug_data.getSecDAString();
std::cout << "\n.------------------- debug -------------------\r\n"; std::cout << "\n.------------------- debug -------------------\r\n";

View File

@ -21,18 +21,23 @@
***********************************************************************/ ***********************************************************************/
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
#undef __STRICT_ANSI__ // need for realpath and strdup #undef __STRICT_ANSI__ // need for strdup
#include <strings.h> // need for strcasecmp #include <strings.h> // need for strcasecmp
#endif #endif
#include <pwd.h>
#include <vector> #include <vector>
#include "final/fevent.h" #include "final/fevent.h"
#include "final/fsystem.h"
#include "final/ffiledialog.h" #include "final/ffiledialog.h"
namespace finalcut namespace finalcut
{ {
// static class attributes
FSystem* FFileDialog::fsystem = nullptr;
// non-member functions // non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool sortByName ( const FFileDialog::dir_entry& lhs bool sortByName ( const FFileDialog::dir_entry& lhs
@ -200,7 +205,7 @@ void FFileDialog::setPath (const FString& dir)
return; return;
} }
if ( realpath(dir.c_str(), resolved_path) != 0 ) if ( fsystem->realpath(dir.c_str(), resolved_path) != 0 )
r_dir = resolved_path; r_dir = resolved_path;
else else
r_dir = dir; r_dir = dir;
@ -321,7 +326,10 @@ void FFileDialog::init()
{ {
static constexpr std::size_t w = 42; static constexpr std::size_t w = 42;
static constexpr std::size_t h = 15; static constexpr std::size_t h = 15;
int x, y; int x{}, y{};
if ( ! fsystem )
fsystem = FTerm::getFSystem();
setGeometry(FPoint(1, 1), FSize(w, h), false); setGeometry(FPoint(1, 1), FSize(w, h), false);
auto parent_widget = getParentWidget(); auto parent_widget = getParentWidget();
@ -602,6 +610,9 @@ void FFileDialog::followSymLink (const char* const dir, dir_entry& entry)
char symLink[MAXPATHLEN] = { }; char symLink[MAXPATHLEN] = { };
struct stat sb; struct stat sb;
if ( ! fsystem )
fsystem = FTerm::getFSystem();
std::strncpy (symLink, dir, sizeof(symLink)); std::strncpy (symLink, dir, sizeof(symLink));
symLink[sizeof(symLink) - 1] = '\0'; symLink[sizeof(symLink) - 1] = '\0';
std::strncat ( symLink std::strncat ( symLink
@ -609,7 +620,7 @@ void FFileDialog::followSymLink (const char* const dir, dir_entry& entry)
, sizeof(symLink) - std::strlen(symLink) - 1); , sizeof(symLink) - std::strlen(symLink) - 1);
symLink[sizeof(symLink) - 1] = '\0'; symLink[sizeof(symLink) - 1] = '\0';
if ( realpath(symLink, resolved_path) == 0 ) if ( fsystem->realpath(symLink, resolved_path) == 0 )
return; // Cannot follow the symlink return; // Cannot follow the symlink
if ( lstat(resolved_path, &sb) == -1 ) if ( lstat(resolved_path, &sb) == -1 )
@ -665,6 +676,9 @@ int FFileDialog::changeDir (const FString& dirname)
FString lastdir = directory; FString lastdir = directory;
FString newdir = dirname; FString newdir = dirname;
if ( ! fsystem )
fsystem = FTerm::getFSystem();
if ( newdir.includes('~') ) if ( newdir.includes('~') )
newdir = newdir.replace('~', getHomeDir()); newdir = newdir.replace('~', getHomeDir());
@ -733,7 +747,12 @@ const FString FFileDialog::getHomeDir()
struct passwd* pwd_ptr; struct passwd* pwd_ptr;
char buf[1024]; char buf[1024];
if ( getpwuid_r (geteuid(), &pwd, buf, sizeof(buf), &pwd_ptr) ) if ( ! fsystem )
fsystem = FTerm::getFSystem();
uid_t euid = fsystem->geteuid();
if ( fsystem->getpwuid_r(euid, &pwd, buf, sizeof(buf), &pwd_ptr) )
return FString(""); return FString("");
else else
return FString(pwd.pw_dir); return FString(pwd.pw_dir);

View File

@ -895,25 +895,18 @@ void FTerm::detectTermSize()
data = FTerm::getFTermData(); data = FTerm::getFTermData();
struct winsize win_size; struct winsize win_size;
bool close_after_detect = false;
int fd = data->getTTYFileDescriptor();
int ret;
if ( fd < 0 ) // console is closed
{
if ( openConsole() != 0 )
return;
fd = data->getTTYFileDescriptor();
close_after_detect = true;
}
auto& term_geometry = data->getTermGeometry(); auto& term_geometry = data->getTermGeometry();
int ret;
errno = 0;
if ( fsys ) do
ret = fsys->ioctl (fd, TIOCGWINSZ, &win_size); {
else if ( fsys )
ret = -1; ret = fsys->ioctl (FTermios::getStdOut(), TIOCGWINSZ, &win_size);
else
ret = -1;
}
while (errno == EINTR);
if ( ret != 0 || win_size.ws_col == 0 || win_size.ws_row == 0 ) if ( ret != 0 || win_size.ws_col == 0 || win_size.ws_row == 0 )
{ {
@ -933,9 +926,6 @@ void FTerm::detectTermSize()
if ( opti_move ) if ( opti_move )
opti_move->setTermSize ( term_geometry.getWidth() opti_move->setTermSize ( term_geometry.getWidth()
, term_geometry.getHeight() ); , term_geometry.getHeight() );
if ( close_after_detect )
closeConsole();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2549,7 +2539,8 @@ void FTerm::signal_handler (int signum)
case SIGWINCH: case SIGWINCH:
if ( ! data ) if ( ! data )
break; break;
else if ( data->hasTermResized() )
if ( data->hasTermResized() )
break; break;
// initialize a resize event to the root element // initialize a resize event to the root element

View File

@ -286,7 +286,7 @@ void FTermcap::termcapKeysVt100 (char*& buffer)
const char* key_up_string = tgetstr(C_STR("ku"), &buffer); const char* key_up_string = tgetstr(C_STR("ku"), &buffer);
if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0)) if ( (key_up_string && (std::strcmp(key_up_string, ESC "OA") == 0))
|| ( TCAP(fc::t_cursor_up) || ( TCAP(fc::t_cursor_up)
&& (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) ) && (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) )
{ {

View File

@ -262,6 +262,12 @@ void FVTerm::updateTerminal()
} }
} }
// Check terminal size has changed
auto data = getFTerm().getFTermData();
if ( data->hasTermResized() )
return;
// Update data on VTerm // Update data on VTerm
updateVTerm(); updateVTerm();
@ -2511,7 +2517,7 @@ void FVTerm::updateTerminalLine (uInt y)
uInt& xmin = vt->changes[y].xmin; uInt& xmin = vt->changes[y].xmin;
uInt& xmax = vt->changes[y].xmax; uInt& xmax = vt->changes[y].xmax;
if ( xmin <= xmax ) if ( xmin <= xmax ) // Line has changes
{ {
bool draw_leading_ws = false; bool draw_leading_ws = false;
bool draw_trailing_ws = false; bool draw_trailing_ws = false;

View File

@ -27,6 +27,7 @@
#include "final/fmenubar.h" #include "final/fmenubar.h"
#include "final/fstatusbar.h" #include "final/fstatusbar.h"
#include "final/fstring.h" #include "final/fstring.h"
#include "final/ftermdata.h"
#include "final/fwidget.h" #include "final/fwidget.h"
#include "final/fwidgetcolors.h" #include "final/fwidgetcolors.h"
@ -1020,10 +1021,14 @@ void FWidget::resize()
{ {
if ( isRootWidget() ) if ( isRootWidget() )
{ {
FRect old_term_geometry = getTermGeometry();
detectTermSize(); detectTermSize();
FRect term_geometry = getTermGeometry(); FRect term_geometry = getTermGeometry();
term_geometry.move (-1, -1); term_geometry.move (-1, -1);
if ( old_term_geometry.getSize() == term_geometry.getSize() )
return;
resizeVTerm (term_geometry.getSize()); resizeVTerm (term_geometry.getSize());
resizeArea (term_geometry, getShadow(), vdesktop); resizeArea (term_geometry, getShadow(), vdesktop);
adjustSizeGlobal(); adjustSizeGlobal();

View File

@ -68,7 +68,6 @@
#include <dirent.h> #include <dirent.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <libgen.h> #include <libgen.h>
#include <pwd.h>
#include <unistd.h> #include <unistd.h>
#include <string> #include <string>
@ -86,6 +85,9 @@
namespace finalcut namespace finalcut
{ {
// class forward declaration
class FSystem;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FFileDialog // class FFileDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -195,17 +197,18 @@ class FFileDialog : public FDialog
void cb_processShowHidden (FWidget*, FDataPtr); void cb_processShowHidden (FWidget*, FDataPtr);
// Data Members // Data Members
DIR* directory_stream{nullptr}; static FSystem* fsystem;
dirEntries dir_entries{}; DIR* directory_stream{nullptr};
FString directory{}; dirEntries dir_entries{};
FString filter_pattern{}; FString directory{};
FLineEdit filename{this}; FString filter_pattern{};
FListBox filebrowser{this}; FLineEdit filename{this};
FCheckBox hidden_check{this}; FListBox filebrowser{this};
FButton cancel_btn{this}; FCheckBox hidden_check{this};
FButton open_btn{this}; FButton cancel_btn{this};
DialogType dlg_type{FFileDialog::Open}; FButton open_btn{this};
bool show_hidden{false}; DialogType dlg_type{FFileDialog::Open};
bool show_hidden{false};
// Friend functions // Friend functions
friend bool sortByName ( const FFileDialog::dir_entry& friend bool sortByName ( const FFileDialog::dir_entry&

View File

@ -35,6 +35,7 @@
#error "Only <final/final.h> can be included directly." #error "Only <final/final.h> can be included directly."
#endif #endif
#include <pwd.h>
#include "final/ftypes.h" #include "final/ftypes.h"
namespace finalcut namespace finalcut
@ -68,6 +69,10 @@ class FSystem
virtual int putchar (int) = 0; virtual int putchar (int) = 0;
virtual int tputs (const char*, int, int (*)(int)) = 0; virtual int tputs (const char*, int, int (*)(int)) = 0;
virtual uid_t getuid() = 0; virtual uid_t getuid() = 0;
virtual uid_t geteuid() = 0;
virtual int getpwuid_r ( uid_t, struct passwd*, char*, size_t ,
struct passwd**) = 0;
virtual char* realpath (const char*, char*) = 0;
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@ -61,6 +61,10 @@
#undef buttons // from term.h #undef buttons // from term.h
#endif #endif
#if defined(__CYGWIN__)
#undef __STRICT_ANSI__ // need for realpath and strdup
#endif
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -71,7 +75,6 @@
#include "final/fc.h" #include "final/fc.h"
#include "final/fsystem.h" #include "final/fsystem.h"
namespace finalcut namespace finalcut
{ {
@ -190,6 +193,22 @@ class FSystemImpl : public FSystem
{ {
return ::getuid(); return ::getuid();
} }
uid_t geteuid() override
{
return ::geteuid();
}
int getpwuid_r ( uid_t uid, struct passwd* pwd
, char* buf, size_t buflen, struct passwd** result )
{
return ::getpwuid_r (uid, pwd, buf, buflen, result);
}
char* realpath (const char* path, char* resolved_path) override
{
return ::realpath(path, resolved_path);
}
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@ -159,9 +159,6 @@ class FVTerm
static char* getTermType(); static char* getTermType();
static char* getTermFileName(); static char* getTermFileName();
FTerm& getFTerm(); FTerm& getFTerm();
#if DEBUG
FTermDebugData& getFTermDebugData();
#endif
// Mutators // Mutators
void setTermXY (int, int); void setTermXY (int, int);
@ -637,12 +634,6 @@ inline char* FVTerm::getTermFileName()
inline FTerm& FVTerm::getFTerm() inline FTerm& FVTerm::getFTerm()
{ return *fterm; } { return *fterm; }
//----------------------------------------------------------------------
#if DEBUG
inline FTermDebugData& FVTerm::getFTermDebugData()
{ return getFTerm().getFTermDebugData(); }
#endif
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::hideCursor() inline void FVTerm::hideCursor()
{ return hideCursor(true); } { return hideCursor(true); }

View File

@ -66,6 +66,8 @@ class FSystemTest : public finalcut::FSystem
int putchar (int) override; int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override; int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override; uid_t getuid() override;
uid_t geteuid() override;
char* realpath (const char*, char*) override;
std::string& getCharacters(); std::string& getCharacters();
int& getCursorType(); int& getCursorType();
struct keymap_t& getTerminalKeymap(); struct keymap_t& getTerminalKeymap();
@ -534,6 +536,25 @@ uid_t FSystemTest::getuid()
return 0; return 0;
} }
//----------------------------------------------------------------------
uid_t FSystemTest::geteuid()
{
return 0;
}
//----------------------------------------------------------------------
int FSystemTest::getpwuid_r ( uid_t, struct passwd*, char*, size_t
, struct passwd** )
{
return 0;
}
//----------------------------------------------------------------------
char* FSystemTest::realpath (const char*, char*);
{
return "";
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::string& FSystemTest::getCharacters() std::string& FSystemTest::getCharacters()
{ {

View File

@ -116,6 +116,8 @@ class FSystemTest : public finalcut::FSystem
int putchar (int) override; int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override; int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override; uid_t getuid() override;
uid_t geteuid() override;
char* realpath (const char*, char*) override;
rgb& getRGB (std::size_t); rgb& getRGB (std::size_t);
console_font_op& getConsoleFont(); console_font_op& getConsoleFont();
shiftstate& getShiftState(); shiftstate& getShiftState();
@ -1348,6 +1350,25 @@ uid_t FSystemTest::getuid()
return 0; return 0;
} }
//----------------------------------------------------------------------
uid_t FSystemTest::geteuid()
{
return 0;
}
//----------------------------------------------------------------------
int FSystemTest::getpwuid_r ( uid_t, struct passwd*, char*, size_t
, struct passwd** )
{
return 0;
}
//----------------------------------------------------------------------
char* FSystemTest::realpath (const char*, char*);
{
return "";
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FSystemTest::rgb& FSystemTest::getRGB (std::size_t i) FSystemTest::rgb& FSystemTest::getRGB (std::size_t i)
{ {

View File

@ -84,6 +84,8 @@ class FSystemTest : public finalcut::FSystem
int putchar (int) override; int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override; int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override; uid_t getuid() override;
uid_t geteuid() override;
char* realpath (const char*, char*) override;
wskbd_bell_data& getBell(); wskbd_bell_data& getBell();
private: private:
@ -274,6 +276,25 @@ uid_t FSystemTest::getuid()
return 0; return 0;
} }
//----------------------------------------------------------------------
uid_t FSystemTest::geteuid()
{
return 0;
}
//----------------------------------------------------------------------
int FSystemTest::getpwuid_r ( uid_t, struct passwd*, char*, size_t
, struct passwd** )
{
return 0;
}
//----------------------------------------------------------------------
char* FSystemTest::realpath (const char*, char*);
{
return "";
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
wskbd_bell_data& FSystemTest::getBell() wskbd_bell_data& FSystemTest::getBell()
{ {