Scroll in new lines using the default attribute
When the window or buffer scrolls use the default attribute for the resulting new lines, not the current. Fixes #64.
This commit is contained in:
parent
33ba31ad3c
commit
9260451684
64
ANSI.c
64
ANSI.c
@ -197,7 +197,7 @@
|
|||||||
v1.83, 16 February, 2018:
|
v1.83, 16 February, 2018:
|
||||||
create the flush thread on first use.
|
create the flush thread on first use.
|
||||||
|
|
||||||
v1.84-wip, 17 February, 26 April to 7 May, 2018:
|
v1.84-wip, 17 February, 26 April to 8 May, 2018:
|
||||||
close the flush handles on detach;
|
close the flush handles on detach;
|
||||||
dynamically load WINMM.DLL;
|
dynamically load WINMM.DLL;
|
||||||
use sprintf/_snprintf/_snwprintf instead of wsprintf, avoiding USER32.DLL;
|
use sprintf/_snprintf/_snwprintf instead of wsprintf, avoiding USER32.DLL;
|
||||||
@ -207,7 +207,8 @@
|
|||||||
use remote load on Win8+ when the process has no IAT;
|
use remote load on Win8+ when the process has no IAT;
|
||||||
remove dependency on the CRT;
|
remove dependency on the CRT;
|
||||||
increase heap to 256KiB to fix logging of really long command lines;
|
increase heap to 256KiB to fix logging of really long command lines;
|
||||||
default to 7 or -7 if ANSICON_DEF could not be parsed.
|
default to 7 or -7 if ANSICON_DEF could not be parsed;
|
||||||
|
scrolling will use the default attribute for new lines.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ansicon.h"
|
#include "ansicon.h"
|
||||||
@ -670,6 +671,25 @@ void set_pos( int x, int y )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get the default attribute, as-is if !ATTR (i.e. preserve negative), else for
|
||||||
|
// the console (swap foreground/background if negative).
|
||||||
|
int get_default_attr( BOOL attr )
|
||||||
|
{
|
||||||
|
TCHAR def[4];
|
||||||
|
int a;
|
||||||
|
|
||||||
|
*def = '7'; def[1] = '\0';
|
||||||
|
GetEnvironmentVariable( L"ANSICON_DEF", def, lenof(def) );
|
||||||
|
a = ac_wcstol( def, NULL, 16 );
|
||||||
|
if (a == 0)
|
||||||
|
a = (*def == '-') ? -7 : 7;
|
||||||
|
if (a > 0 || !attr)
|
||||||
|
return a;
|
||||||
|
a = -a;
|
||||||
|
return ((a >> 4) & 15) | ((a & 15) << 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlushBuffer()
|
// FlushBuffer()
|
||||||
// Writes the buffer to the console and empties it.
|
// Writes the buffer to the console and empties it.
|
||||||
@ -835,7 +855,7 @@ void FlushBuffer( void )
|
|||||||
CHAR_INFO ci;
|
CHAR_INFO ci;
|
||||||
|
|
||||||
ci.Char.UnicodeChar = ' ';
|
ci.Char.UnicodeChar = ' ';
|
||||||
ci.Attributes = ATTR;
|
ci.Attributes = get_default_attr( TRUE );
|
||||||
c.X =
|
c.X =
|
||||||
sr.Left = LEFT;
|
sr.Left = LEFT;
|
||||||
sr.Right = RIGHT;
|
sr.Right = RIGHT;
|
||||||
@ -860,6 +880,26 @@ void FlushBuffer( void )
|
|||||||
cr.Left = CUR.X = wi.CURPOS.X;
|
cr.Left = CUR.X = wi.CURPOS.X;
|
||||||
ScrollConsoleScreenBuffer( hConOut, &sr, &cr, CUR, &ci );
|
ScrollConsoleScreenBuffer( hConOut, &sr, &cr, CUR, &ci );
|
||||||
}
|
}
|
||||||
|
else if (nWrapped && CUR.Y + nWrapped > LAST)
|
||||||
|
{
|
||||||
|
// The buffer is going to scroll; do it manually in order to use the
|
||||||
|
// default attribute, not current.
|
||||||
|
SMALL_RECT sr;
|
||||||
|
COORD c;
|
||||||
|
CHAR_INFO ci;
|
||||||
|
|
||||||
|
ci.Char.UnicodeChar = ' ';
|
||||||
|
ci.Attributes = get_default_attr( TRUE );
|
||||||
|
c.X =
|
||||||
|
sr.Left = LEFT;
|
||||||
|
sr.Right = RIGHT;
|
||||||
|
sr.Top = 0;
|
||||||
|
sr.Bottom = LAST;
|
||||||
|
c.Y = -wi.CURPOS.Y;
|
||||||
|
ScrollConsoleScreenBuffer( hConOut, &sr, &sr, c, &ci );
|
||||||
|
CUR.Y -= wi.CURPOS.Y;
|
||||||
|
SetConsoleCursorPos( hConOut, CUR );
|
||||||
|
}
|
||||||
if (pState->crm)
|
if (pState->crm)
|
||||||
{
|
{
|
||||||
SetConsoleMode( hConOut, cache[0].mode & ~ENABLE_PROCESSED_OUTPUT );
|
SetConsoleMode( hConOut, cache[0].mode & ~ENABLE_PROCESSED_OUTPUT );
|
||||||
@ -1368,13 +1408,7 @@ void InterpretEscSeq( void )
|
|||||||
case 39:
|
case 39:
|
||||||
case 49:
|
case 49:
|
||||||
{
|
{
|
||||||
TCHAR def[4];
|
int a = get_default_attr( FALSE );
|
||||||
int a;
|
|
||||||
*def = '7'; def[1] = '\0';
|
|
||||||
GetEnvironmentVariable( L"ANSICON_DEF", def, lenof(def) );
|
|
||||||
a = ac_wcstol( def, NULL, 16 );
|
|
||||||
if (a == 0)
|
|
||||||
a = (*def == '-') ? -7 : 7;
|
|
||||||
pState->sgr.reverse = FALSE;
|
pState->sgr.reverse = FALSE;
|
||||||
if (a < 0)
|
if (a < 0)
|
||||||
{
|
{
|
||||||
@ -1572,7 +1606,7 @@ void InterpretEscSeq( void )
|
|||||||
}
|
}
|
||||||
Pos.Y = Rect.Top + (suffix == 'T' ? p1 : -p1);
|
Pos.Y = Rect.Top + (suffix == 'T' ? p1 : -p1);
|
||||||
CharInfo.Char.UnicodeChar = ' ';
|
CharInfo.Char.UnicodeChar = ' ';
|
||||||
CharInfo.Attributes = ATTR;
|
CharInfo.Attributes = get_default_attr( TRUE );
|
||||||
ScrollConsoleScreenBuffer( hConOut, &Rect, &Rect, Pos, &CharInfo );
|
ScrollConsoleScreenBuffer( hConOut, &Rect, &Rect, Pos, &CharInfo );
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2098,7 +2132,7 @@ void MoveDown( BOOL home )
|
|||||||
Pos.X = LEFT;
|
Pos.X = LEFT;
|
||||||
Pos.Y = TOP + pState->top_margin;
|
Pos.Y = TOP + pState->top_margin;
|
||||||
CharInfo.Char.UnicodeChar = ' ';
|
CharInfo.Char.UnicodeChar = ' ';
|
||||||
CharInfo.Attributes = ATTR;
|
CharInfo.Attributes = get_default_attr( TRUE );
|
||||||
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
||||||
if (home)
|
if (home)
|
||||||
{
|
{
|
||||||
@ -2122,7 +2156,7 @@ void MoveDown( BOOL home )
|
|||||||
Rect.Bottom = LAST;
|
Rect.Bottom = LAST;
|
||||||
Pos.X = Pos.Y = 0;
|
Pos.X = Pos.Y = 0;
|
||||||
CharInfo.Char.UnicodeChar = ' ';
|
CharInfo.Char.UnicodeChar = ' ';
|
||||||
CharInfo.Attributes = ATTR;
|
CharInfo.Attributes = get_default_attr( TRUE );
|
||||||
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
||||||
if (home)
|
if (home)
|
||||||
{
|
{
|
||||||
@ -2155,7 +2189,7 @@ void MoveUp( void )
|
|||||||
Pos.X = LEFT;
|
Pos.X = LEFT;
|
||||||
Pos.Y = TOP + pState->top_margin + 1;
|
Pos.Y = TOP + pState->top_margin + 1;
|
||||||
CharInfo.Char.UnicodeChar = ' ';
|
CharInfo.Char.UnicodeChar = ' ';
|
||||||
CharInfo.Attributes = ATTR;
|
CharInfo.Attributes = get_default_attr( TRUE );
|
||||||
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
||||||
}
|
}
|
||||||
else if (pState->tb_margins && CUR.Y == TOP)
|
else if (pState->tb_margins && CUR.Y == TOP)
|
||||||
@ -2171,7 +2205,7 @@ void MoveUp( void )
|
|||||||
Pos.X = LEFT;
|
Pos.X = LEFT;
|
||||||
Pos.Y = 1;
|
Pos.Y = 1;
|
||||||
CharInfo.Char.UnicodeChar = ' ';
|
CharInfo.Char.UnicodeChar = ' ';
|
||||||
CharInfo.Attributes = ATTR;
|
CharInfo.Attributes = get_default_attr( TRUE );
|
||||||
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
ScrollConsoleScreenBuffer( hConOut, &Rect, NULL, Pos, &CharInfo );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
import the DLL.
|
import the DLL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PDATE L"7 May, 2018"
|
#define PDATE L"8 May, 2018"
|
||||||
|
|
||||||
#include "ansicon.h"
|
#include "ansicon.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
@ -339,7 +339,7 @@ Version History
|
|||||||
|
|
||||||
Legend: + added, - bug-fixed, * changed.
|
Legend: + added, - bug-fixed, * changed.
|
||||||
|
|
||||||
1.84-wip - 7 May, 2018:
|
1.84-wip - 8 May, 2018:
|
||||||
- close the flush handles on detach;
|
- close the flush handles on detach;
|
||||||
- WriteFile wasn't properly testing if its handle was for a console;
|
- WriteFile wasn't properly testing if its handle was for a console;
|
||||||
- use remote load on Win8+ if the process has no IAT;
|
- use remote load on Win8+ if the process has no IAT;
|
||||||
@ -348,7 +348,8 @@ Version History
|
|||||||
* remove dependency on CRT & USER32, dynamically load WINMM;
|
* remove dependency on CRT & USER32, dynamically load WINMM;
|
||||||
* exit process if the primary thread is detached (for processes on Win10
|
* exit process if the primary thread is detached (for processes on Win10
|
||||||
that return, rather than call ExitProcess);
|
that return, rather than call ExitProcess);
|
||||||
* ansicon.exe statically loads the DLL.
|
* ansicon.exe statically loads the DLL;
|
||||||
|
* scrolling will use the default attribute for new lines.
|
||||||
|
|
||||||
1.83 - 16 February, 2018:
|
1.83 - 16 February, 2018:
|
||||||
- create the flush thread on first use.
|
- create the flush thread on first use.
|
||||||
@ -624,4 +625,4 @@ Distribution
|
|||||||
|
|
||||||
|
|
||||||
========================
|
========================
|
||||||
Jason Hood, 7 May, 2018.
|
Jason Hood, 8 May, 2018.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user