Skip to content

Commit

Permalink
Print header properly when terminal resizes
Browse files Browse the repository at this point in the history
Added a handler for SIGWINCH, so that one header
is printed per screen even when the terminal resizes.

Signed-off-by: Isaac Huang <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #2847
  • Loading branch information
huangheintel authored and behlendorf committed Nov 14, 2014
1 parent 1c49ac5 commit a82db4e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cmd/arcstat/arcstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import copy

from decimal import Decimal
from signal import signal, SIGINT, SIG_DFL
from signal import signal, SIGINT, SIGWINCH, SIG_DFL

cols = {
# HDR: [Size, Scale, Description]
Expand Down Expand Up @@ -239,11 +239,21 @@ def get_terminal_lines():
except:
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():
global sint
global count
global hdr
global hdr_intr
global xhdr
global opfile
global sep
Expand Down Expand Up @@ -313,9 +323,7 @@ def init():
if xflag:
hdr = xhdr

lines = get_terminal_lines()
if lines:
hdr_intr = lines - 3
update_hdr_intr()

# check if L2ARC exists
snap_stats()
Expand Down Expand Up @@ -426,6 +434,7 @@ def main():
count_flag = 1

signal(SIGINT, SIG_DFL)
signal(SIGWINCH, resize_handler)
while True:
if i == 0:
print_header()
Expand All @@ -439,7 +448,7 @@ def main():
break
count -= 1

i = 0 if i == hdr_intr else i + 1
i = 0 if i >= hdr_intr else i + 1
time.sleep(sint)

if out:
Expand Down

0 comments on commit a82db4e

Please sign in to comment.