diff --git a/vlib/benchmark/benchmark.v b/vlib/benchmark/benchmark.v index e00e1f49a3..ddbcc5ebaf 100644 --- a/vlib/benchmark/benchmark.v +++ b/vlib/benchmark/benchmark.v @@ -104,7 +104,7 @@ pub fn (b mut Benchmark) total_duration() i64 { fn (b mut Benchmark) tdiff_in_ms(s string, sticks i64, eticks i64) string { if b.verbose { tdiff := (eticks - sticks) - return '${tdiff:6d} ms | $s' + return '${tdiff:6lld} ms | $s' } return s } diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index f88b8ba236..0becdf91a4 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -6,7 +6,7 @@ module builtin fn init() { $if windows { - if is_atty(0) { + if is_atty(0) > 0 { C._setmode(C._fileno(C.stdin), C._O_U16TEXT) } else { C._setmode(C._fileno(C.stdin), C._O_U8TEXT) @@ -195,13 +195,13 @@ fn v_ptr_free(ptr voidptr) { C.free(ptr) } -pub fn is_atty(fd int) bool { +pub fn is_atty(fd int) int { $if windows { mut mode := 0 C.GetConsoleMode(C._get_osfhandle(fd), &mode) - return mode > 0 + return mode } $else { - return C.isatty(fd) != 0 + return C.isatty(fd) } } diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 19d3bfb79b..53f5968308 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -645,7 +645,11 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type // Also register the wrapper, so we can use the original function without modifying it fn_name = p.table.fn_gen_name(f) wrapper_name := '${fn_name}_thread_wrapper' - wrapper_text := 'void* $wrapper_name($arg_struct_name * arg) {$fn_name( /*f*/$str_args ); }' + mut wrapper_type := 'void*' + if p.os == .windows { + wrapper_type = 'void* __stdcall' + } + wrapper_text := '$wrapper_type $wrapper_name($arg_struct_name * arg) {$fn_name( /*f*/$str_args ); }' p.cgen.register_thread_fn(wrapper_name, wrapper_text, arg_struct) // Create thread object tmp_nr := p.get_tmp_counter() diff --git a/vlib/os/os.v b/vlib/os/os.v index 26538440c1..93f13d2adc 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -580,7 +580,7 @@ pub fn get_raw_line() string { $if windows { max_line_chars := 256 buf := &byte(malloc(max_line_chars*2)) - if is_atty(0) { + if is_atty(0) > 0 { h_input := C.GetStdHandle(STD_INPUT_HANDLE) mut nr_chars := 0 C.ReadConsole(h_input, buf, max_line_chars * 2, &nr_chars, 0) diff --git a/vlib/term/can_show_color.v b/vlib/term/can_show_color.v index 2e8ad05631..568280a981 100644 --- a/vlib/term/can_show_color.v +++ b/vlib/term/can_show_color.v @@ -3,11 +3,19 @@ module term import os pub fn can_show_color_on_stdout() bool { - return is_atty(1) && os.getenv('TERM') != 'dumb' + return supports_escape_sequences(1) } pub fn can_show_color_on_stderr() bool { - return is_atty(2) && os.getenv('TERM') != 'dumb' + return supports_escape_sequences(2) +} + +fn supports_escape_sequences(fd int) bool { + $if windows { + return (is_atty(fd) & 0x0004) > 0 && os.getenv('TERM') != 'dumb' // ENABLE_VIRTUAL_TERMINAL_PROCESSING + } $else { + return is_atty(fd) > 0 && os.getenv('TERM') != 'dumb' + } } //////////////////////////////////////////////