Add ANSICON_WRAP for programs that expect wrap

Some programs (notably less) rely on the right margin performing the
wrap.  Add such programs to the ANSICON_WRAP environment variable to
stop ANSICON suppressing the newline.
This commit is contained in:
Jason Hood 2018-02-12 16:44:55 +10:00
parent a2c3595477
commit af2c31c466
4 changed files with 29 additions and 9 deletions

14
ANSI.c
View File

@ -187,6 +187,9 @@
fix CRM with all partial RM sequences; fix CRM with all partial RM sequences;
check for the empty buffer within the critical section; check for the empty buffer within the critical section;
palette improvements. palette improvements.
v1.82-wip, 12 February, 2018:
add ANSICON_WRAP environment variable for programs that expect the wrap.
*/ */
#include "ansicon.h" #include "ansicon.h"
@ -233,6 +236,7 @@ int es_argv[MAX_ARG]; // escape sequence args
TCHAR Pt_arg[4096]; // text parameter for Operating System Command TCHAR Pt_arg[4096]; // text parameter for Operating System Command
int Pt_len; int Pt_len;
BOOL shifted, G0_special, SaveG0; BOOL shifted, G0_special, SaveG0;
BOOL wm = FALSE; // does program detect wrap itself?
BOOL awm = TRUE; // autowrap mode BOOL awm = TRUE; // autowrap mode
BOOL im; // insert mode BOOL im; // insert mode
int screen_top = -1; // initial window top when cleared int screen_top = -1; // initial window top when cleared
@ -662,7 +666,7 @@ void FlushBuffer( void )
return; return;
} }
if (!awm && !im) if ((wm || !awm) && !im && !pState->tb_margins)
{ {
if (pState->crm) if (pState->crm)
{ {
@ -867,6 +871,11 @@ void PushBuffer( WCHAR c )
if (pState->crm) if (pState->crm)
ChBuffer[nCharInBuffer++] = c; ChBuffer[nCharInBuffer++] = c;
FlushBuffer(); FlushBuffer();
if (wm)
{
MoveDown( TRUE );
return;
}
// Avoid writing the newline if wrap has already occurred. // Avoid writing the newline if wrap has already occurred.
GetConsoleScreenBufferInfo( hConOut, &Info ); GetConsoleScreenBufferInfo( hConOut, &Info );
if (pState->crm) if (pState->crm)
@ -3841,6 +3850,9 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
bResult = HookAPIAllMod( Hooks, FALSE, FALSE ); bResult = HookAPIAllMod( Hooks, FALSE, FALSE );
OriginalAttr( lpReserved ); OriginalAttr( lpReserved );
if (search_env( L"ANSICON_WRAP", prog ))
wm = TRUE;
NtQueryInformationThread = (PNTQIT)GetProcAddress( NtQueryInformationThread = (PNTQIT)GetProcAddress(
GetModuleHandle( L"ntdll.dll" ), "NtQueryInformationThread" ); GetModuleHandle( L"ntdll.dll" ), "NtQueryInformationThread" );
if (NtQueryInformationThread == NULL) if (NtQueryInformationThread == NULL)

View File

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

View File

@ -3,7 +3,7 @@
Copyright 2005-2017 Jason Hood Copyright 2005-2017 Jason Hood
Version 1.80. Freeware Version 1.82-wip. Freeware
Description Description
@ -135,6 +135,11 @@ Usage
rent attributes. The shift state and insert mode are always reset for a rent attributes. The shift state and insert mode are always reset for a
new process. new process.
ANSICON will detect when a line wraps at the right margin and suppress a
following newline. Some programs detect the wrap themselves and so the
following newline is actually for a blank line; use the ANSICON_WRAP
variable to indicate as such (see ANSICON_API below).
My version of WriteConsoleA will always set the number of characters writt- My version of WriteConsoleA will always set the number of characters writt-
en, not the number of bytes. This means writing a double-byte character as en, not the number of bytes. This means writing a double-byte character as
two bytes will set 0 the first write (nothing was written) and 1 the second two bytes will set 0 the first write (nothing was written) and 1 the second
@ -334,6 +339,9 @@ Version History
Legend: + added, - bug-fixed, * changed. Legend: + added, - bug-fixed, * changed.
1.82-wip - 12 February, 2018:
- add ANSICON_WRAP for programs that expect the wrap at right margin.
1.81 - 28 December, 2017: 1.81 - 28 December, 2017:
- fix multiple CRs before LF (including preventing an immediate flush); - fix multiple CRs before LF (including preventing an immediate flush);
- fix CR, BS and partial RM during CRM; - fix CR, BS and partial RM during CRM;
@ -600,4 +608,4 @@ Distribution
============================== ==============================
Jason Hood, 28 December, 2017. Jason Hood, 12 February, 2018.

View File

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