diff options
Diffstat (limited to 'src/io/term.nim')
| -rw-r--r-- | src/io/term.nim | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/io/term.nim b/src/io/term.nim index 5103c153..d60d5746 100644 --- a/src/io/term.nim +++ b/src/io/term.nim @@ -1,14 +1,31 @@ import terminal +when defined(posix): + import termios type TermAttributes* = object - termWidth*: int - termHeight*: int + width*: int + height*: int + ppc*: int + ppl*: int proc getTermAttributes*(): TermAttributes = - let attrs = TermAttributes(termWidth: terminalWidth(), - termHeight: terminalHeight()) - return attrs + if stdin.isatty(): + when defined(posix): + var win: IOctl_WinSize + if ioctl(cint(getOsFileHandle(stdout)), TIOCGWINSZ, addr win) != -1: + result.width = int(win.ws_col) + result.height = int(win.ws_row) + result.ppc = int(win.ws_xpixel) div int(win.ws_col) + result.ppl = int(win.ws_ypixel) div int(win.ws_row) + return + #fail + result.width = terminalWidth() + result.height = terminalHeight() + if result.height == 0: + result.height = 24 + result.ppc = 9 + result.ppl = 18 proc termGoto*(x: int, y: int) = setCursorPos(stdout, x, y) |