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

os: add term colors for Windows +minor fixes

This commit is contained in:
joe-conigliaro
2019-07-05 01:39:35 +10:00
committed by Alexander Medvednikov
parent b745234a52
commit 4e1afc148a
3 changed files with 54 additions and 12 deletions

View File

@@ -4,6 +4,24 @@
module term
import os
// Calling this functions enables color terminal output on windows
// Maybe implement a way to auto run an init function when a module
// is imported on a certain os. for example to run this?
pub fn enable_term_color_win() {
$if windows {
h_output := C.GetStdHandle(os.STD_OUTPUT_HANDLE)
if h_output == os.INVALID_HANDLE_VALUE
|| !C.SetConsoleMode(h_output, os.ENABLE_PROCESSED_OUTPUT|os.ENABLE_VIRTUAL_TERMINAL_PROCESSING) {
println('enable_term_color_win() Sorry, there was an error enabling terminal color.')
}
}
$else {
println('enable_term_color_win() should only be called on windows.')
}
}
pub fn format(msg, open, close string) string {
return '\x1b[' + open + 'm' + msg + '\x1b[' + close + 'm'
}