Skip to content

Commit

Permalink
Merge pull request #715 from JacobBarthelmeh/examples
Browse files Browse the repository at this point in the history
case of non-console ouptut handle
  • Loading branch information
ejohnstown authored Jul 10, 2024
2 parents bfdcd73 + 816b314 commit 0f9e873
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions apps/wolfssh/wolfssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,20 @@ static THREAD_RET readPeer(void* in)
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 */
/* get console mode will fail on handles that are not a console,
* i.e. if the stdout is being redirected to a file */
if (GetConsoleMode(stdoutHandle, &wrd) != FALSE) {
/* depend on the terminal to process VT characters */
#ifndef _WIN32_WINNT_WIN10
/* support for virtual terminal processing was introduced in windows 10 */
#define _WIN32_WINNT_WIN10 0x0A00
#endif
#if defined(WINVER) && (WINVER >= _WIN32_WINNT_WIN10)
wrd |= (ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT);
#endif
if (SetConsoleMode(stdoutHandle, wrd) == FALSE) {
err_sys("Unable to set console mode");
if (SetConsoleMode(stdoutHandle, wrd) == FALSE) {
err_sys("Unable to set console mode");
}
}
}

Expand Down
28 changes: 14 additions & 14 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,20 @@ static THREAD_RET readPeer(void* in)
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 */
#ifndef _WIN32_WINNT_WIN10
/* support for virtual terminal processing was introduced in windows 10 */
#define _WIN32_WINNT_WIN10 0x0A00
#endif
#if defined(WINVER) && (WINVER >= _WIN32_WINNT_WIN10)
wrd |= (ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT);
#endif
if (SetConsoleMode(stdoutHandle, wrd) == FALSE) {
err_sys("Unable to set console mode");
/* get console mode will fail on handles that are not a console,
* i.e. if the stdout is being redirected to a file */
if (GetConsoleMode(stdoutHandle, &wrd) != FALSE) {
/* depend on the terminal to process VT characters */
#ifndef _WIN32_WINNT_WIN10
/* support for virtual terminal processing was introduced in windows 10 */
#define _WIN32_WINNT_WIN10 0x0A00
#endif
#if defined(WINVER) && (WINVER >= _WIN32_WINNT_WIN10)
wrd |= (ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT);
#endif
if (SetConsoleMode(stdoutHandle, wrd) == FALSE) {
err_sys("Unable to set console mode");
}
}
}

Expand Down

0 comments on commit 0f9e873

Please sign in to comment.