diff options
Diffstat (limited to 'lib/pure/terminal.nim')
-rw-r--r-- | lib/pure/terminal.nim | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim index 29f700db5..1e9c40f06 100644 --- a/lib/pure/terminal.nim +++ b/lib/pure/terminal.nim @@ -20,7 +20,7 @@ when defined(windows): import windows, os var - conHandle: THandle + conHandle: Handle # = createFile("CONOUT$", GENERIC_WRITE, 0, nil, OPEN_ALWAYS, 0, 0) block: @@ -30,13 +30,13 @@ when defined(windows): raiseOSError(osLastError()) proc getCursorPos(): tuple [x,y: int] = - var c: TCONSOLESCREENBUFFERINFO + var c: CONSOLESCREENBUFFERINFO if GetConsoleScreenBufferInfo(conHandle, addr(c)) == 0: raiseOSError(osLastError()) return (int(c.dwCursorPosition.X), int(c.dwCursorPosition.Y)) proc getAttributes(): int16 = - var c: TCONSOLESCREENBUFFERINFO + var c: CONSOLESCREENBUFFERINFO # workaround Windows bugs: try several times if GetConsoleScreenBufferInfo(conHandle, addr(c)) != 0: return c.wAttributes @@ -51,11 +51,11 @@ else: proc setRaw(fd: FileHandle, time: cint = TCSAFLUSH) = var mode: Termios discard fd.tcgetattr(addr mode) - mode.c_iflag = mode.c_iflag and not Tcflag(BRKINT or ICRNL or INPCK or + mode.c_iflag = mode.c_iflag and not Cflag(BRKINT or ICRNL or INPCK or ISTRIP or IXON) - mode.c_oflag = mode.c_oflag and not Tcflag(OPOST) - mode.c_cflag = (mode.c_cflag and not Tcflag(CSIZE or PARENB)) or CS8 - mode.c_lflag = mode.c_lflag and not Tcflag(ECHO or ICANON or IEXTEN or ISIG) + mode.c_oflag = mode.c_oflag and not Cflag(OPOST) + mode.c_cflag = (mode.c_cflag and not Cflag(CSIZE or PARENB)) or CS8 + mode.c_lflag = mode.c_lflag and not Cflag(ECHO or ICANON or IEXTEN or ISIG) mode.c_cc[VMIN] = 1.cuchar mode.c_cc[VTIME] = 0.cuchar discard fd.tcsetattr(time, addr mode) @@ -64,7 +64,7 @@ proc setCursorPos*(x, y: int) = ## sets the terminal's cursor to the (x,y) position. (0,0) is the ## upper left of the screen. when defined(windows): - var c: TCOORD + var c: COORD c.X = int16(x) c.Y = int16(y) if SetConsoleCursorPosition(conHandle, c) == 0: raiseOSError(osLastError()) @@ -75,7 +75,7 @@ proc setCursorXPos*(x: int) = ## sets the terminal's cursor to the x position. The y position is ## not changed. when defined(windows): - var scrbuf: TCONSOLESCREENBUFFERINFO + var scrbuf: CONSOLESCREENBUFFERINFO var hStdout = conHandle if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: raiseOSError(osLastError()) @@ -91,7 +91,7 @@ when defined(windows): ## sets the terminal's cursor to the y position. The x position is ## not changed. **Warning**: This is not supported on UNIX! when defined(windows): - var scrbuf: TCONSOLESCREENBUFFERINFO + var scrbuf: CONSOLESCREENBUFFERINFO var hStdout = conHandle if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: raiseOSError(osLastError()) @@ -172,7 +172,7 @@ else: proc eraseLine* = ## Erases the entire current line. when defined(windows): - var scrbuf: TCONSOLESCREENBUFFERINFO + var scrbuf: CONSOLESCREENBUFFERINFO var numwrote: DWORD var hStdout = conHandle if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: @@ -196,9 +196,9 @@ proc eraseLine* = proc eraseScreen* = ## Erases the screen with the background colour and moves the cursor to home. when defined(windows): - var scrbuf: TCONSOLESCREENBUFFERINFO + var scrbuf: CONSOLESCREENBUFFERINFO var numwrote: DWORD - var origin: TCOORD # is inititalized to 0, 0 + var origin: COORD # is inititalized to 0, 0 var hStdout = conHandle if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: @@ -364,7 +364,13 @@ macro styledEcho*(m: varargs[expr]): stmt = result.add(newCall(bindSym"write", bindSym"stdout", newStrLitNode("\n"))) result.add(newCall(bindSym"resetAttributes")) -when not defined(windows): +when defined(nimdoc): + proc getch*(): char = + ## Read a single character from the terminal, blocking until it is entered. + ## The character is not printed to the terminal. This is not available for + ## Windows. + discard +elif not defined(windows): proc getch*(): char = ## Read a single character from the terminal, blocking until it is entered. ## The character is not printed to the terminal. This is not available for |