Refactoring FVTerm::restoreVTerm

This commit is contained in:
Markus Gans 2018-01-05 00:49:00 +01:00
parent f53efc90c5
commit 3419e9e908
11 changed files with 188 additions and 160 deletions

View File

@ -1,4 +1,8 @@
2017-01-02 Markus Gans <guru.mail@muenster.de>
2017-01-05 Markus Gans <guru.mail@muenster.de>
* Refactoring FVTerm::restoreVTerm
* Fixed buffer size in FOptiMove
2017-01-03 Markus Gans <guru.mail@muenster.de>
* Refactoring FOptiMove::relativeMove
* Refactoring attribute settings in FOptiAttr
* Refactoring FTerm::parseKeyString and timeout settings

View File

@ -14,5 +14,5 @@ doc/terminfo-manual.sh
doc/textview.png
doc/TODO
doc/vt100_line_drawing_graphics.png
doc/VTerm.txt
doc/virtual-terminal.txt
doc/xgraphics

View File

@ -21,7 +21,7 @@ EXTRA_DIST = \
textview.png \
TODO \
vt100_line_drawing_graphics.png \
VTerm.txt \
virtual-terminal.txt \
xgraphics
doc_DATA = \
@ -41,5 +41,5 @@ doc_DATA = \
textview.png \
TODO \
vt100_line_drawing_graphics.png \
VTerm.txt \
virtual-terminal.txt \
xgraphics

View File

@ -285,7 +285,7 @@ EXTRA_DIST = \
textview.png \
TODO \
vt100_line_drawing_graphics.png \
VTerm.txt \
virtual-terminal.txt \
xgraphics
doc_DATA = \
@ -305,7 +305,7 @@ doc_DATA = \
textview.png \
TODO \
vt100_line_drawing_graphics.png \
VTerm.txt \
virtual-terminal.txt \
xgraphics
all: all-am

View File

@ -1,3 +1,5 @@
The virtual terminal (vterm)
----------------------------
print(...)
printf(...)

View File

@ -516,7 +516,7 @@ void FListBox::insert (Container container, LazyConverter convert)
conv_type = lazy_convert;
source_container = container;
convertToItem = convert;
size_t size = container->size();
std::size_t size = container->size();
if ( size > 0 )
itemlist.resize(size);

View File

@ -112,6 +112,9 @@ class FOptiMove
void printDurations();
private:
// Constant
static const std::size_t BUF_SIZE = 512;
// Typedefs
typedef unsigned char uChar;
typedef unsigned int uInt;
@ -171,7 +174,7 @@ class FOptiMove
bool automatic_left_margin;
bool eat_nl_glitch;
char move_buf[512];
char move_buf[BUF_SIZE];
int char_duration;
int baudrate;
int tabstop;

View File

@ -329,6 +329,9 @@ class FVTerm : public FTerm
static void scrollAreaReverse (term_area*);
static void clearArea (term_area*, int = ' ');
static char_data generateCharacter (const FPoint&);
static char_data generateCharacter (int, int);
static char_data getCharacter ( character_type
, const FPoint&
, FVTerm* );

View File

