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 {
|
$if windows {
|
||||||
max_line_chars := 256
|
max_line_chars := 256
|
||||||
buf := &byte(malloc(max_line_chars*2))
|
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 ) )
|
res := int( C.fgetws(buf, max_line_chars, C.stdin ) )
|
||||||
len := int( C.wcslen(&u16(buf)) )
|
len := int( C.wcslen(&u16(buf)) )
|
||||||
if 0 != res { return string_from_wide2( &u16(buf), len ) }
|
if 0 != res { return string_from_wide2( &u16(buf), len ) }
|
||||||
return ''
|
return ''
|
||||||
}
|
} $else {
|
||||||
$else {
|
|
||||||
max := size_t(256)
|
max := size_t(256)
|
||||||
buf := *char(malloc(int(max)))
|
buf := *char(malloc(int(max)))
|
||||||
nr_chars := C.getline(&buf, &max, stdin)
|
nr_chars := C.getline(&buf, &max, stdin)
|
||||||
|
|
Loading…
Reference in New Issue