Ensure everything fits on screen 79/66679/2
authorStephen Kitt <skitt@redhat.com>
Wed, 20 Dec 2017 20:26:11 +0000 (21:26 +0100)
committerJamo Luhrsen <jluhrsen@redhat.com>
Wed, 20 Dec 2017 22:08:08 +0000 (22:08 +0000)
Depending on the window size, the controller names and number and
names of shards, we might run off the end of the screen, which aborts
curses in a rather inelegant fashion. We reduce the column widths
until everything fits.

Change-Id: I2924c005646694368b2eaa220ae3b5f3313b5c6c
Signed-off-by: Stephen Kitt <skitt@redhat.com>
tools/clustering/cluster-monitor/monitor.py

index a36cd50273349874839c11d59e19619aa09d8e13..d255b5cd9a9482c3dfc1952d6bb5a73bde842b6c 100755 (executable)
@@ -36,6 +36,7 @@ import json
 import pycurl
 import string
 import argparse
+import math
 
 
 def rest_get(restURL, username, password):
@@ -136,6 +137,8 @@ curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLUE)
 curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_YELLOW)
 curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_YELLOW)
 
+(maxy, maxx) = stdscr.getmaxyx()
+
 key = -1
 controller_len = 0
 field_len = 0
@@ -173,6 +176,13 @@ while key != ord('q') and key != ord('Q'):
     else:
         field_len = max(field_len, 0)
 
+    # Ensure everything fits
+    if controller_len + 1 + (field_len + 1) * len(Shards) > maxx:
+        extra = controller_len + 1 + (field_len + 1) * len(Shards) - maxx
+        delta = int(math.ceil(float(extra) / (1 + len(Shards))))
+        controller_len -= delta
+        field_len -= delta
+
     # display controller and shard headers
     for row, controller in enumerate(controllers):
         stdscr.addstr(row + 1, 0, string.center(controller['name'], controller_len), curses.color_pair(1))