term: add better error detection on Windows
parent
2a30564ed1
commit
c7edeb00a8
|
@ -11,14 +11,24 @@ import os
|
||||||
// is imported on a certain os. for example to run this?
|
// is imported on a certain os. for example to run this?
|
||||||
pub fn enable_term_color_win() {
|
pub fn enable_term_color_win() {
|
||||||
$if windows {
|
$if windows {
|
||||||
|
mode_wanted := os.ENABLE_PROCESSED_OUTPUT | os.ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
||||||
|
mut mode_current := 0
|
||||||
h_output := C.GetStdHandle(os.STD_OUTPUT_HANDLE)
|
h_output := C.GetStdHandle(os.STD_OUTPUT_HANDLE)
|
||||||
if h_output == os.INVALID_HANDLE_VALUE
|
if h_output == os.INVALID_HANDLE_VALUE {
|
||||||
|| !C.SetConsoleMode(h_output, os.ENABLE_PROCESSED_OUTPUT|os.ENABLE_VIRTUAL_TERMINAL_PROCESSING) {
|
panic('term.enable_term_color_win(): error getting output handle.')
|
||||||
println('enable_term_color_win() Sorry, there was an error enabling terminal color.')
|
}
|
||||||
|
if !C.GetConsoleMode(h_output, &mode_current) {
|
||||||
|
panic('term.enable_term_color_win(): error getting console mode.')
|
||||||
|
}
|
||||||
|
if mode_wanted == mode_current {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !C.SetConsoleMode(h_output, mode_wanted) {
|
||||||
|
panic('term.enable_term_color_win(): error setting console mode.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$else {
|
$else {
|
||||||
println('enable_term_color_win() should only be called on windows.')
|
println('term.enable_term_color_win() should only be called on windows.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue