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>
* FRect has now got a scaleBy() method
* 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
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& sec_da = debug_data.getSecDAString();
std::cout << "\n.------------------- debug -------------------\r\n";

View File

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

View File

@ -895,25 +895,18 @@ void FTerm::detectTermSize()
data = FTerm::getFTermData();
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();
int ret;
errno = 0;
if ( fsys )
ret = fsys->ioctl (fd, TIOCGWINSZ, &win_size);
else
ret = -1;
do
{
if ( fsys )
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 )
{
@ -933,9 +926,6 @@ void FTerm::detectTermSize()
if ( opti_move )
opti_move->setTermSize ( term_geometry.getWidth()
, term_geometry.getHeight() );
if ( close_after_detect )
closeConsole();
}
//----------------------------------------------------------------------
@ -2549,7 +2539,8 @@ void FTerm::signal_handler (int signum)
case SIGWINCH:
if ( ! data )
break;
else if ( data->hasTermResized() )
if ( data->hasTermResized() )
break;
// 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);
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)
&& (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
updateVTerm();
@ -2511,7 +2517,7 @@ void FVTerm::updateTerminalLine (uInt y)
uInt& xmin = vt->changes[y].xmin;
uInt& xmax = vt->changes[y].xmax;
if ( xmin <= xmax )
if ( xmin <= xmax ) // Line has changes
{
bool draw_leading_ws = false;
bool draw_trailing_ws = false;

View File

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

View File

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

View File

@ -35,6 +35,7 @@
#error "Only <final/final.h> can be included directly."
#endif
#include <pwd.h>
#include "final/ftypes.h"
namespace finalcut
@ -68,6 +69,10 @@ class FSystem
virtual int putchar (int) = 0;
virtual int tputs (const char*, int, int (*)(int)) = 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)

View File

@ -61,6 +61,10 @@
#undef buttons // from term.h
#endif
#if defined(__CYGWIN__)
#undef __STRICT_ANSI__ // need for realpath and strdup
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
@ -71,7 +75,6 @@
#include "final/fc.h"
#include "final/fsystem.h"
namespace finalcut
{
@ -190,6 +193,22 @@ class FSystemImpl : public FSystem
{
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)

View File

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

View File

@ -66,6 +66,8 @@ class FSystemTest : public finalcut::FSystem
int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override;
uid_t geteuid() override;
char* realpath (const char*, char*) override;
std::string& getCharacters();
int& getCursorType();
struct keymap_t& getTerminalKeymap();
@ -534,6 +536,25 @@ uid_t FSystemTest::getuid()
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()
{

View File

@ -116,6 +116,8 @@ class FSystemTest : public finalcut::FSystem
int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override;
uid_t geteuid() override;
char* realpath (const char*, char*) override;
rgb& getRGB (std::size_t);
console_font_op& getConsoleFont();
shiftstate& getShiftState();
@ -1348,6 +1350,25 @@ uid_t FSystemTest::getuid()
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)
{

View File

@ -84,6 +84,8 @@ class FSystemTest : public finalcut::FSystem
int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override;
uid_t geteuid() override;
char* realpath (const char*, char*) override;
wskbd_bell_data& getBell();
private:
@ -274,6 +276,25 @@ uid_t FSystemTest::getuid()
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()
{