]> granicus.if.org Git - zfs/commitdiff
Print header properly when terminal resizes
authorIsaac Huang <he.huang@intel.com>
Wed, 29 Oct 2014 03:35:10 +0000 (21:35 -0600)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 14 Nov 2014 23:32:30 +0000 (15:32 -0800)
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

cmd/arcstat/arcstat.py

index a5e0653b32c872086fb159c0fab97e3168d95d5f..b516cf285fdc76ee2e8f94035d9c9d757147efd3 100755 (executable)
@@ -51,7 +51,7 @@ import re
 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]
@@ -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
@@ -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()
@@ -426,6 +434,7 @@ def main():
         count_flag = 1
 
     signal(SIGINT, SIG_DFL)
+    signal(SIGWINCH, resize_handler)
     while True:
         if i == 0:
             print_header()
@@ -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: