Skip to content

Commit

Permalink
Fix Win32 display problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Jan 18, 2001
1 parent e145a2e commit 97b35c2
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 78 deletions.
2 changes: 0 additions & 2 deletions linenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ find_linenum(pos)
* The decision is based on which way involves
* traversing fewer bytes in the file.
*/
flush();
#if HAVE_TIME
startime = get_time();
#endif
Expand Down Expand Up @@ -386,7 +385,6 @@ find_pos(lno)
/* Found it exactly. */
return (p->pos);

flush();
if (p == &anchor || lno - p->prev->line < p->line - lno)
{
/*
Expand Down
61 changes: 21 additions & 40 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,59 +129,40 @@ flush()
char *op;
DWORD nwritten = 0;
CONSOLE_SCREEN_BUFFER_INFO scr;
DWORD nchars;
COORD cpos;
int row;
int col;
int olen;
int len;
extern HANDLE con_out;
extern int nm_fg_color;
extern int nm_bg_color;
#define MAKEATTR(fg,bg) ((WORD)((fg)|((bg)<<4)))

olen = ob - obuf;
/*
* There is a bug in Win32 WriteConsole() if we're
* writing in the last cell whith a different color.
* To avoid color problems, in the bottom line,
* we scroll the screen, with scroll_up(), and then
* we write only up to the char that causes the scroll,
* (a newline or a char in the last column). Then we write
* the rest using the same algorithm.
* writing in the last cell with a different color.
* To avoid color problems in the bottom line,
* we scroll the screen manually, before writing.
*/
for (op = obuf; olen > 0; )
GetConsoleScreenBufferInfo(con_out, &scr);
col = scr.dwCursorPosition.X;
row = scr.dwCursorPosition.Y;
for (op = obuf; op < obuf + olen; op++)
{
GetConsoleScreenBufferInfo(con_out, &scr);
/* Find the next newline. */
p = strchr(op, '\n');
if (p == NULL &&
scr.dwCursorPosition.X + olen >= sc_width)
if (*op == '\n')
{
/*
* No newline, but writing in the
* last column causes scrolling.
*/
p = op + sc_width - scr.dwCursorPosition.X - 1;
}
if (scr.dwCursorPosition.Y != scr.srWindow.Bottom ||
p == NULL)
{
/*
* Write the entire buffer.
*/
len = olen;
col = 0;
row++;
} else
{
/*
* Manually scroll up one line first, then
* write only up to the scrolling char.
*/
len = p - op + 1;
win32_scroll_up(1);
col++;
if (col >= sc_width)
{
col = 0;
row++;
}
}
WriteConsole(con_out, op, len, &nwritten, NULL);
op += len;
olen -= len;
}
if (row > scr.srWindow.Bottom)
win32_scroll_up(row - scr.srWindow.Bottom);
WriteConsole(con_out, obuf, olen, &nwritten, NULL);
ob = obuf;
return;
}
Expand Down
102 changes: 67 additions & 35 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,9 +1469,13 @@ deinit()
tputs(sc_e_keypad, sc_height, putchr);
tputs(sc_deinit, sc_height, putchr);
#else
/* Restore system colors. */
SETCOLORS(sy_fg_color, sy_bg_color);
#if MSDOS_COMPILER==WIN32C
win32_deinit_term();
#else
/* Need clreol to make SETCOLORS take effect. */
clreol();
#endif
#endif
init_done = 0;
Expand Down Expand Up @@ -1547,6 +1551,7 @@ add_line()
#endif
}

