1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

make V work on Windows 7

This commit is contained in:
vitalyster 2019-11-06 23:04:40 +03:00 committed by Alexander Medvednikov
parent e266c8a750
commit 8dbeab9a7b
5 changed files with 21 additions and 9 deletions

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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()

View File

@ -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)

View File

@ -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'
}
}
//////////////////////////////////////////////