Fix CR and CRM issues

CR and BS would still be processed during CRM.	Fix all the partial CRM
sequences followed by a complete CRM sequence.

It's possible for some text files to have `\r\r\n` endings (Microsoft
converts LF to CRLF even when the CR is already there).  Collapse
multiple CRs to a single CR to catch this.  It is also necessary to
always delay flushing if the last character is CR, to see if the next
character is CR or LF.
This commit is contained in:
Jason Hood 2017-12-26 16:47:08 +10:00
parent 2120ff3efa
commit 44e5941a08
4 changed files with 57 additions and 34 deletions

73
ANSI.c
View File

@ -179,6 +179,12 @@
only flush before accessing the console, adding a mode to flush immediately;
added DECSTR & RIS;
fix state problems with windowless processes.
v1.81-wip, 26 December, 2017:
combine multiple CRs as one (to ignore all CRs before LF);
don't process CR or BS during CRM;
don't flush CR immediately (to catch following LF);
fix CRM with all partial RM sequences.
*/
#include "ansicon.h"
@ -898,31 +904,35 @@ void PushBuffer( WCHAR c )
}
return;
}
if (nCharInBuffer > 0 && ChBuffer[nCharInBuffer-1] == '\r')
if (!pState->crm)
{
FlushBuffer();
if (nWrapped)
if (nCharInBuffer > 0 && ChBuffer[nCharInBuffer-1] == '\r')
{
GetConsoleScreenBufferInfo( hConOut, &Info );
CUR.Y -= nWrapped;
if (CUR.Y < 0) CUR.Y = 0;
if (pState->tb_margins && CUR.Y < TOP) CUR.Y = TOP;
set_pos( LEFT, CUR.Y );
}
}
if (c == '\b')
{
FlushBuffer();
if (nWrapped)
{
GetConsoleScreenBufferInfo( hConOut, &Info );
if (CUR.X == LEFT)
if (c == '\r') return; // \r\r\r... == \r, thus \r\r\n == \r\n
FlushBuffer();
if (nWrapped)
{
CUR.X = RIGHT;
CUR.Y--;
SetConsoleCursorPos( hConOut, CUR );
--nWrapped;
return;
GetConsoleScreenBufferInfo( hConOut, &Info );
CUR.Y -= nWrapped;
if (CUR.Y < 0) CUR.Y = 0;
if (pState->tb_margins && CUR.Y < TOP) CUR.Y = TOP;
set_pos( LEFT, CUR.Y );
}
}
if (c == '\b')
{
FlushBuffer();
if (nWrapped)
{
GetConsoleScreenBufferInfo( hConOut, &Info );
if (CUR.X == LEFT)
{
CUR.X = RIGHT;
CUR.Y--;
SetConsoleCursorPos( hConOut, CUR );
--nWrapped;
return;
}
}
}
}
@ -2363,8 +2373,12 @@ ParseAndPrintString( HANDLE hDev,
{
PushBuffer( ESC );
PushBuffer( '[' );
PushBuffer( (WCHAR)c );
state = 1;
if (c == ESC) state = 7;
else
{
PushBuffer( (WCHAR)c );
state = 1;
}
}
}
else if (state == 9)
@ -2373,20 +2387,25 @@ ParseAndPrintString( HANDLE hDev,
{
FlushBuffer();
pState->crm = FALSE;
state = 1;
}
else
{
PushBuffer( ESC );
PushBuffer( '[' );
PushBuffer( '3' );
PushBuffer( (WCHAR)c );
if (c == ESC) state = 7;
else
{
PushBuffer( (WCHAR)c );
state = 1;
}
}
state = 1;
}
}
if (nCharInBuffer > 0)
{
if (pState->fm) FlushBuffer();
if (pState->fm && ChBuffer[nCharInBuffer-1] != '\r') FlushBuffer();
else
{
LARGE_INTEGER due;

View File

@ -91,7 +91,7 @@
use -pu to unload from the parent.
*/
#define PDATE L"24 December, 2017"
#define PDATE L"26 December, 2017"
#include "ansicon.h"
#include "version.h"

View File

@ -334,6 +334,10 @@ Version History
Legend: + added, - bug-fixed, * changed.
1.81-wip - 26 December, 2017:
- fix multiple CRs before LF (including preventing an immediate flush);
- fix CR, BS and partial RM during CRM.
1.80 - 24 December, 2017:
- fix unloading;
- fix -e et al when redirecting to CON;
@ -590,4 +594,4 @@ Distribution
==============================
Jason Hood, 24 December, 2017.
Jason Hood, 26 December, 2017.

View File

@ -2,11 +2,11 @@
version.h - Version defines.
*/
#define PVERS L"1.80" // wide string
#define PVERSA "1.80" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"180" // wide environment string
#define PVEREA "180" // ANSI environment string
#define PVERB 1,8,0,0 // binary (resource)
#define PVERS L"1.81-wip" // wide string
#define PVERSA "1.81-wip" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"181" // wide environment string
#define PVEREA "181" // ANSI environment string
#define PVERB 1,8,1,0 // binary (resource)
#ifdef _WIN64
# define BITS L"64"