#if 0
/*
* Remove the n topmost lines and scroll everything below it in the
* window upward. This is needed to stop leaking the topmost line
Expand Down Expand Up @@ -1600,8 +1605,39 @@ remove_top(n)
goto_line(sc_height - n - 1);
#endif
}
#endif

#if MSDOS_COMPILER==WIN32C
/*
* Clear the screen.
*/
static void
win32_clear()
{
/*
* This will clear only the currently visible rows of the NT
* console buffer, which means none of the precious scrollback
* rows are touched making for faster scrolling. Note that, if
* the window has fewer columns than the console buffer (i.e.
* there is a horizontal scrollbar as well), the entire width
* of the visible rows will be cleared.
*/
COORD topleft;
DWORD nchars;
DWORD winsz;
CONSOLE_SCREEN_BUFFER_INFO csbi;

/* get the number of cells in the current buffer */
GetConsoleScreenBufferInfo(con_out, &csbi);
winsz = csbi.dwSize.X * (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
topleft.X = 0;
topleft.Y = csbi.srWindow.Top;

curr_attr = MAKEATTR(nm_fg_color, nm_bg_color);
FillConsoleOutputCharacter(con_out, ' ', winsz, topleft, &nchars);
FillConsoleOutputAttribute(con_out, curr_attr, winsz, topleft, &nchars);
}

/*
* Remove the n topmost lines and scroll everything below it in the
* window upward.
Expand All @@ -1610,19 +1646,26 @@ remove_top(n)
win32_scroll_up(n)
int n;
{
extern int sc_height;
extern HANDLE con_out;
extern int nm_fg_color;
extern int nm_bg_color;
SMALL_RECT rcSrc, rcClip;
CHAR_INFO fillchar;
COORD topleft;
COORD new_org;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
#define MAKEATTR(fg,bg) ((WORD)((fg)|((bg)<<4)))
DWORD nchars;
DWORD size;
CONSOLE_SCREEN_BUFFER_INFO csbi;

GetConsoleScreenBufferInfo(con_out, &csbi);
if (n <= 0)
return;

/* Get the extent of all-visible-rows-but-the-last. */
if (n >= sc_height - 1)
{
win32_clear();
_settextposition(1,1);
return;
}

/* Get the extent of what will remain visible after scrolling. */
GetConsoleScreenBufferInfo(con_out, &csbi);
rcSrc.Left = csbi.srWindow.Left;
rcSrc.Top = csbi.srWindow.Top + n;
rcSrc.Right = csbi.srWindow.Right;
Expand All @@ -1634,17 +1677,29 @@ win32_scroll_up(n)
rcClip.Right = rcSrc.Right;
rcClip.Bottom = rcSrc.Bottom ;

/* Move the source window up n rows. */
/* Move the source text to the top of the screen. */
new_org.X = rcSrc.Left;
new_org.Y = rcSrc.Top - n;
new_org.Y = 0;

/* Fill the right character and attributes. */
fillchar.Char.AsciiChar = ' ';
fillchar.Attributes = MAKEATTR(nm_fg_color, nm_bg_color);

/* Scroll the window. */
SetConsoleTextAttribute(con_out, fillchar.Attributes);
ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar);

/* Position cursor n lines up. */
/* Clear remaining lines at bottom. */
topleft.X = csbi.dwCursorPosition.X;
topleft.Y = rcSrc.Bottom - n;
size = (n * csbi.dwSize.X) + (rcSrc.Right - topleft.X);
FillConsoleOutputCharacter(con_out, ' ', size, topleft,
&nchars);
FillConsoleOutputAttribute(con_out, fillchar.Attributes, size, topleft,
&nchars);
SetConsoleTextAttribute(con_out, curr_attr);

/* Move cursor n lines up from where it was. */
csbi.dwCursorPosition.Y -= n;
SetConsoleCursorPosition(con_out, csbi.dwCursorPosition);
}
Expand Down Expand Up @@ -1877,30 +1932,7 @@ clear()
#else
flush();
#if MSDOS_COMPILER==WIN32C
/*
* This will clear only the currently visible rows of the NT
* console buffer, which means none of the precious scrollback
* rows are touched making for faster scrolling. Note that, if
* the window has fewer columns than the console buffer (i.e.
* there is a horizontal scrollbar as well), the entire width
* of the visible rows will be cleared.
*/
{
COORD topleft;
DWORD nchars;
DWORD winsz;
CONSOLE_SCREEN_BUFFER_INFO csbi;

/* get the number of cells in the current buffer */
GetConsoleScreenBufferInfo(con_out, &csbi);
winsz = csbi.dwSize.X * (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
topleft.X = 0;
topleft.Y = csbi.srWindow.Top;

curr_attr = MAKEATTR(nm_fg_color, nm_bg_color);
FillConsoleOutputCharacter(con_out, ' ', winsz, topleft, &nchars);
FillConsoleOutputAttribute(con_out, curr_attr, winsz, topleft, &nchars);
}
win32_clear();
#else
_clearscreen(_GCLEARSCREEN);
#endif
Expand Down
2 changes: 1 addition & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ v357 7/6/00 Support sigprocmask.
v358 7/8/00 Fix problems with #stop in lesskey file.
Posted to Web page.
-----------------------------------------------------------------
v359 9/10/00
v359 9/10/00 Fixes for Win32 display problems (thanks to Maurizio Vairani).
*/

Expand Down

0 comments on commit 97b35c2

Please sign in to comment.