-
Notifications
You must be signed in to change notification settings - Fork 0
/
resize.py
49 lines (42 loc) · 1.9 KB
/
resize.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
47
48
49
# Resize ExtremeXOS (EXOS) CLI to current remote terminal dimensions.
# Copyright (C) 2016 Erik Auerswald <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
# source for code inside terminal_size() function taken from a Stack
# Overflow answer by "pascal" and modified by "mic_e":
# http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python/3010495#3010495
# (short link: https://stackoverflow.com/a/3010495)
# answer is from 2010, thus licensed under CC BY-SA 2.5 by Stack Exchange Inc.
def terminal_size():
import fcntl, termios, struct
h, w, hp, wp = struct.unpack('HHHH',
fcntl.ioctl(1, termios.TIOCGWINSZ,
struct.pack('HHHH', 0, 0, 0, 0)))
return w, h
# -----------------------------------------------------------------------------
# this only works in remote sessions (SSH, Telnet), not via serial console
columns, lines = terminal_size()
# columns must be in the range [80, 256]
if columns < 80:
columns = 80
elif columns > 256:
columns = 256
# lines must be in the range [24, 128]
if lines < 24:
lines = 24
elif lines > 128:
lines = 128
# the exsh module is available on ExtremeXOS switches that provide Python
import exsh
exsh.clicmd("configure cli columns {0}".format(columns))
exsh.clicmd("configure cli lines {0}".format(lines))