mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: use C.write for print/eprint . Call C.SetConsoleOutputCP(C.CP_UTF8) on windows
This commit is contained in:
@@ -59,11 +59,25 @@ const (
|
||||
symopt_debug = 0x80000000
|
||||
)
|
||||
|
||||
// g_original_codepage - used to restore the original windows console code page when exiting
|
||||
__global g_original_codepage u32=0
|
||||
// utf8 to stdout needs C.SetConsoleOutputCP(C.CP_UTF8)
|
||||
fn C.GetConsoleOutputCP() u32
|
||||
fn C.SetConsoleOutputCP(wCodePageID u32) bool
|
||||
fn restore_codepage() {
|
||||
C.SetConsoleOutputCP( g_original_codepage )
|
||||
}
|
||||
|
||||
fn builtin_init() {
|
||||
g_original_codepage = C.GetConsoleOutputCP()
|
||||
C.SetConsoleOutputCP(C.CP_UTF8)
|
||||
C.atexit(restore_codepage)
|
||||
if is_atty(1) > 0 {
|
||||
C.SetConsoleMode(C.GetStdHandle(C.STD_OUTPUT_HANDLE), C.ENABLE_PROCESSED_OUTPUT | 0x0004) // enable_virtual_terminal_processing
|
||||
C.SetConsoleMode(C.GetStdHandle(C.STD_ERROR_HANDLE), C.ENABLE_PROCESSED_OUTPUT | 0x0004) // enable_virtual_terminal_processing
|
||||
unsafe {
|
||||
C.setbuf(C.stdout, 0)
|
||||
C.setbuf(C.stderr, 0)
|
||||
}
|
||||
}
|
||||
add_unhandled_exception_handler()
|
||||
|
||||
Reference in New Issue
Block a user