mirror of https://github.com/rfivet/uemacs.git
Refactoring display primitives.
This commit is contained in:
parent
109e330861
commit
79c3dfa4d9
269
display.c
269
display.c
|
@ -80,8 +80,12 @@ static int scrolls(int inserts);
|
|||
static void scrscroll( int from, int to, int count) ;
|
||||
static int texttest( int vrow, int prow) ;
|
||||
static int endofline( unicode_t *s, int n) ;
|
||||
static void upddex( void) ;
|
||||
static void updext( void) ;
|
||||
static void updgar( void) ;
|
||||
static void updpos( void) ;
|
||||
static int updateline( int row, video_p vp1, video_p vp2) ;
|
||||
static boolean updupd( boolean force_f) ;
|
||||
static void modeline( window_p wp) ;
|
||||
static void mlputi( int i, int r) ;
|
||||
static void mlputli( long l, int r) ;
|
||||
|
@ -227,8 +231,8 @@ static int vtputs( const char *s) {
|
|||
return n ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase from the end of the software cursor to the end of the line on which
|
||||
|
||||
/* Erase from the end of the software cursor to the end of the line on which
|
||||
* the software cursor is located.
|
||||
*/
|
||||
static void vteeol( void) {
|
||||
|
@ -260,7 +264,7 @@ static int scrflags;
|
|||
|
||||
boolean force_f ; force update past type ahead?
|
||||
*/
|
||||
int update( boolean force_f) {
|
||||
boolean update( boolean force_f) {
|
||||
#if TYPEAH && ! PKCODE
|
||||
if( force_f == FALSE && typahead())
|
||||
return TRUE ;
|
||||
|
@ -340,8 +344,8 @@ int update( boolean force_f) {
|
|||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* reframe:
|
||||
|
||||
/* reframe:
|
||||
* check to see if the cursor is on in the window
|
||||
* and re-frame it if needed or wanted
|
||||
*/
|
||||
|
@ -428,8 +432,7 @@ static int reframe( window_p wp) {
|
|||
return TRUE ;
|
||||
}
|
||||
|
||||
static void show_line( line_p lp)
|
||||
{
|
||||
static void show_line( line_p lp) {
|
||||
int i = 0, len = llength( lp) ;
|
||||
|
||||
while( i < len) {
|
||||
|
@ -439,24 +442,18 @@ static void show_line( line_p lp)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* updone:
|
||||
|
||||
/* updone:
|
||||
* update the current line to the virtual screen
|
||||
*
|
||||
* window_p wp; window to update current line in
|
||||
*/
|
||||
static void updone(window_p wp)
|
||||
{
|
||||
line_p lp; /* line to update */
|
||||
int sline; /* physical screen line to update */
|
||||
|
||||
static void updone( window_p wp) {
|
||||
/* search down the line we want */
|
||||
lp = wp->w_linep;
|
||||
sline = wp->w_toprow;
|
||||
while (lp != wp->w_dotp) {
|
||||
int sline = wp->w_toprow ; /* physical screen line to update */
|
||||
line_p lp ;
|
||||
for( lp = wp->w_linep ; lp != wp->w_dotp ; lp = lforw( lp))
|
||||
++sline ;
|
||||
lp = lforw(lp);
|
||||
}
|
||||
|
||||
/* and update the virtual line */
|
||||
vscreen[ sline]->v_flag |= VFCHG ;
|
||||
|
@ -470,22 +467,17 @@ static void updone(window_p wp)
|
|||
vteeol() ;
|
||||
}
|
||||
|
||||
/*
|
||||
* updall:
|
||||
|
||||
/* updall:
|
||||
* update all the lines in a window on the virtual screen
|
||||
*
|
||||
* window_p wp; window to update lines in
|
||||
*/
|
||||
static void updall(window_p wp)
|
||||
{
|
||||
line_p lp; /* line to update */
|
||||
int sline; /* physical screen line to update */
|
||||
|
||||
static void updall( window_p wp) {
|
||||
/* search down the lines, updating them */
|
||||
lp = wp->w_linep;
|
||||
sline = wp->w_toprow;
|
||||
line_p lp = wp->w_linep ; /* line to update */
|
||||
int sline = wp->w_toprow ; /* physical screen line to update */
|
||||
while( sline < wp->w_toprow + wp->w_ntrows) {
|
||||
|
||||
/* and update the virtual line */
|
||||
vscreen[ sline]->v_flag |= VFCHG ;
|
||||
vscreen[ sline]->v_flag &= ~VFREQ ;
|
||||
|
@ -504,7 +496,6 @@ static void updall(window_p wp)
|
|||
vteeol() ;
|
||||
++sline ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -512,7 +503,7 @@ static void updall(window_p wp)
|
|||
update the position of the hardware cursor and handle extended lines.
|
||||
This is the only update for simple moves.
|
||||
*/
|
||||
void updpos(void) {
|
||||
static void updpos( void) {
|
||||
/* find the current row */
|
||||
line_p lp = curwp->w_linep ;
|
||||
currow = curwp->w_toprow ;
|
||||
|
@ -546,26 +537,18 @@ void updpos(void) {
|
|||
lbound = 0 ;
|
||||
}
|
||||
|
||||
/*
|
||||
* upddex:
|
||||
|
||||
/* upddex:
|
||||
* de-extend any line that deserves it
|
||||
*/
|
||||
void upddex(void)
|
||||
{
|
||||
window_p wp;
|
||||
line_p lp;
|
||||
int i;
|
||||
|
||||
wp = wheadp;
|
||||
|
||||
while (wp != NULL) {
|
||||
lp = wp->w_linep;
|
||||
i = wp->w_toprow;
|
||||
|
||||
while (i < wp->w_toprow + wp->w_ntrows) {
|
||||
static void upddex( void) {
|
||||
for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
|
||||
line_p lp = wp->w_linep ;
|
||||
for( int i = wp->w_toprow ; i < wp->w_toprow + wp->w_ntrows ; i++) {
|
||||
if( vscreen[ i]->v_flag & VFEXT) {
|
||||
if ((wp != curwp) || (lp != wp->w_dotp) ||
|
||||
(curcol < term.t_ncol - 1)) {
|
||||
if( (wp != curwp)
|
||||
|| (lp != wp->w_dotp)
|
||||
|| (curcol < term.t_ncol - 1)) {
|
||||
vtmove( i, 0) ;
|
||||
show_line( lp) ;
|
||||
vteeol() ;
|
||||
|
@ -575,25 +558,19 @@ void upddex(void)
|
|||
vscreen[ i]->v_flag |= VFCHG ;
|
||||
}
|
||||
}
|
||||
|
||||
lp = lforw( lp) ;
|
||||
++i;
|
||||
}
|
||||
/* and onward to the next window */
|
||||
wp = wp->w_wndp;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* updgar:
|
||||
|
||||
/* updgar:
|
||||
* if the screen is garbage, clear the physical screen and
|
||||
* the virtual screen and force a full update
|
||||
*/
|
||||
void updgar(void)
|
||||
{
|
||||
unicode_t *txt;
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < term.t_nrow; ++i) {
|
||||
static void updgar( void) {
|
||||
for( int i = 0 ; i < term.t_nrow ; ++i) {
|
||||
vscreen[ i]->v_flag |= VFCHG ;
|
||||
#if REVSTA
|
||||
vscreen[ i]->v_flag &= ~VFREV ;
|
||||
|
@ -603,14 +580,14 @@ void updgar(void)
|
|||
vscreen[ i]->v_bcolor = gbcolor ;
|
||||
#endif
|
||||
#if MEMMAP == 0 || SCROLLCODE
|
||||
txt = pscreen[i]->v_text;
|
||||
for (j = 0; j < term.t_ncol; ++j)
|
||||
unicode_t *txt = pscreen[ i]->v_text ;
|
||||
for( int j = 0 ; j < term.t_ncol ; ++j)
|
||||
txt[ j] = ' ' ;
|
||||
#endif
|
||||
}
|
||||
|
||||
movecursor( 0, 0) ; /* Erase the screen. */
|
||||
(*term.t_eeop) ();
|
||||
term.t_eeop() ;
|
||||
sgarbf = FALSE ; /* Erase-page clears */
|
||||
mpresf = FALSE ; /* the message area. */
|
||||
#if COLOR
|
||||
|
@ -618,32 +595,30 @@ void updgar(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* updupd:
|
||||
|
||||
/* updupd:
|
||||
* update the physical screen from the virtual screen
|
||||
*
|
||||
* int force; forced update flag
|
||||
*/
|
||||
int updupd(int force)
|
||||
{
|
||||
video_p vp1;
|
||||
int i;
|
||||
|
||||
static boolean updupd( boolean force_f) {
|
||||
#if SCROLLCODE
|
||||
if( scrflags & WFKILLS)
|
||||
scrolls( FALSE) ;
|
||||
|
||||
if( scrflags & WFINS)
|
||||
scrolls( TRUE) ;
|
||||
|
||||
scrflags = 0 ;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < term.t_nrow; ++i) {
|
||||
vp1 = vscreen[i];
|
||||
for( int i = 0 ; i < term.t_nrow ; ++i) {
|
||||
video_p vp1 = vscreen[ i] ;
|
||||
|
||||
/* for each line that needs to be updated */
|
||||
if( (vp1->v_flag & VFCHG) != 0) {
|
||||
#if TYPEAH && ! PKCODE
|
||||
if (force == FALSE && typahead())
|
||||
if( force_f == FALSE && typahead())
|
||||
return TRUE ;
|
||||
#endif
|
||||
#if MEMMAP && ! SCROLLCODE
|
||||
|
@ -653,44 +628,39 @@ int updupd(int force)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
#if SCROLLCODE
|
||||
|
||||
/*
|
||||
* optimize out scrolls (line breaks, and newlines)
|
||||
/* optimize out scrolls (line breaks, and newlines)
|
||||
* arg. chooses between looking for inserts or deletes
|
||||
|
||||
* returns true if it does something
|
||||
*/
|
||||
static int scrolls(int inserts)
|
||||
{ /* returns true if it does something */
|
||||
video_p vpv; /* virtual screen image */
|
||||
video_p vpp; /* physical screen image */
|
||||
static int scrolls( int inserts) {
|
||||
int i, j, k ;
|
||||
int rows, cols;
|
||||
int first, match, count, target, end;
|
||||
int longmatch, longcount;
|
||||
int from, to;
|
||||
int count, target, end ;
|
||||
int to ;
|
||||
|
||||
if( !term.t_scroll) /* no way to scroll */
|
||||
return FALSE ;
|
||||
|
||||
rows = term.t_nrow;
|
||||
cols = term.t_ncol;
|
||||
int rows = term.t_nrow ;
|
||||
int cols = term.t_ncol ;
|
||||
|
||||
first = -1;
|
||||
for (i = 0; i < rows; i++) { /* find first wrong line */
|
||||
if (!texttest(i, i)) {
|
||||
first = i;
|
||||
for( i = 0 ; i < rows ; i++) /* find first wrong line */
|
||||
if( !texttest( i, i))
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
if (first < 0)
|
||||
return FALSE; /* no text changes */
|
||||
if( i == rows) /* no text changes */
|
||||
return FALSE ;
|
||||
|
||||
vpv = vscreen[first];
|
||||
vpp = pscreen[first];
|
||||
int first = i ;
|
||||
|
||||
video_p vpv = vscreen[ first] ;
|
||||
video_p vpp = pscreen[ first] ;
|
||||
|
||||
if( inserts) {
|
||||
/* determine types of potential scrolls */
|
||||
|
@ -706,10 +676,10 @@ static int scrolls(int inserts)
|
|||
}
|
||||
|
||||
/* find the matching shifted area */
|
||||
match = -1;
|
||||
longmatch = -1;
|
||||
longcount = 0;
|
||||
from = target;
|
||||
int match = -1 ;
|
||||
int longmatch = -1 ;
|
||||
int longcount = 0 ;
|
||||
int from = target ;
|
||||
for( i = from + 1 ; i < rows - longcount /* P.K. */ ; i++) {
|
||||
if( inserts ? texttest( i, from) : texttest( from, i)) {
|
||||
match = i ;
|
||||
|
@ -728,6 +698,7 @@ static int scrolls(int inserts)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
match = longmatch ;
|
||||
count = longcount ;
|
||||
|
||||
|
@ -787,31 +758,28 @@ static int scrolls(int inserts)
|
|||
return FALSE ;
|
||||
}
|
||||
|
||||
|
||||
/* move the "count" lines starting at "from" to "to" */
|
||||
static void scrscroll(int from, int to, int count)
|
||||
{
|
||||
static void scrscroll( int from, int to, int count) {
|
||||
ttrow = ttcol = -1 ;
|
||||
(*term.t_scroll) (from, to, count);
|
||||
term.t_scroll( from, to, count) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* return TRUE on text match
|
||||
|
||||
/* return TRUE on text match
|
||||
*
|
||||
* int vrow, prow; virtual, physical rows
|
||||
*/
|
||||
static int texttest(int vrow, int prow)
|
||||
{
|
||||
static int texttest( int vrow, int prow) {
|
||||
video_p vpv = vscreen[ vrow] ; /* virtual screen image */
|
||||
video_p vpp = pscreen[ prow] ; /* physical screen image */
|
||||
|
||||
return !memcmp( vpv->v_text, vpp->v_text, 4*term.t_ncol) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* return the index of the first blank of trailing whitespace
|
||||
*/
|
||||
static int endofline(unicode_t *s, int n)
|
||||
{
|
||||
|
||||
/* return the index of the first blank of trailing whitespace */
|
||||
static int endofline( unicode_t *s, int n) {
|
||||
int i ;
|
||||
for( i = n - 1 ; i >= 0 ; i--)
|
||||
if( s[ i] != ' ')
|
||||
|
@ -821,15 +789,14 @@ static int endofline(unicode_t *s, int n)
|
|||
|
||||
#endif /* SCROLLCODE */
|
||||
|
||||
/*
|
||||
* updext:
|
||||
|
||||
/* updext:
|
||||
* update the extended line which the cursor is currently
|
||||
* on at a column greater than the terminal width. The line
|
||||
* will be scrolled right or left to let the user see where
|
||||
* the cursor is
|
||||
*/
|
||||
static void updext(void)
|
||||
{
|
||||
static void updext( void) {
|
||||
int rcursor ; /* real cursor location */
|
||||
line_p lp ; /* pointer to current line */
|
||||
|
||||
|
@ -851,16 +818,15 @@ static void updext(void)
|
|||
vscreen[ currow]->v_text[ 0] = '$' ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update a single line. This does not know how to use insert or delete
|
||||
|
||||
/* Update a single line. This does not know how to use insert or delete
|
||||
* character sequences; we are using VT52 functionality. Update the physical
|
||||
* row and column variables. It does try an exploit erase to end of line.
|
||||
*/
|
||||
#if MEMMAP
|
||||
/* UPDATELINE specific code for the IBM-PC and other compatables */
|
||||
|
||||
static int updateline(int row, video_p vp1, video_p vp2)
|
||||
{
|
||||
static int updateline( int row, video_p vp1, video_p vp2) {
|
||||
#if SCROLLCODE
|
||||
unicode_t *cp1 ;
|
||||
unicode_t *cp2 ;
|
||||
|
@ -887,7 +853,6 @@ static int updateline(int row, video_p vp1, video_p vp2)
|
|||
scwrite( row, vp1->v_text, 7, 0) ;
|
||||
#endif
|
||||
vp1->v_flag &= ~(VFCHG | VFCOL) ; /* flag this line as changed */
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -1028,8 +993,8 @@ static int updateline(int row, video_p vp1, video_p vp2) {
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Redisplay the mode line for the window pointed to by the "wp". This is the
|
||||
|
||||
/* Redisplay the mode line for the window pointed to by the "wp". This is the
|
||||
* only routine that has any idea of how the modeline is formatted. You can
|
||||
* change the modeline format by hacking at this routine. Called by "update"
|
||||
* any time there is a dirty window.
|
||||
|
@ -1155,8 +1120,7 @@ static void modeline( window_p wp) {
|
|||
int ratio = 0 ;
|
||||
|
||||
if( numlines != 0)
|
||||
ratio =
|
||||
(100L * predlines) / numlines;
|
||||
ratio = (100L * predlines) / numlines ;
|
||||
if( ratio > 99)
|
||||
ratio = 99 ;
|
||||
|
||||
|
@ -1177,8 +1141,7 @@ static void modeline( window_p wp) {
|
|||
}
|
||||
}
|
||||
|
||||
void upmode(void)
|
||||
{ /* update all the mode lines */
|
||||
void upmode( void) { /* update all the mode lines */
|
||||
window_p wp ;
|
||||
|
||||
wp = wheadp ;
|
||||
|
@ -1188,13 +1151,12 @@ void upmode(void)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a command to the terminal to move the hardware cursor to row "row"
|
||||
|
||||
/* Send a command to the terminal to move the hardware cursor to row "row"
|
||||
* and column "col". The row and column arguments are origin 0. Optimize out
|
||||
* random calls. Update "ttrow" and "ttcol".
|
||||
*/
|
||||
void movecursor(int row, int col)
|
||||
{
|
||||
void movecursor( int row, int col) {
|
||||
if( row != ttrow || col != ttcol) {
|
||||
ttrow = row ;
|
||||
ttcol = col ;
|
||||
|
@ -1202,8 +1164,8 @@ void movecursor(int row, int col)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase the message line. This is a special routine because the message line
|
||||
|
||||
/* Erase the message line. This is a special routine because the message line
|
||||
* is not considered to be part of the virtual screen. It always works
|
||||
* immediately; the terminal buffer is flushed via a call to the flusher.
|
||||
*/
|
||||
|
@ -1236,8 +1198,8 @@ static void mlputc( unicode_t c) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* output a string of output characters
|
||||
|
||||
/* output a string of output characters
|
||||
*
|
||||
* char *s; string to output
|
||||
*/
|
||||
|
@ -1247,8 +1209,8 @@ void ostring( const char *s) {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write a message into the message line. Keep track of the physical cursor
|
||||
|
||||
/* Write a message into the message line. Keep track of the physical cursor
|
||||
* position. A small class of printf like format items is handled. Assumes the
|
||||
* stack grows down; this assumption is made by the "++" in the argument scan
|
||||
* loop. Set the "message line" flag TRUE.
|
||||
|
@ -1339,8 +1301,8 @@ void mlwrite( const char *fmt, ...) {
|
|||
va_end( ap) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write out a string. Update the physical cursor position. This assumes that
|
||||
|
||||
/* Write out a string. Update the physical cursor position. This assumes that
|
||||
* the characters in the string all have width "1"; if this is not the case
|
||||
* things will get screwed up a little.
|
||||
*/
|
||||
|
@ -1357,8 +1319,8 @@ static void mlputs( const char *s) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write out an integer, in the specified radix. Update the physical cursor
|
||||
|
||||
/* Write out an integer, in the specified radix. Update the physical cursor
|
||||
* position.
|
||||
*/
|
||||
static void mlputi( int i, int r) {
|
||||
|
@ -1381,9 +1343,8 @@ static void mlputi( int i, int r) {
|
|||
mlputc( hexdigits[ u % r]) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* do the same except as a long integer.
|
||||
*/
|
||||
|
||||
/* do the same except as a long integer. */
|
||||
static void mlputli( long l, int r) {
|
||||
long q ;
|
||||
|
||||
|
@ -1400,8 +1361,8 @@ static void mlputli( long l, int r) {
|
|||
mlputc( (int) (l % r) + '0') ;
|
||||
}
|
||||
|
||||
/*
|
||||
* write out a scaled integer with two decimal places
|
||||
|
||||
/* write out a scaled integer with two decimal places
|
||||
*
|
||||
* int s; scaled integer to output
|
||||
*/
|
||||
|
@ -1425,8 +1386,7 @@ static void mlputf( int s) {
|
|||
Store number of lines into *heightp and width into *widthp.
|
||||
If zero or a negative number is stored, the value is not valid. */
|
||||
|
||||
void getscreensize(int *widthp, int *heightp)
|
||||
{
|
||||
void getscreensize( int *widthp, int *heightp) {
|
||||
#ifdef TIOCGWINSZ
|
||||
struct winsize size ;
|
||||
*widthp = 0 ;
|
||||
|
@ -1442,8 +1402,7 @@ void getscreensize(int *widthp, int *heightp)
|
|||
}
|
||||
|
||||
#ifdef SIGWINCH
|
||||
void sizesignal(int signr)
|
||||
{
|
||||
void sizesignal( int signr) {
|
||||
int w, h ;
|
||||
int old_errno = errno ;
|
||||
|
||||
|
@ -1460,17 +1419,18 @@ void sizesignal(int signr)
|
|||
errno = old_errno ;
|
||||
}
|
||||
|
||||
static int newscreensize(int h, int w)
|
||||
{
|
||||
static int newscreensize( int h, int w) {
|
||||
/* do the change later */
|
||||
if( displaying) {
|
||||
chg_width = w ;
|
||||
chg_height = h ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
chg_width = chg_height = 0 ;
|
||||
if( h <= term.t_mrow)
|
||||
newsize( TRUE, h) ;
|
||||
|
||||
if( w <= term.t_mcol)
|
||||
newwidth( TRUE, w) ;
|
||||
|
||||
|
@ -1480,8 +1440,8 @@ static int newscreensize(int h, int w)
|
|||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* output a character when echo is enabled
|
||||
|
||||
/* output a character when echo is enabled
|
||||
*
|
||||
* char c ; character to output
|
||||
*/
|
||||
|
@ -1492,8 +1452,8 @@ void echoc( unicode_t c) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* output a string of characters when display input is enabled
|
||||
|
||||
/* output a string of characters when display input is enabled
|
||||
*
|
||||
* char *s; string to output
|
||||
*/
|
||||
|
@ -1507,6 +1467,7 @@ void echos( const char *s) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void rubout( void) {
|
||||
if( disinp) {
|
||||
TTputc( '\b') ;
|
||||
|
|
|
@ -21,11 +21,7 @@ BINDABLE( upscreen) ;
|
|||
void vtinit( void) ;
|
||||
void vtfree( void) ;
|
||||
void vttidy( void) ;
|
||||
int update( boolean force_f) ;
|
||||
void updpos( void) ;
|
||||
void upddex( void) ;
|
||||
void updgar( void) ;
|
||||
int updupd( int force) ;
|
||||
boolean update( boolean force_f) ;
|
||||
void upmode( void) ;
|
||||
void movecursor( int row, int col) ;
|
||||
void mlerase( void) ;
|
||||
|
|
Loading…
Reference in New Issue