Recognise CR after wrap; update ANSICON_API docs

CR will match BS/CUB/HPB, moving back to previous line(s) after a wrap.

I hadn't updated the comment when I switched ANSICON_API from WriteFile
to WriteConsoleA.  Mention that is should be deleted when upgrading.
This commit is contained in:
Jason Hood 2017-12-24 10:11:57 +10:00
parent 9140e3bd56
commit 10575a0647
3 changed files with 29 additions and 11 deletions

27
ANSI.c
View File

@ -152,7 +152,7 @@
remove wcstok, avoiding potential interference with the host; remove wcstok, avoiding potential interference with the host;
similarly, use a private heap instead of malloc. similarly, use a private heap instead of malloc.
v1.80, 26 October to 22 December, 2017: v1.80, 26 October to 24 December, 2017:
fix unloading; fix unloading;
revert back to (re)storing buffer cursor position; revert back to (re)storing buffer cursor position;
increase cache to five handles; increase cache to five handles;
@ -174,7 +174,7 @@
added tab handling; added tab handling;
added the bright SGR colors, recognised the system indices; added the bright SGR colors, recognised the system indices;
added insert mode; added insert mode;
BS/CUB/HPB after wrap will move back to the previous line(s); BS/CR/CUB/HPB after wrap will move back to the previous line(s);
added DECOM, DECSTBM, SD & SU; added DECOM, DECSTBM, SD & SU;
only flush before accessing the console, adding a mode to flush immediately; only flush before accessing the console, adding a mode to flush immediately;
added DECSTR & RIS; added DECSTR & RIS;
@ -861,6 +861,20 @@ void PushBuffer( WCHAR c )
MoveDown( TRUE ); MoveDown( TRUE );
} }
} }
else if (c == '\r')
{
FlushBuffer();
if (nWrapped)
{
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 );
}
else
ChBuffer[nCharInBuffer++] = c;
}
else if (c == '\b') else if (c == '\b')
{ {
BOOL bs = FALSE; BOOL bs = FALSE;
@ -868,7 +882,7 @@ void PushBuffer( WCHAR c )
if (nWrapped) if (nWrapped)
{ {
GetConsoleScreenBufferInfo( hConOut, &Info ); GetConsoleScreenBufferInfo( hConOut, &Info );
if (CUR.X == 0) if (CUR.X == LEFT)
{ {
CUR.X = RIGHT; CUR.X = RIGHT;
CUR.Y--; CUR.Y--;
@ -3210,10 +3224,9 @@ WINAPI MyWriteConsoleA( HANDLE hCon, LPCVOID lpBuffer,
if (rc && lpNumberOfCharsWritten != NULL && if (rc && lpNumberOfCharsWritten != NULL &&
*lpNumberOfCharsWritten != nNumberOfCharsToWrite) *lpNumberOfCharsWritten != nNumberOfCharsToWrite)
{ {
// Converting a multibyte character to Unicode results in a different // I set the number of characters actually written, which may be 0 when
// "character" count. This causes some programs to think not everything // multibyte characters are split across calls. If that causes problems,
// was written, so the difference is sent again. Fudge the (presumably) // restore original behaviour.
// correct count.
if (search_env( L"ANSICON_API", prog )) if (search_env( L"ANSICON_API", prog ))
*lpNumberOfCharsWritten = nNumberOfCharsToWrite; *lpNumberOfCharsWritten = nNumberOfCharsToWrite;
} }

View File

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

View File

@ -45,6 +45,11 @@ Installation
ing the directory from PATH; and deleting the files. No other changes are ing the directory from PATH; and deleting the files. No other changes are
made (unless you created environment variables). made (unless you created environment variables).
Upgrading
---------
Delete ANSICON_API - it has switched from WriteFile to WriteConsoleA.
Usage Usage
===== =====
@ -329,7 +334,7 @@ Version History
Legend: + added, - bug-fixed, * changed. Legend: + added, - bug-fixed, * changed.
1.80 - 23 December, 2017: 1.80 - 24 December, 2017:
- fix unloading; - fix unloading;
- fix -e et al when redirecting to CON; - fix -e et al when redirecting to CON;
- hook CreateFile and CreateConsoleScreenBuffer to force read/write access - hook CreateFile and CreateConsoleScreenBuffer to force read/write access
@ -345,7 +350,7 @@ Version History
* preserve escape that isn't part of a sequence; * preserve escape that isn't part of a sequence;
* escaped control characters will display the control; * escaped control characters will display the control;
* change the graphics SCAN characters to their Unicode equivalents; * change the graphics SCAN characters to their Unicode equivalents;
* BS/CUB/HVP after wrap will move back to the previous line(s); * BS/CR/CUB/HVP after wrap will move back to the previous line(s);
* improve speed by only flushing when necessary, adding a mode to restore * improve speed by only flushing when necessary, adding a mode to restore
flushing immediately; flushing immediately;
+ added DA, DECCOLM, DECNCSM, DECOM, DECPS, DECRC, DECSC, DECST8C, DECSTBM, + added DA, DECCOLM, DECNCSM, DECOM, DECPS, DECRC, DECSC, DECST8C, DECSTBM,
@ -583,4 +588,4 @@ Distribution
============================== ==============================
Jason Hood, 23 December, 2017. Jason Hood, 24 December, 2017.