diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index 9eeeaa6df8..bf8ac8531f 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -8,15 +8,10 @@ __global g_m2_ptr byteptr fn init() { $if windows { - if is_atty(0) > 0 { - C._setmode(C._fileno(C.stdin), C._O_U16TEXT) + if is_atty(1) > 0 { + C.SetConsoleMode(C.GetStdHandle(C.STD_OUTPUT_HANDLE), C.ENABLE_PROCESSED_OUTPUT | 0x0004) // ENABLE_VIRTUAL_TERMINAL_PROCESSING + C.setbuf(C.stdout, 0) } - else { - C._setmode(C._fileno(C.stdin), C._O_U8TEXT) - } - C._setmode(C._fileno(C.stdout), C._O_U8TEXT) - C.SetConsoleMode(C.GetStdHandle(C.STD_OUTPUT_HANDLE), C.ENABLE_PROCESSED_OUTPUT | 0x0004) // ENABLE_VIRTUAL_TERMINAL_PROCESSING - C.setbuf(C.stdout, 0) } } diff --git a/vlib/builtin/cfns.v b/vlib/builtin/cfns.v index f48abf8773..14befde820 100644 --- a/vlib/builtin/cfns.v +++ b/vlib/builtin/cfns.v @@ -197,8 +197,6 @@ fn C.syscall() int fn C.sysctl() int -// Windows -fn C._setmode(int, int) int fn C._fileno(int) int @@ -252,9 +250,6 @@ fn C.SetConsoleMode() fn C.GetConsoleMode() int -fn C._putws() - - fn C.wprintf() @@ -312,9 +307,6 @@ fn C.WriteConsole() voidptr fn C.WriteFile() voidptr -fn C.fgetws() voidptr - - fn C.GetModuleFileName() int diff --git a/vlib/compiler/cheaders.v b/vlib/compiler/cheaders.v index 4d6a95c915..e9fe91b56b 100644 --- a/vlib/compiler/cheaders.v +++ b/vlib/compiler/cheaders.v @@ -60,13 +60,6 @@ const ( #include // tolower #include #include // sleep -#else -#if defined(_MSC_VER) -#pragma comment(lib, "Dbghelp.lib") -#endif -#if defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < __MSVCR90_DLL -#error Please upgrade your MinGW distribution to use msvcr90.dll or later. -#endif #endif #if defined(__CYGWIN__) && !defined(_WIN32) @@ -108,13 +101,7 @@ $c_common_macros #define UNICODE #include -// must be included after -#ifndef __TINYC__ -#include -#endif - #include // _waccess -#include // _O_U8TEXT #include // _wgetcwd //#include #ifdef _MSC_VER @@ -127,6 +114,10 @@ $c_common_macros #define EMPTY_STRUCT_DECLARATION int ____dummy_variable #define OPTION_CAST(x) + +#include +#pragma comment(lib, "Dbghelp.lib") + #endif #else diff --git a/vlib/os/os.v b/vlib/os/os.v index ba7ae06ff7..1418602eb2 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -646,18 +646,26 @@ pub fn get_raw_line() string { $if windows { max_line_chars := 256 buf := malloc(max_line_chars * 2) + h_input := C.GetStdHandle(STD_INPUT_HANDLE) + mut bytes_read := 0 if is_atty(0) > 0 { - h_input := C.GetStdHandle(STD_INPUT_HANDLE) - mut nr_chars := u32(0) - C.ReadConsole(h_input, buf, max_line_chars * 2, voidptr(&nr_chars), 0) - return string_from_wide2(&u16(buf), int(nr_chars)) + C.ReadConsole(h_input, buf, max_line_chars * 2, &bytes_read, 0) + return string_from_wide2(&u16(buf), bytes_read) } - res := C.fgetws(&u16(buf), max_line_chars, C.stdin) - len := C.wcslen(&u16(buf)) - if !isnil(res) { - return string_from_wide2(&u16(buf), len) + mut offset := 0 + for { + pos := buf + offset + res := C.ReadFile(h_input, pos, 1, &bytes_read, 0) + if !res || bytes_read == 0 { + break + } + if *pos == `\n` || *pos == `\r` { + offset++ + break + } + offset++ } - return '' + return string(buf, offset) } $else { max := size_t(256) buf := charptr(malloc(int(max)))