From 614441eba9bfb2c8c795343370642287f49d4845 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 2 Apr 2017 14:52:35 +0200 Subject: [PATCH] Use -> and <- arrows keys to switch between processing sort (issue #1075) --- NEWS | 4 ++++ glances/outputs/glances_curses.py | 33 +++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index c08687aa..693b0c0b 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ Glances Version 2 Version 2.9.2 ============= +Enhancements and new features: + + * Use -> and <- arrows keys to switch between processing sort (issue #1075) + Bugs corrected: * StatsD export prefix option is ignored (issue #1074) diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 3234775a..5416e5be 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -82,9 +82,11 @@ class _GlancesCurses(object): 'm': {'auto_sort': False, 'sort_key': 'memory_percent'}, 'p': {'auto_sort': False, 'sort_key': 'name'}, 't': {'auto_sort': False, 'sort_key': 'cpu_times'}, - 'u': {'auto_sort': False, 'sort_key': 'username'} + 'u': {'auto_sort': False, 'sort_key': 'username'}, } + _sort_loop = ['cpu_percent', 'memory_percent', 'username', 'cpu_times', 'io_counters', 'name'] + def __init__(self, config=None, args=None): # Init self.config = config @@ -130,7 +132,7 @@ class _GlancesCurses(object): self.args.reset_minmax_tag = False # Catch key pressed with non blocking mode - self.no_flash_cursor() + self.term_window.keypad(1) self.term_window.nodelay(1) self.pressedkey = -1 @@ -284,12 +286,6 @@ class _GlancesCurses(object): 'PASSWORD': curses.A_PROTECT } - def flash_cursor(self): - self.term_window.keypad(1) - - def no_flash_cursor(self): - self.term_window.keypad(0) - def set_cursor(self, value): """Configure the curse cursor apparence. @@ -395,10 +391,27 @@ class _GlancesCurses(object): glances_processes.disable() else: glances_processes.enable() + elif self.pressedkey == curses.KEY_LEFT: + # "<" (left arrow) navigation through process sort + setattr(glances_processes, 'auto_sort', False) + next_sort = (self.loop_position() - 1) % len(self._sort_loop) + glances_processes.sort_key = self._sort_loop[next_sort] + elif self.pressedkey == curses.KEY_RIGHT: + # ">" (right arrow) navigation through process sort + setattr(glances_processes, 'auto_sort', False) + next_sort = (self.loop_position() + 1) % len(self._sort_loop) + glances_processes.sort_key = self._sort_loop[next_sort] # Return the key code return self.pressedkey + def loop_position(self): + """Return the current sort in the loop""" + for i, v in enumerate(self._sort_loop): + if v == glances_processes.sort_key: + return i + return 0 + def disable_top(self): """Disable the top panel""" for p in ['quicklook', 'cpu', 'gpu', 'mem', 'memswap', 'load']: @@ -816,11 +829,11 @@ class _GlancesCurses(object): subpop.refresh() # Create the textbox inside the subwindows self.set_cursor(2) - self.flash_cursor() + self.term_window.keypad(1) textbox = GlancesTextbox(subpop, insert_mode=False) textbox.edit() self.set_cursor(0) - self.no_flash_cursor() + self.term_window.keypad(0) if textbox.gather() != '': logger.debug( "User enters the following string: %s" % textbox.gather())