summaryrefslogtreecommitdiffstats
path: root/glances/outputs/glances_curses.py
diff options
context:
space:
mode:
Diffstat (limited to 'glances/outputs/glances_curses.py')
-rw-r--r--glances/outputs/glances_curses.py67
1 files changed, 38 insertions, 29 deletions
diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py
index 59c309e8..06abba7c 100644
--- a/glances/outputs/glances_curses.py
+++ b/glances/outputs/glances_curses.py
@@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
-# Copyright (C) 2018 Nicolargo <nicolas@nicolargo.com>
+# Copyright (C) 2019 Nicolargo <nicolas@nicolargo.com>
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
@@ -25,7 +25,7 @@ import sys
from glances.compat import u, itervalues
from glances.globals import MACOS, WINDOWS
from glances.logger import logger
-from glances.logs import glances_logs
+from glances.events import glances_events
from glances.processes import glances_processes
from glances.timer import Timer
@@ -181,10 +181,13 @@ class _GlancesCurses(object):
"""Init the Curses color layout."""
# Set curses options
- if hasattr(curses, 'start_color'):
- curses.start_color()
- if hasattr(curses, 'use_default_colors'):
- curses.use_default_colors()
+ try:
+ if hasattr(curses, 'start_color'):
+ curses.start_color()
+ if hasattr(curses, 'use_default_colors'):
+ curses.use_default_colors()
+ except Exception as e:
+ logger.warning('Error initializing terminal color ({})'.format(e))
# Init colors
if self.args.disable_bold:
@@ -302,20 +305,26 @@ class _GlancesCurses(object):
except Exception:
pass
- def get_key(self, window):
- # Catch ESC key AND numlock key (issue #163)
- keycode = [0, 0]
- keycode[0] = window.getch()
- keycode[1] = window.getch()
-
- if keycode != [-1, -1]:
- logger.debug("Keypressed (code: %s)" % keycode)
+ # def get_key(self, window):
+ # # Catch ESC key AND numlock key (issue #163)
+ # keycode = [0, 0]
+ # keycode[0] = window.getch()
+ # keycode[1] = window.getch()
+ #
+ # if keycode != [-1, -1]:
+ # logger.debug("Keypressed (code: %s)" % keycode)
+ #
+ # if keycode[0] == 27 and keycode[1] != -1:
+ # # Do not escape on specials keys
+ # return -1
+ # else:
+ # return keycode[0]
- if keycode[0] == 27 and keycode[1] != -1:
- # Do not escape on specials keys
- return -1
- else:
- return keycode[0]
+ def get_key(self, window):
+ # @TODO: Check issue #163
+ ret = window.getch()
+ logger.debug("Keypressed (code: %s)" % ret)
+ return ret
def __catch_key(self, return_to_browser=False):
# Catch the pressed key
@@ -375,10 +384,10 @@ class _GlancesCurses(object):
self.args.disable_folders = not self.args.disable_folders
elif self.pressedkey == ord('w'):
# 'w' > Delete finished warning logs
- glances_logs.clean()
+ glances_events.clean()
elif self.pressedkey == ord('x'):
# 'x' > Delete finished warning and critical logs
- glances_logs.clean(critical=True)
+ glances_events.clean(critical=True)
elif self.pressedkey == ord('z'):
# 'z' > Enable or disable processes
self.args.disable_process = not self.args.disable_process
@@ -595,7 +604,7 @@ class _GlancesCurses(object):
'Examples:\n' +
'- python\n' +
'- .*python.*\n' +
- '- \/usr\/lib.*\n' +
+ '- /usr/lib.*\n' +
'- name:.*nautilus.*\n' +
'- cmdline:.*glances.*\n' +
'- username:nicolargo\n' +
@@ -945,8 +954,6 @@ class _GlancesCurses(object):
return_to_browser=False):
"""Update the screen.
- Catch key every 100 ms.
-
INPUT
stats: Stats database to display
duration: duration of the loop
@@ -958,7 +965,7 @@ class _GlancesCurses(object):
True: Do not exist, return to the browser list
False: Exit and return to the shell
- OUPUT
+ OUTPUT
True: Exit key has been pressed
False: Others cases...
"""
@@ -968,12 +975,14 @@ class _GlancesCurses(object):
# If the duration is < 0 (update + export time > refresh_time)
# Then display the interface and log a message
if duration <= 0:
- logger.debug('Update and export time higher than refresh_time.')
+ logger.warning('Update and export time higher than refresh_time.')
duration = 0.1
- # Wait
+ # Wait duration (in s) time
exitkey = False
countdown = Timer(duration)
+ # Set the default timeout (in ms) for the getch method
+ self.term_window.timeout(int(duration * 1000))
while not countdown.finished() and not exitkey:
# Getkey
pressedkey = self.__catch_key(return_to_browser=return_to_browser)
@@ -982,8 +991,8 @@ class _GlancesCurses(object):
if not exitkey and pressedkey > -1:
# Redraw display
self.flush(stats, cs_status=cs_status)
- # Wait 100ms...
- self.wait()
+ # Overwrite the timeout with the countdown
+ self.term_window.timeout(int(countdown.get() * 1000))
return exitkey