-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtermsize.py
executable file
·46 lines (36 loc) · 913 Bytes
/
termsize.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
Get terminal size.
"""
__author__ = "mikoto2000 <[email protected]>"
__version__ = "1.0.0"
__date__ = "22 Apr 2015"
__USEAGE__ = """Useage: termsize.py PATH_TO_PTS"""
import struct,fcntl,termios,sys;
"""
Get terminal size.
Return terminal size array.
[0] : line count.
[1] : charactor count of line.
[2] : pixels of width.
[3] : pixels of height.
"""
def getTermSize(ptsPath) :
termSize=struct.unpack(
'HHHH',
fcntl.ioctl(
open(ptsPath),
termios.TIOCGWINSZ,
'\0' * 8))
return termSize
if __name__ == "__main__" :
if len(sys.argv) != 2 :
print(__USEAGE__)
exit()
if sys.argv[1] == "--help"\
or sys.argv[1] == "-h" :
print(__USEAGE__)
exit()
termSize = getTermSize(sys.argv[1])
print(termSize[0], termSize[1], termSize[2], termSize[3])