about summary refs log tree commit diff stats
path: root/src/io/term.nim
blob: d60d5746f9c6abe723ceb93e8ba6d634165694ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import terminal
when defined(posix):
  import termios

type
  TermAttributes* = object
    width*: int
    height*: int
    ppc*: int
    ppl*: int

proc getTermAttributes*(): TermAttributes =
  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)