mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 16:24:39 +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 LastCursorX;
|
||||||
int LastCursorY;
|
int LastCursorY;
|
||||||
BOOL isAnsiParsingRequired = FALSE;
|
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 */
|
/* 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;
|
int track_view_port = 0;
|
||||||
char *pSavedScreen = NULL;
|
char *pSavedScreen = NULL;
|
||||||
@ -152,6 +153,12 @@ ConEnterRawMode()
|
|||||||
return;
|
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)) {
|
if (!GetConsoleMode(GetConsoleOutputHandle(), &stdout_dwSavedAttributes)) {
|
||||||
dwRet = GetLastError();
|
dwRet = GetLastError();
|
||||||
error("GetConsoleMode on GetConsoleOutputHandle() failed with %d", dwRet);
|
error("GetConsoleMode on GetConsoleOutputHandle() failed with %d", dwRet);
|
||||||
@ -190,7 +197,7 @@ ConEnterRawMode()
|
|||||||
SavedViewRect = csbi.srWindow;
|
SavedViewRect = csbi.srWindow;
|
||||||
debug("console doesn't support the ansi parsing");
|
debug("console doesn't support the ansi parsing");
|
||||||
} else {
|
} 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_out_cp_saved = GetConsoleOutputCP();
|
||||||
console_in_cp_saved = GetConsoleCP();
|
console_in_cp_saved = GetConsoleCP();
|
||||||
if (SetConsoleOutputCP(CP_UTF8))
|
if (SetConsoleOutputCP(CP_UTF8))
|
||||||
|
@ -83,6 +83,10 @@
|
|||||||
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4
|
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
|
||||||
|
#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_NEWLINE_AUTO_RETURN
|
#ifndef DISABLE_NEWLINE_AUTO_RETURN
|
||||||
#define DISABLE_NEWLINE_AUTO_RETURN 0x8
|
#define DISABLE_NEWLINE_AUTO_RETURN 0x8
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,3 +13,4 @@ char *w32_strerror(int);
|
|||||||
static char errorBuf[ERROR_MSG_MAXLEN];
|
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;
|
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 <windows.h>
|
||||||
#include "ansiprsr.h"
|
#include "ansiprsr.h"
|
||||||
#include "inc\utf.h"
|
#include "inc\utf.h"
|
||||||
|
#include "inc\string.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "misc_internal.h"
|
#include "misc_internal.h"
|
||||||
|
|
||||||
#define dwBuffer 4096
|
#define dwBuffer 4096
|
||||||
|
|
||||||
extern BOOL isAnsiParsingRequired;
|
extern BOOL isAnsiParsingRequired;
|
||||||
|
extern BOOL isConsoleVTSeqAvailable;
|
||||||
extern int track_view_port;
|
extern int track_view_port;
|
||||||
extern bool gbVTAppMode;
|
extern bool gbVTAppMode;
|
||||||
BOOL isFirstPacket = TRUE;
|
BOOL isFirstPacket = TRUE;
|
||||||
@ -63,6 +65,8 @@ processBuffer(HANDLE handle, char *buf, DWORD len, unsigned char **respbuf, size
|
|||||||
const char *normalModeSeq = "\x1b[?1l";
|
const char *normalModeSeq = "\x1b[?1l";
|
||||||
const DWORD normalModeSeqLen = (DWORD)strlen(normalModeSeq);
|
const DWORD normalModeSeqLen = (DWORD)strlen(normalModeSeq);
|
||||||
const char *clsSeq = "\x1b[2J";
|
const char *clsSeq = "\x1b[2J";
|
||||||
|
const char *appModePtr = NULL;
|
||||||
|
const char *normalModePtr = NULL;
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return;
|
return;
|
||||||
@ -79,10 +83,18 @@ processBuffer(HANDLE handle, char *buf, DWORD len, unsigned char **respbuf, size
|
|||||||
ConMoveCursorTopOfVisibleWindow();
|
ConMoveCursorTopOfVisibleWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(len >= applicationModeSeqLen && strstr(buf, applicationModeSeq))
|
if (!isConsoleVTSeqAvailable) {
|
||||||
gbVTAppMode = true;
|
if (len >= applicationModeSeqLen && (appModePtr = strrstr(buf, applicationModeSeq)))
|
||||||
else if(len >= normalModeSeqLen && strstr(buf, normalModeSeq))
|
gbVTAppMode = true;
|
||||||
gbVTAppMode = false;
|
|
||||||
|
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.
|
/* 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.
|
* 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