From 10575a064720f80b884cb8e68b9e87e753a4aefd Mon Sep 17 00:00:00 2001 From: Jason Hood Date: Sun, 24 Dec 2017 10:11:57 +1000 Subject: [PATCH] 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. --- ANSI.c | 27 ++++++++++++++++++++------- ansicon.c | 2 +- readme.txt | 11 ++++++++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ANSI.c b/ANSI.c index 75a6483..d71c4c6 100644 --- a/ANSI.c +++ b/ANSI.c @@ -152,7 +152,7 @@ remove wcstok, avoiding potential interference with the host; 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; revert back to (re)storing buffer cursor position; increase cache to five handles; @@ -174,7 +174,7 @@ added tab handling; added the bright SGR colors, recognised the system indices; 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; only flush before accessing the console, adding a mode to flush immediately; added DECSTR & RIS; @@ -861,6 +861,20 @@ void PushBuffer( WCHAR c ) 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') { BOOL bs = FALSE; @@ -868,7 +882,7 @@ void PushBuffer( WCHAR c ) if (nWrapped) { GetConsoleScreenBufferInfo( hConOut, &Info ); - if (CUR.X == 0) + if (CUR.X == LEFT) { CUR.X = RIGHT; CUR.Y--; @@ -3210,10 +3224,9 @@ WINAPI MyWriteConsoleA( HANDLE hCon, LPCVOID lpBuffer, if (rc && lpNumberOfCharsWritten != NULL && *lpNumberOfCharsWritten != nNumberOfCharsToWrite) { - // Converting a multibyte character to Unicode results in a different - // "character" count. This causes some programs to think not everything - // was written, so the difference is sent again. Fudge the (presumably) - // correct count. + // I set the number of characters actually written, which may be 0 when + // multibyte characters are split across calls. If that causes problems, + // restore original behaviour. if (search_env( L"ANSICON_API", prog )) *lpNumberOfCharsWritten = nNumberOfCharsToWrite; } diff --git a/ansicon.c b/ansicon.c index 40f7a6b..233bf2e 100644 --- a/ansicon.c +++ b/ansicon.c @@ -91,7 +91,7 @@ use -pu to unload from the parent. */ -#define PDATE L"23 December, 2017" +#define PDATE L"24 December, 2017" #include "ansicon.h" #include "version.h" diff --git a/readme.txt b/readme.txt index 9a35199..188227d 100644 --- a/readme.txt +++ b/readme.txt @@ -45,6 +45,11 @@ Installation ing the directory from PATH; and deleting the files. No other changes are made (unless you created environment variables). +Upgrading +--------- + + Delete ANSICON_API - it has switched from WriteFile to WriteConsoleA. + Usage ===== @@ -329,7 +334,7 @@ Version History Legend: + added, - bug-fixed, * changed. - 1.80 - 23 December, 2017: + 1.80 - 24 December, 2017: - fix unloading; - fix -e et al when redirecting to CON; - hook CreateFile and CreateConsoleScreenBuffer to force read/write access @@ -345,7 +350,7 @@ Version History * preserve escape that isn't part of a sequence; * escaped control characters will display the control; * 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 flushing immediately; + 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.