@ -651,7 +651,7 @@ int FOptiMove::repeatedAppend ( const capability& o
dst_len = ( dst != 0 ) ? std::strlen(dst) : 0;
total = 0;
if ( (dst_len + uInt(count) * src_len) < sizeof(move_buf) - 1 )
if ( (dst_len + uInt(count) * src_len) < BUF_SIZE - 1 )
{
total += count * o.duration;
@ -693,7 +693,7 @@ int FOptiMove::relativeMove ( char move[]
if ( to_x != from_x ) // horizontal move
{
char hmove[sizeof(move_buf)] = {};
char hmove[BUF_SIZE] = {};
htime = horizontalMove (hmove, from_x, to_x);
if ( htime >= LONG_DURATION )
@ -702,9 +702,9 @@ int FOptiMove::relativeMove ( char move[]
if ( move )
{
if ( *move )
std::strncat (move, hmove, sizeof(move_buf) - std::strlen(move) - 1);
std::strncat (move, hmove, BUF_SIZE - std::strlen(move) - 1);
else
std::strncpy (move, hmove, sizeof(move_buf) - 1);
std::strncpy (move, hmove, BUF_SIZE - 1);
}
}
@ -721,7 +721,7 @@ inline int FOptiMove::verticalMove (char move[], int from_y, int to_y)
if ( move )
std::strncpy ( move
, tparm(F_row_address.cap, to_y, 0, 0, 0, 0, 0, 0, 0, 0)
, sizeof(move_buf) - 1 );
, BUF_SIZE - 1 );
vtime = F_row_address.duration;
}
@ -735,7 +735,7 @@ inline int FOptiMove::verticalMove (char move[], int from_y, int to_y)
if ( move )
std::strncpy ( move
, tparm(F_parm_down_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0)
, sizeof(move_buf) - 1 );
, BUF_SIZE - 1 );
vtime = F_parm_down_cursor.duration;
}
@ -757,7 +757,7 @@ inline int FOptiMove::verticalMove (char move[], int from_y, int to_y)
if ( move )
std::strncpy ( move
, tparm(F_parm_up_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0)
, sizeof(move_buf) - 1 );
, BUF_SIZE - 1 );
vtime = F_parm_up_cursor.duration;
}
@ -777,14 +777,14 @@ inline int FOptiMove::verticalMove (char move[], int from_y, int to_y)
//----------------------------------------------------------------------
inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
{
char str[sizeof(move_buf)] = {};
char str[BUF_SIZE] = {};
int htime = LONG_DURATION;
if ( F_column_address.cap )
{
std::strncat ( hmove
, tparm(F_column_address.cap, to_x, 0, 0, 0, 0, 0, 0, 0, 0)
, sizeof(hmove) - std::strlen(hmove) - 1 );
, BUF_SIZE - std::strlen(hmove) - 1 );
htime = F_column_address.duration;
}
@ -796,7 +796,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
{
std::strncat ( hmove
, tparm(F_parm_right_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0)
, sizeof(hmove) - std::strlen(hmove) - 1 );
, BUF_SIZE - std::strlen(hmove) - 1 );
htime = F_parm_right_cursor.duration;
}
@ -832,7 +832,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
if ( htime_r < htime )
{
std::strncpy (hmove, str, sizeof(move_buf) - 1);
std::strncpy (hmove, str, BUF_SIZE - 1);
htime = htime_r;
}
}
@ -845,7 +845,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
{
std::strncat ( hmove
, tparm(F_parm_left_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0)
, sizeof(hmove) - std::strlen(hmove) - 1 );
, BUF_SIZE - std::strlen(hmove) - 1 );
htime = F_parm_left_cursor.duration;
}
@ -881,7 +881,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
if ( htime_l < htime )
{
std::strncpy (hmove, str, sizeof(move_buf) - 1);
std::strncpy (hmove, str, BUF_SIZE - 1);
htime = htime_l;
}
}
@ -910,7 +910,7 @@ inline bool FOptiMove::isMethod0Faster ( int& move_time
if ( move_xy )
{
char* move_ptr = move_buf;
std::strncpy (move_ptr, move_xy, sizeof(move_buf) - 1);
std::strncpy (move_ptr, move_xy, BUF_SIZE - 1);
move_time = F_cursor_address.duration;
return true;
}
@ -927,7 +927,7 @@ inline bool FOptiMove::isMethod1Faster ( int& move_time
if ( xold >= 0 && yold >= 0 )
{
char null_result[sizeof(move_buf)];
char null_result[BUF_SIZE];
char* null_ptr = null_result;
int new_time = relativeMove (null_ptr, xold, yold, xnew, ynew);
@ -950,7 +950,7 @@ inline bool FOptiMove::isMethod2Faster ( int& move_time
if ( yold >= 0 && F_carriage_return.cap )
{
char null_result[sizeof(move_buf)];
char null_result[BUF_SIZE];
char* null_ptr = null_result;
int new_time = relativeMove (null_ptr, 0, yold, xnew, ynew);
@ -973,7 +973,7 @@ inline bool FOptiMove::isMethod3Faster ( int& move_time
if ( F_cursor_home.cap )
{
char null_result[sizeof(move_buf)];
char null_result[BUF_SIZE];
char* null_ptr = null_result;
int new_time = relativeMove (null_ptr, 0, 0, xnew, ynew);
@ -995,7 +995,7 @@ inline bool FOptiMove::isMethod4Faster ( int& move_time
// Test method 4: home-down + local movement
if ( F_cursor_to_ll.cap )
{
char null_result[sizeof(move_buf)];
char null_result[BUF_SIZE];
char* null_ptr = null_result;
int new_time = relativeMove ( null_ptr
, 0, screen_height - 1
@ -1023,7 +1023,7 @@ inline bool FOptiMove::isMethod5Faster ( int& move_time
&& yold > 0
&& F_cursor_left.cap )
{
char null_result[sizeof(move_buf)];
char null_result[BUF_SIZE];
char* null_ptr = null_result;
int new_time = relativeMove ( null_ptr
, screen_width - 1, yold - 1
@ -1059,20 +1059,20 @@ void FOptiMove::moveByMethod ( int method
case 2:
if ( F_carriage_return.cap )
{
std::strncpy (move_ptr, F_carriage_return.cap, sizeof(move_buf) - 1);
std::strncpy (move_ptr, F_carriage_return.cap, BUF_SIZE - 1);
move_ptr += F_carriage_return.length;
relativeMove (move_ptr, 0, yold, xnew, ynew);
}
break;
case 3:
std::strncpy (move_ptr, F_cursor_home.cap, sizeof(move_buf) - 1);
std::strncpy (move_ptr, F_cursor_home.cap, BUF_SIZE - 1);
move_ptr += F_cursor_home.length;
relativeMove (move_ptr, 0, 0, xnew, ynew);
break;
case 4:
std::strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf) - 1);
std::strncpy (move_ptr, F_cursor_to_ll.cap, BUF_SIZE - 1);
move_ptr += F_cursor_to_ll.length;
relativeMove (move_ptr, 0, screen_height - 1, xnew, ynew);
break;
@ -1083,11 +1083,11 @@ void FOptiMove::moveByMethod ( int method
if ( xold >= 0 )
std::strncat ( move_ptr
, F_carriage_return.cap
, sizeof(move_buf) - std::strlen(move_ptr) - 1 );
, BUF_SIZE - std::strlen(move_ptr) - 1 );
std::strncat ( move_ptr
, F_cursor_left.cap
, sizeof(move_buf) - std::strlen(move_ptr) - 1 );
, BUF_SIZE - std::strlen(move_ptr) - 1 );
move_ptr += std::strlen(move_buf);
relativeMove (move_ptr, screen_width - 1, yold - 1, xnew, ynew);
break;

View File

@ -3186,22 +3186,22 @@ inline char* FTerm::secDA_Analysis_24 (char current_termtype[])
}
//----------------------------------------------------------------------
inline char* FTerm::secDA_Analysis_32 (char current_termtype[])
inline char* FTerm::secDA_Analysis_32 (char[])
{
// Terminal ID 32 - Tera Term
char* new_termtype = current_termtype;
char* new_termtype;
tera_terminal = true;
new_termtype = C_STR("teraterm");
return new_termtype;
}
//----------------------------------------------------------------------
inline char* FTerm::secDA_Analysis_77 (char current_termtype[])
inline char* FTerm::secDA_Analysis_77 (char[])
{
// Terminal ID 77 - mintty
char* new_termtype = current_termtype;
char* new_termtype;
mintty_terminal = true;
new_termtype = C_STR("xterm-256color");
// switch to application escape key mode
@ -4804,15 +4804,15 @@ inline int FTerm::getTermcapKey (char buffer[], int buf_size)
// Looking for termcap key strings in the buffer
assert ( buf_size > 0 );
register int len, n;
for (int i = 0; fc::Fkey[i].tname[0] != 0; i++)
{
char* k = fc::Fkey[i].string;
len = ( k ) ? int(std::strlen(k)) : 0;
register int len = ( k ) ? int(std::strlen(k)) : 0;
if ( k && std::strncmp(k, buffer, uInt(len)) == 0 ) // found
{
register int n;
for (n = len; n < buf_size; n++) // Remove founded entry
buffer[n - len] = buffer[n];

View File

@ -943,10 +943,7 @@ void FVTerm::restoreVTerm (const FRect& box)
void FVTerm::restoreVTerm (int x, int y, int w, int h)
{
char_data* tc; // terminal character
char_data* sc; // shown character
char_data s_ch; // shadow character
char_data i_ch; // inherit background character
FWidget* widget;
char_data sc; // shown character
x--;
y--;
@ -972,88 +969,23 @@ void FVTerm::restoreVTerm (int x, int y, int w, int h)
if ( h < 0 )
return;
widget = static_cast<FWidget*>(vterm->widget);
for (register int ty = 0; ty < h; ty++)
for (int ty = 0; ty < h; ty++)
{
for (register int tx = 0; tx < w; tx++)
int ypos = y + ty;
for (int tx = 0; tx < w; tx++)
{
tc = &vterm->text[(y + ty) * vterm->width + (x + tx)];
sc = &vdesktop->text[(y + ty) * vdesktop->width + (x + tx)];
if ( widget->window_list && ! widget->window_list->empty() )
{
FWidget::widgetList::const_iterator iter, end;
iter = widget->window_list->begin();
end = widget->window_list->end();
for (; iter != end; ++iter)
{
term_area* win = (*iter)->getVWin();
if ( ! win )
continue;
if ( ! win->visible )
continue;
int win_x = win->offset_left;
int win_y = win->offset_top;
FRect geometry ( win_x
, win_y
, win->width + win->right_shadow
, win->height + win->bottom_shadow );
// window visible and contains current character
if ( geometry.contains(tx + x, ty + y) )
{
char_data* tmp;
int line_len = win->width + win->right_shadow;
tmp = &win->text[(ty + y - win_y) * line_len + (tx + x - win_x)];
if ( ! tmp->attr.bit.transparent ) // current character not transparent
{
if ( tmp->attr.bit.trans_shadow ) // transparent shadow
{
// keep the current vterm character
std::memcpy (&s_ch, sc, sizeof(char_data));
s_ch.fg_color = tmp->fg_color;
s_ch.bg_color = tmp->bg_color;
s_ch.attr.bit.reverse = false;
s_ch.attr.bit.standout = false;
if ( s_ch.code == fc::LowerHalfBlock
|| s_ch.code == fc::UpperHalfBlock
|| s_ch.code == fc::LeftHalfBlock
|| s_ch.code == fc::RightHalfBlock
|| s_ch.code == fc::MediumShade
|| s_ch.code == fc::FullBlock )
s_ch.code = ' ';
sc = &s_ch;
}
else if ( tmp->attr.bit.inherit_bg )
{
// add the covered background to this character
std::memcpy (&i_ch, tmp, sizeof(char_data));
i_ch.bg_color = sc->bg_color; // last background color;
sc = &i_ch;
}
else // default
sc = tmp;
}
}
}
int xpos = x + tx;
tc = &vterm->text[ypos * vterm->width + xpos];
sc = generateCharacter(xpos, ypos);
std::memcpy (tc, &sc, sizeof(char_data));
}
std::memcpy (tc, sc, sizeof(char_data));
if ( short(vterm->changes[ypos].xmin) > x )
vterm->changes[ypos].xmin = uInt(x);
if ( short(vterm->changes[y + ty].xmin) > x )
vterm->changes[y + ty].xmin = uInt(x);
if ( short(vterm->changes[y + ty].xmax) < x + w - 1 )
vterm->changes[y + ty].xmax = uInt(x + w - 1);
}
if ( short(vterm->changes[ypos].xmax) < x + w - 1 )
vterm->changes[ypos].xmax = uInt(x + w - 1);
}
}
@ -1986,6 +1918,90 @@ void FVTerm::clearArea (term_area* area, int fillchar)
area->has_changes = true;
}
//----------------------------------------------------------------------
FVTerm::char_data FVTerm::generateCharacter (const FPoint& pos)
{
// Generates characters for a given position considering all areas
return generateCharacter (pos.getX(), pos.getY());
}
//----------------------------------------------------------------------
FVTerm::char_data FVTerm::generateCharacter (int x, int y)
{
// Generates characters for a given position considering all areas
FWidget::widgetList::const_iterator iter, end;
char_data* sc; // shown character
char_data s_ch; // shadow character
char_data i_ch; // inherit background character
FWidget* widget;
widget = static_cast<FWidget*>(vterm->widget);
sc = &vdesktop->text[y * vdesktop->width + x];
if ( ! widget->window_list || widget->window_list->empty() )
return *sc;
iter = widget->window_list->begin();
end = widget->window_list->end();
for (; iter != end; ++iter)
{
term_area* win = (*iter)->getVWin();
if ( ! win || ! win->visible )
continue;
int win_x = win->offset_left;
int win_y = win->offset_top;
FRect geometry ( win_x
, win_y
, win->width + win->right_shadow
, win->height + win->bottom_shadow );
// Window is visible and contains current character
if ( geometry.contains(x, y) )
{
char_data* tmp;
int line_len = win->width + win->right_shadow;
tmp = &win->text[(y - win_y) * line_len + (x - win_x)];
if ( ! tmp->attr.bit.transparent ) // Current character not transparent
{
if ( tmp->attr.bit.trans_shadow ) // Transparent shadow
{
// Keep the current vterm character
std::memcpy (&s_ch, sc, sizeof(char_data));
s_ch.fg_color = tmp->fg_color;
s_ch.bg_color = tmp->bg_color;
s_ch.attr.bit.reverse = false;
s_ch.attr.bit.standout = false;
if ( s_ch.code == fc::LowerHalfBlock
|| s_ch.code == fc::UpperHalfBlock
|| s_ch.code == fc::LeftHalfBlock
|| s_ch.code == fc::RightHalfBlock
|| s_ch.code == fc::MediumShade
|| s_ch.code == fc::FullBlock )
s_ch.code = ' ';
sc = &s_ch;
}
else if ( tmp->attr.bit.inherit_bg )
{
// Add the covered background to this character
std::memcpy (&i_ch, tmp, sizeof(char_data));
i_ch.bg_color = sc->bg_color; // Last background color
sc = &i_ch;
}
else // Default
sc = tmp;
}
}
}
return *sc;
}
//----------------------------------------------------------------------
FVTerm::char_data FVTerm::getCharacter ( character_type type
, const FPoint& pos
@ -2031,7 +2047,7 @@ FVTerm::char_data FVTerm::getCharacter ( character_type char_type
if ( w->window_list && ! w->window_list->empty() )
{
FWidget::widgetList::const_iterator iter, end;
// get the window layer of this object
// Get the window layer of this object
int layer = FWindow::getWindowLayer(w);
iter = w->window_list->begin();
end = w->window_list->end();
@ -2064,19 +2080,19 @@ FVTerm::char_data FVTerm::getCharacter ( character_type char_type
, win->width + win->right_shadow
, win->height + win->bottom_shadow );
// window visible and contains current character
// Window visible and contains current character
if ( geometry.contains(x, y) )
{
char_data* tmp;
int line_len = win->width + win->right_shadow;
tmp = &win->text[(y - win_y) * line_len + (x - win_x)];
// current character not transparent
// Current character not transparent
if ( ! tmp->attr.bit.transparent )
{
if ( tmp->attr.bit.trans_shadow ) // transparent shadow
{
// keep the current vterm character
// Keep the current vterm character
std::memcpy (&s_ch, cc, sizeof(char_data));
s_ch.fg_color = tmp->fg_color;
s_ch.bg_color = tmp->bg_color;
@ -2086,7 +2102,7 @@ FVTerm::char_data FVTerm::getCharacter ( character_type char_type
}
else if ( tmp->attr.bit.inherit_bg )
{
// add the covered background to this character
// Add the covered background to this character
std::memcpy (&i_ch, tmp, sizeof(char_data));
i_ch.bg_color = cc->bg_color; // last background color
cc = &i_ch;