File: gs.py

package info (click to toggle)
pydf 14%2Bgit20170320.5996c59-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116 kB
  • sloc: python: 551; makefile: 10
file content (29 lines) | stat: -rwxr-xr-x 739 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/python

# get terminal size
# from resize(1)
# it does not work quite properly and there is a simpler way
#
# do not use

import os, time, termios
from termios import ICRNL, IUCLC, ICANON, ECHO, CS8, VMIN, VTIME, TCSANOW, TCSADRAIN, TCSAFLUSH

getsize = "\0337\033[r\033[999;999H\0336n\033[18t"
restoreemu = "\0338"
ttyfd = os.open('/dev/tty', os.O_RDWR)

tioorig = termios.tcgetattr(ttyfd)
tio = tioorig[:]

tio[0] &= ~(ICRNL | IUCLC) # iflag
tio[3] &= ~(ICANON | ECHO) # lflag
tio[2] |= CS8 # cflag
tio[6][VMIN] = 6 # cc
tio[6][VTIME] = 1 # cc
termios.tcsetattr(ttyfd, TCSAFLUSH, tio)
os.write(ttyfd, getsize)
x = os.read(ttyfd, len(getsize))
os.write(ttyfd, restoreemu)
termios.tcsetattr(ttyfd, TCSADRAIN, tioorig)
print `x`