Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitcrazed/enable windows vt support - fixes #3008 #3011

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -56,3 +56,5 @@ scripts/_curl
curl_fuzzer
curl_fuzzer_seed_corpus.zip
libstandaloneengine.a
.vscode/
*.debugtarget
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being development environment specific, these two are probably better handled locally in $GIT_DIR/info/exclude

56 changes: 56 additions & 0 deletions src/tool_main.c
Expand Up @@ -236,6 +236,56 @@ static void main_free(struct GlobalConfig *config)
config->last = NULL;
}

#if defined(_WIN32)
/* TerminalSettings for Windows */
struct TerminalSettings {
HANDLE hStdOut;
DWORD dwOutputMode;
UINT nCodepage;
}TerminalSettings;
#endif

static void configure_terminal(void)
{
#if defined(_WIN32)
/*
* If we're running Windows, enable VT output & set codepage to UTF-8.
* Note: VT mode flag can be set on any version of Windows, but VT
* processing only performed on Win10 >= Creators Update)
*/

/* Define the VT flags in case we're building with an older SDK */
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif

/* Cache current codepage (will restore on exit) & set codepage to UTF-8 */
memset(&TerminalSettings, 0, sizeof(TerminalSettings));
TerminalSettings.nCodepage = GetConsoleOutputCP();
SetConsoleOutputCP(65001);

/* Enable VT output */
TerminalSettings.hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if((TerminalSettings.hStdOut != INVALID_HANDLE_VALUE)
&& (GetConsoleMode(TerminalSettings.hStdOut,
&TerminalSettings.dwOutputMode))) {
SetConsoleMode(TerminalSettings.hStdOut,
TerminalSettings.dwOutputMode
| ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
#endif
}

static void restore_terminal(void)
{
#if defined(_WIN32)
/* Restore Console output mode and codepage to whatever they were
* when Curl started */
SetConsoleMode(TerminalSettings.hStdOut, TerminalSettings.dwOutputMode);
SetConsoleOutputCP(TerminalSettings.nCodepage);
#endif
}

/*
** curl tool main function.
*/
Expand All @@ -245,6 +295,9 @@ int main(int argc, char *argv[])
struct GlobalConfig global;
memset(&global, 0, sizeof(global));

/* Perform any platform-specific terminal configuration */
configure_terminal();

main_checkfds();

#if defined(HAVE_SIGNAL) && defined(SIGPIPE)
Expand All @@ -270,6 +323,9 @@ int main(int argc, char *argv[])
main_free(&global);
}

/* Return the terminal to its original state */
restore_terminal();

#ifdef __NOVELL_LIBC__
if(getenv("_IN_NETWARE_BASH_") == NULL)
tool_pressanykey();
Expand Down
12 changes: 12 additions & 0 deletions winbuild/makedebug.cmd
@@ -0,0 +1,12 @@
@echo off

where.exe nmake.exe >nul 2>&1

IF %ERRORLEVEL == 1 (
ECHO Error: Can't find `nmake.exe` - be sure to run this script from within a Developer Command-Prompt
ECHO.
) ELSE (
nmake /f Makefile.vc mode=static DEBUG=yes GEN_PDB=yes
IF %ERRORLEVEL% NEQ 0 (ECHO "Error: Build Failed")
)

2 changes: 2 additions & 0 deletions winbuild/rundebug.cmd
@@ -0,0 +1,2 @@
@echo off
start cmd /k ..\builds\libcurl-vc-x86-debug-static-ipv6-sspi-winssl\bin\curl.exe https://wttr.in/seattle