Skip to content

Commit

Permalink
feat: sys.std{in,out,err} with bug of stdin not for unicode.
Browse files Browse the repository at this point in the history
Use readChar underline, which returns wrong char when meeting
non-ASCII for `stdin`
under Windows.
  • Loading branch information
litlighilit committed May 19, 2024
1 parent 8ab9553 commit c39082b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/pylib/Lib/sys.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ import ../noneType
import ../pystring/strimpl
export list, strimpl

when not defined(pylibSysNoStdio):
import ./io
export io.read, io.readline, io.write, io.fileno, io.isatty

template wrap(ioe): untyped =
var ioe* = newNoEncTextIO(
name = '<' & astToStr(ioe) & '>',
file = system.ioe, newline=DefNewLine)
# XXX: NIM-BUG: under Windows, system.stdin.readChar for non-ASCII is buggy,
# returns a random char for one unicode.
wrap stdin
wrap stdout
wrap stderr
stdin.mode = "r"
stdout.mode = "w"
stderr.mode = "w"

proc exit*(s: PyStr) = quit($s)
func exit*(c: int) = quit(c)
Expand Down

0 comments on commit c39082b

Please sign in to comment.