mirror of https://github.com/nicolargo/glances.git
Replace the wait method by a default timeout on getch
This commit is contained in:
parent
27230bfb5c
commit
cab0e868ae
Binary file not shown.
|
Before Width: | Height: | Size: 318 KiB After Width: | Height: | Size: 321 KiB |
|
|
@ -302,20 +302,26 @@ class _GlancesCurses(object):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
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)
|
||||||
|
#
|
||||||
|
# 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):
|
def get_key(self, window):
|
||||||
# Catch ESC key AND numlock key (issue #163)
|
# @TODO: Check issue #163
|
||||||
keycode = [0, 0]
|
ret = window.getch()
|
||||||
keycode[0] = window.getch()
|
logger.debug("Keypressed (code: %s)" % ret)
|
||||||
keycode[1] = window.getch()
|
return ret
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
def __catch_key(self, return_to_browser=False):
|
def __catch_key(self, return_to_browser=False):
|
||||||
# Catch the pressed key
|
# Catch the pressed key
|
||||||
|
|
@ -945,8 +951,6 @@ class _GlancesCurses(object):
|
||||||
return_to_browser=False):
|
return_to_browser=False):
|
||||||
"""Update the screen.
|
"""Update the screen.
|
||||||
|
|
||||||
Catch key every 100 ms.
|
|
||||||
|
|
||||||
INPUT
|
INPUT
|
||||||
stats: Stats database to display
|
stats: Stats database to display
|
||||||
duration: duration of the loop
|
duration: duration of the loop
|
||||||
|
|
@ -958,7 +962,7 @@ class _GlancesCurses(object):
|
||||||
True: Do not exist, return to the browser list
|
True: Do not exist, return to the browser list
|
||||||
False: Exit and return to the shell
|
False: Exit and return to the shell
|
||||||
|
|
||||||
OUPUT
|
OUTPUT
|
||||||
True: Exit key has been pressed
|
True: Exit key has been pressed
|
||||||
False: Others cases...
|
False: Others cases...
|
||||||
"""
|
"""
|
||||||
|
|
@ -968,12 +972,14 @@ class _GlancesCurses(object):
|
||||||
# If the duration is < 0 (update + export time > refresh_time)
|
# If the duration is < 0 (update + export time > refresh_time)
|
||||||
# Then display the interface and log a message
|
# Then display the interface and log a message
|
||||||
if duration <= 0:
|
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
|
duration = 0.1
|
||||||
|
|
||||||
# Wait
|
# Wait duration (in s) time
|
||||||
exitkey = False
|
exitkey = False
|
||||||
countdown = Timer(duration)
|
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:
|
while not countdown.finished() and not exitkey:
|
||||||
# Getkey
|
# Getkey
|
||||||
pressedkey = self.__catch_key(return_to_browser=return_to_browser)
|
pressedkey = self.__catch_key(return_to_browser=return_to_browser)
|
||||||
|
|
@ -982,8 +988,6 @@ class _GlancesCurses(object):
|
||||||
if not exitkey and pressedkey > -1:
|
if not exitkey and pressedkey > -1:
|
||||||
# Redraw display
|
# Redraw display
|
||||||
self.flush(stats, cs_status=cs_status)
|
self.flush(stats, cs_status=cs_status)
|
||||||
# Wait 100ms...
|
|
||||||
self.wait()
|
|
||||||
|
|
||||||
return exitkey
|
return exitkey
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue