Fix problem with reporting cursor position

Turns out that sending duplicate characters would only send one (e.g.
"11" would just be "1").  Sending the key up events fixed it.
This commit is contained in:
Jason Hood 2017-11-03 23:04:51 +10:00
parent 2f3fe57b60
commit 43b3653c8a
3 changed files with 23 additions and 15 deletions

30
ANSI.c
View File

@ -152,11 +152,12 @@
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 to 30 October, 2017: v1.80, 26 October to 3 November, 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;
hook CreateFile & CreateConsoleScreenBuffer to enable readable handles. hook CreateFile & CreateConsoleScreenBuffer to enable readable handles;
fix cursor report with duplicated digits (e.g. "11" was just "1").
*/ */
#include "ansicon.h" #include "ansicon.h"
@ -610,20 +611,25 @@ void PushBuffer( WCHAR c )
void SendSequence( LPTSTR seq ) void SendSequence( LPTSTR seq )
{ {
DWORD out; DWORD out;
INPUT_RECORD in; PINPUT_RECORD in;
DWORD len;
HANDLE hStdIn = GetStdHandle( STD_INPUT_HANDLE ); HANDLE hStdIn = GetStdHandle( STD_INPUT_HANDLE );
in.EventType = KEY_EVENT; in = HeapAlloc( hHeap, HEAP_ZERO_MEMORY, 2 * wcslen( seq ) * sizeof(*in) );
in.Event.KeyEvent.bKeyDown = TRUE; if (in == NULL)
in.Event.KeyEvent.wRepeatCount = 1; return;
in.Event.KeyEvent.wVirtualKeyCode = 0; for (len = 0; *seq; len += 2, ++seq)
in.Event.KeyEvent.wVirtualScanCode = 0;
in.Event.KeyEvent.dwControlKeyState = 0;
for (; *seq; ++seq)
{ {
in.Event.KeyEvent.uChar.UnicodeChar = *seq; in[len+0].EventType =
WriteConsoleInput( hStdIn, &in, 1, &out ); in[len+1].EventType = KEY_EVENT;
in[len+0].Event.KeyEvent.wRepeatCount =
in[len+1].Event.KeyEvent.wRepeatCount = 1;
in[len+0].Event.KeyEvent.uChar.UnicodeChar =
in[len+1].Event.KeyEvent.uChar.UnicodeChar = *seq;
in[len+0].Event.KeyEvent.bKeyDown = TRUE;
} }
WriteConsoleInput( hStdIn, in, len, &out );
HeapFree( hHeap, 0, in );
} }
// ========== Print functions // ========== Print functions

View File

@ -90,7 +90,7 @@
write newline with _putws, not putwchar (fixes redirecting to CON). write newline with _putws, not putwchar (fixes redirecting to CON).
*/ */
#define PDATE L"30 October, 2017" #define PDATE L"3 November, 2017"
#include "ansicon.h" #include "ansicon.h"
#include "version.h" #include "version.h"

View File

@ -295,11 +295,12 @@ Version History
Legend: + added, - bug-fixed, * changed. Legend: + added, - bug-fixed, * changed.
1.80 - 28 October, 2017: 1.80 - 3 November, 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
(fixes redirecting to CON and Microsoft's conio); (fixes redirecting to CON and Microsoft's conio);
- fix cursor report with duplicated digits (e.g. "11" was only writing "1");
* go back to saving the buffer cursor position. * go back to saving the buffer cursor position.
1.72 - 24 December, 2015: 1.72 - 24 December, 2015:
@ -505,6 +506,7 @@ Acknowledgments
Leigh Hebblethwaite for documentation tweaks. Leigh Hebblethwaite for documentation tweaks.
Vincent Fatica for pointing out \e[K was not right. Vincent Fatica for pointing out \e[K was not right.
Nat Kuhn for pointing out the problem with report cursor position.
Contact Contact
@ -528,4 +530,4 @@ Distribution
============================= =============================
Jason Hood, 30 October, 2017. Jason Hood, 3 November, 2017.