Skip to content

Commit

Permalink
use windows terminal parsing for VT wolfssh.c
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Mar 6, 2024
1 parent e137865 commit 9c7edce
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions apps/wolfssh/wolfssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ static THREAD_RET readPeer(void* in)
FD_SET(fd, &errSet);

#ifdef USE_WINDOWS_API
if (args->rawMode == 0) {
DWORD wrd;

if (GetConsoleMode(stdoutHandle, &wrd) == FALSE) {
err_sys("Unable to get stdout handle");
}

/* depend on the terminal to process VT characters */
wrd |= (ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT);
if (SetConsoleMode(stdoutHandle, wrd) == FALSE) {
err_sys("Unable to set console mode");
}
}

/* set handle to use for window resize */
wc_LockMutex(&args->lock);
wolfSSH_SetTerminalResizeCtx(args->ssh, stdoutHandle);
Expand Down Expand Up @@ -482,22 +496,14 @@ static THREAD_RET readPeer(void* in)
}
}
else {
#ifdef USE_WINDOWS_API
DWORD writtn = 0;
#endif
buf[bufSz - 1] = '\0';

#ifdef USE_WINDOWS_API
if (args->rawMode == 0) {
ret = wolfSSH_ConvertConsole(args->ssh, stdoutHandle, buf,
ret);
if (ret != WS_SUCCESS && ret != WS_WANT_READ) {
err_sys("issue with print out");
}
if (ret == WS_WANT_READ) {
ret = 0;
}
}
else {
printf("%s", buf);
fflush(stdout);
if (WriteFile(stdoutHandle, buf, bufSz, &writtn, NULL) == FALSE) {
err_sys("Failed to write to stdout handle");
}
#else
if (write(STDOUT_FILENO, buf, ret) < 0) {
Expand Down

0 comments on commit 9c7edce

Please sign in to comment.