blob: dc54a34c82408600d8e44c7aa99908564ddb337e (
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
|
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
|