mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 08:14:24 +02:00
Read VTSequence from console (#412)
Use console win32 API to read the VTSequence for keystrokes on client-side.
This commit is contained in:
parent
9e42eb0c76
commit
34608f3d29
@ -55,6 +55,7 @@ int ScrollBottom;
|
||||
int LastCursorX;
|
||||
int LastCursorY;
|
||||
BOOL isAnsiParsingRequired = FALSE;
|
||||
BOOL isConsoleVTSeqAvailable = FALSE;
|
||||
/* 1 - We track the viewport (visible window) and restore it back because console renders badly when user scroll up/down */
|
||||
int track_view_port = 0;
|
||||
char *pSavedScreen = NULL;
|
||||
@ -152,6 +153,12 @@ ConEnterRawMode()
|
||||
return;
|
||||
}
|
||||
|
||||
dwAttributes |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
||||
if (SetConsoleMode(GetConsoleInputHandle(), dwAttributes)) {
|
||||
debug("ENABLE_VIRTUAL_TERMINAL_INPUT is supported. Reading the VTSequence from console");
|
||||
isConsoleVTSeqAvailable = TRUE;
|
||||
}
|
||||
|
||||
if (!GetConsoleMode(GetConsoleOutputHandle(), &stdout_dwSavedAttributes)) {
|
||||
dwRet = GetLastError();
|
||||
error("GetConsoleMode on GetConsoleOutputHandle() failed with %d", dwRet);
|
||||
@ -190,7 +197,7 @@ ConEnterRawMode()
|
||||
SavedViewRect = csbi.srWindow;
|
||||
debug("console doesn't support the ansi parsing");
|
||||
} else {
|
||||
debug("console supports the ansi parsing");
|
||||
debug("ENABLE_VIRTUAL_TERMINAL_PROCESSING is supported. Console supports the ansi parsing");
|
||||
console_out_cp_saved = GetConsoleOutputCP();
|
||||
console_in_cp_saved = GetConsoleCP();
|
||||
if (SetConsoleOutputCP(CP_UTF8))
|
||||
|
@ -83,6 +83,10 @@
|
||||
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
|
||||
#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_NEWLINE_AUTO_RETURN
|
||||
#define DISABLE_NEWLINE_AUTO_RETURN 0x8
|
||||
#endif
|
||||
|
@ -12,4 +12,5 @@ char *w32_strerror(int);
|
||||
|
||||
static char errorBuf[ERROR_MSG_MAXLEN];
|
||||
|
||||
char *strndup(const char*, size_t);
|
||||
char *strndup(const char*, size_t);
|
||||
char * strrstr(const char *, const char *);
|
@ -1994,3 +1994,14 @@ cleanup:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
strrstr(const char *inStr, const char *pattern)
|
||||
{
|
||||
char *tmp = NULL, *last = NULL;
|
||||
tmp = (char *) inStr;
|
||||
while(tmp = strstr(tmp, pattern))
|
||||
last = tmp++;
|
||||
|
||||
return last;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -36,12 +36,14 @@
|
||||
#include <windows.h>
|
||||
#include "ansiprsr.h"
|
||||
#include "inc\utf.h"
|
||||
#include "inc\string.h"
|
||||
#include "console.h"
|
||||
#include "misc_internal.h"
|
||||
|
||||
#define dwBuffer 4096
|
||||
|
||||
extern BOOL isAnsiParsingRequired;
|
||||
extern BOOL isConsoleVTSeqAvailable;
|
||||
extern int track_view_port;
|
||||
extern bool gbVTAppMode;
|
||||
BOOL isFirstPacket = TRUE;
|
||||
@ -63,6 +65,8 @@ processBuffer(HANDLE handle, char *buf, DWORD len, unsigned char **respbuf, size
|
||||
const char *normalModeSeq = "\x1b[?1l";
|
||||
const DWORD normalModeSeqLen = (DWORD)strlen(normalModeSeq);
|
||||
const char *clsSeq = "\x1b[2J";
|
||||
const char *appModePtr = NULL;
|
||||
const char *normalModePtr = NULL;
|
||||
|
||||
if (len == 0)
|
||||
return;
|
||||
@ -79,10 +83,18 @@ processBuffer(HANDLE handle, char *buf, DWORD len, unsigned char **respbuf, size
|
||||
ConMoveCursorTopOfVisibleWindow();
|
||||
}
|
||||
|
||||
if(len >= applicationModeSeqLen && strstr(buf, applicationModeSeq))
|
||||
gbVTAppMode = true;
|
||||
else if(len >= normalModeSeqLen && strstr(buf, normalModeSeq))
|
||||
gbVTAppMode = false;
|
||||
if (!isConsoleVTSeqAvailable) {
|
||||
if (len >= applicationModeSeqLen && (appModePtr = strrstr(buf, applicationModeSeq)))
|
||||
gbVTAppMode = true;
|
||||
|
||||
if (len >= normalModeSeqLen && (normalModePtr = strrstr(buf, normalModeSeq)))
|
||||
{
|
||||
if (appModePtr && (appModePtr > normalModePtr))
|
||||
gbVTAppMode = true;
|
||||
else
|
||||
gbVTAppMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* WriteFile() gets messy when user does scroll up/down so we need to restore the visible window.
|
||||
* It's a conhost bug but we need to live with it as they are not going to back port the fix.
|
||||
|
Loading…
x
Reference in New Issue
Block a user