From 898fadae0e9bf9d0eb46abf286a888d791bdaf96 Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 12 Jan 2016 09:47:24 -0500 Subject: perfectionist's job is never done - fixed the console prompt redraw when an async event occurs so it looks nice --- .../client/trex_stateless_client.py | 19 +++++++++++++++---- .../trex_control_plane/console/trex_console.py | 5 +++++ 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'scripts/automation/trex_control_plane') diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py index 42d5031e..c7a9e533 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -69,7 +69,7 @@ class CTRexStatelessClient(object): self.session_id = random.getrandbits(32) self.read_only = False self.connected = False - + self.prompt_redraw_cb = None # returns the port object @@ -99,7 +99,7 @@ class CTRexStatelessClient(object): self.events.append("{:<10} - {:^8} - {:}".format(st, prefix, format_text(msg, 'bold'))) if show: - self.prn_func(format_text("\n{:^8} - {:}".format(prefix, format_text(msg, 'bold')))) + self.prn_func(format_text("\n{:^8} - {:}".format(prefix, format_text(msg, 'bold'))), redraw_console = True) def handle_async_stats_update(self, dump_data): @@ -475,10 +475,21 @@ class CTRexStatelessClient(object): def get_verbose (self): return self.verbose - def prn_func (self, msg, level = VERBOSE_REGULAR): - if self.check_verbose(level): + def prn_func (self, msg, level = VERBOSE_REGULAR, redraw_console = False): + if not self.check_verbose(level): + return + + if redraw_console and self.prompt_redraw_cb: + print "\n" + msg + "\n" + self.prompt_redraw_cb() + else: print msg + sys.stdout.flush() + + def set_prompt_redraw_cb(self, cb): + self.prompt_redraw_cb = cb + ############# server actions ################ # ping server diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 49d58fe0..3e9dec47 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -116,6 +116,8 @@ class TRexConsole(TRexGeneralCmd): def __init__(self, stateless_client, verbose=False): self.stateless_client = stateless_client + self.stateless_client.set_prompt_redraw_cb(self.prompt_redraw) + TRexGeneralCmd.__init__(self) self.tui = trex_tui.TrexTUI(stateless_client) @@ -130,6 +132,9 @@ class TRexConsole(TRexGeneralCmd): ################### internal section ######################## + def prompt_redraw (self): + sys.stdout.write(self.prompt) + def verify_connected(f): @wraps(f) def wrap(*args): -- cgit 1.2.3-korg