Print header properly when terminal resizes
Added a handler for SIGWINCH, so that one header is printed per screen even when the terminal resizes. Signed-off-by: Isaac Huang <he.huang@intel.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #2847
This commit is contained in:
parent
1c49ac575d
commit
a82db4e15f
|
@ -51,7 +51,7 @@ import re
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from signal import signal, SIGINT, SIG_DFL
|
from signal import signal, SIGINT, SIGWINCH, SIG_DFL
|
||||||
|
|
||||||
cols = {
|
cols = {
|
||||||
# HDR: [Size, Scale, Description]
|
# HDR: [Size, Scale, Description]
|
||||||
|
@ -239,11 +239,21 @@ def get_terminal_lines():
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def update_hdr_intr():
|
||||||
|
global hdr_intr
|
||||||
|
|
||||||
|
lines = get_terminal_lines()
|
||||||
|
if lines and lines > 3:
|
||||||
|
hdr_intr = lines - 3
|
||||||
|
|
||||||
|
def resize_handler(signum, frame):
|
||||||
|
update_hdr_intr()
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global sint
|
global sint
|
||||||
global count
|
global count
|
||||||
global hdr
|
global hdr
|
||||||
global hdr_intr
|
|
||||||
global xhdr
|
global xhdr
|
||||||
global opfile
|
global opfile
|
||||||
global sep
|
global sep
|
||||||
|
@ -313,9 +323,7 @@ def init():
|
||||||
if xflag:
|
if xflag:
|
||||||
hdr = xhdr
|
hdr = xhdr
|
||||||
|
|
||||||
lines = get_terminal_lines()
|
update_hdr_intr()
|
||||||
if lines:
|
|
||||||
hdr_intr = lines - 3
|
|
||||||
|
|
||||||
# check if L2ARC exists
|
# check if L2ARC exists
|
||||||
snap_stats()
|
snap_stats()
|
||||||
|
@ -426,6 +434,7 @@ def main():
|
||||||
count_flag = 1
|
count_flag = 1
|
||||||
|
|
||||||
signal(SIGINT, SIG_DFL)
|
signal(SIGINT, SIG_DFL)
|
||||||
|
signal(SIGWINCH, resize_handler)
|
||||||
while True:
|
while True:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
print_header()
|
print_header()
|
||||||
|
@ -439,7 +448,7 @@ def main():
|
||||||
break
|
break
|
||||||
count -= 1
|
count -= 1
|
||||||
|
|
||||||
i = 0 if i == hdr_intr else i + 1
|
i = 0 if i >= hdr_intr else i + 1
|
||||||
time.sleep(sint)
|
time.sleep(sint)
|
||||||
|
|
||||||
if out:
|
if out:
|
||||||
|
|
Loading…
Reference in New Issue