mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
@@ -810,14 +810,33 @@ when defined(windows) and not defined(nimscript) and not defined(js):
|
||||
|
||||
when defined(windows) and appType == "console" and
|
||||
not defined(nimDontSetUtf8CodePage) and not defined(nimscript):
|
||||
import std/exitprocs
|
||||
|
||||
proc setConsoleOutputCP(codepage: cuint): int32 {.stdcall, dynlib: "kernel32",
|
||||
importc: "SetConsoleOutputCP".}
|
||||
proc setConsoleCP(wCodePageID: cuint): int32 {.stdcall, dynlib: "kernel32",
|
||||
importc: "SetConsoleCP".}
|
||||
proc getConsoleOutputCP(): cuint {.stdcall, dynlib: "kernel32",
|
||||
importc: "GetConsoleOutputCP".}
|
||||
proc getConsoleCP(): cuint {.stdcall, dynlib: "kernel32",
|
||||
importc: "GetConsoleCP".}
|
||||
|
||||
const Utf8codepage = 65001
|
||||
discard setConsoleOutputCP(Utf8codepage)
|
||||
discard setConsoleCP(Utf8codepage)
|
||||
|
||||
let
|
||||
consoleOutputCP = getConsoleOutputCP()
|
||||
consoleCP = getConsoleCP()
|
||||
|
||||
proc restoreConsoleOutputCP() = discard setConsoleOutputCP(consoleOutputCP)
|
||||
proc restoreConsoleCP() = discard setConsoleCP(consoleCP)
|
||||
|
||||
if consoleOutputCP != Utf8codepage:
|
||||
discard setConsoleOutputCP(Utf8codepage)
|
||||
addExitProc(restoreConsoleOutputCP)
|
||||
|
||||
if consoleCP != Utf8codepage:
|
||||
discard setConsoleCP(Utf8codepage)
|
||||
addExitProc(restoreConsoleCP)
|
||||
|
||||
proc readFile*(filename: string): string {.tags: [ReadIOEffect], benign.} =
|
||||
## Opens a file named `filename` for reading, calls `readAll
|
||||
|
||||
Reference in New Issue
Block a user