windows: read console with ReadConsole when it is not redirected
parent
b4bf12378e
commit
e10848e0d5
|
@ -533,12 +533,17 @@ pub fn get_raw_line() string {
|
|||
$if windows {
|
||||
max_line_chars := 256
|
||||
buf := &byte(malloc(max_line_chars*2))
|
||||
if C.isConsole > 0 {
|
||||
h_input := C.GetStdHandle(STD_INPUT_HANDLE)
|
||||
mut nr_chars := 0
|
||||
C.ReadConsole(h_input, buf, max_line_chars * 2, &nr_chars, 0)
|
||||
return string_from_wide2(&u16(buf), nr_chars)
|
||||
}
|
||||
res := int( C.fgetws(buf, max_line_chars, C.stdin ) )
|
||||
len := int( C.wcslen(&u16(buf)) )
|
||||
if 0 != res { return string_from_wide2( &u16(buf), len ) }
|
||||
return ''
|
||||
}
|
||||
$else {
|
||||
} $else {
|
||||
max := size_t(256)
|
||||
buf := *char(malloc(int(max)))
|
||||
nr_chars := C.getline(&buf, &max, stdin)
|
||||
|
|
Loading…
Reference in New Issue