From 7ad87d4d22ce0cdaeaee947fe3fc7b3d7353f212 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Tue, 26 Oct 2021 11:12:14 +0200 Subject: [PATCH] Auto-resize stats table when terminal window is resized. --- locust/stats.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/locust/stats.py b/locust/stats.py index 31f024f79c..ef14e37fe0 100644 --- a/locust/stats.py +++ b/locust/stats.py @@ -6,7 +6,7 @@ from itertools import chain import os import csv - +import signal import gevent from .exception import StopUser, CatchResponseError @@ -20,6 +20,18 @@ STATS_NAME_WIDTH = max(min(os.get_terminal_size()[0] - 80, 80), 0) except OSError: # not a real terminal STATS_NAME_WIDTH = 80 + +STATS_AUTORESIZE = True # overwrite this if you dont want auto resize while running + + +def resize_handler(signum, frame): + global STATS_NAME_WIDTH + if STATS_AUTORESIZE: + STATS_NAME_WIDTH = max(min(os.get_terminal_size()[0] - 80, 80), 0) + + +signal.signal(signal.SIGWINCH, resize_handler) + STATS_TYPE_WIDTH = 8 """Default interval for how frequently results are written to console."""