foxes
This commit is contained in:
35
ui.py
35
ui.py
@ -27,10 +27,12 @@ class CursesHandler(logging.Handler):
|
|||||||
fs = "%s\n"
|
fs = "%s\n"
|
||||||
try:
|
try:
|
||||||
print_colored(self.window, fs % msg, 0)
|
print_colored(self.window, fs % msg, 0)
|
||||||
self.window.refresh()
|
self.window.noutrefresh()
|
||||||
|
curses.doupdate()
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
print_colored(self.window, fs % msg.encode("UTF-8"), 0)
|
print_colored(self.window, fs % msg.encode("UTF-8"), 0)
|
||||||
self.window.refresh()
|
self.window.noutrefresh()
|
||||||
|
curses.doupdate()
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
@ -69,8 +71,6 @@ def print_colored(window, message, attributes=0):
|
|||||||
else:
|
else:
|
||||||
window.addch(ch, curses.color_pair(color) | (curses.A_BOLD if bold else 0) | attributes)
|
window.addch(ch, curses.color_pair(color) | (curses.A_BOLD if bold else 0) | attributes)
|
||||||
|
|
||||||
window.refresh()
|
|
||||||
|
|
||||||
class UIManager:
|
class UIManager:
|
||||||
"""Manages curses windows and display"""
|
"""Manages curses windows and display"""
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ class UIManager:
|
|||||||
temp_history_index = -1
|
temp_history_index = -1
|
||||||
temp_input = ""
|
temp_input = ""
|
||||||
window.clear()
|
window.clear()
|
||||||
window.refresh()
|
window.noutrefresh()
|
||||||
|
|
||||||
# Arrow UP - previous command
|
# Arrow UP - previous command
|
||||||
elif key == curses.KEY_UP:
|
elif key == curses.KEY_UP:
|
||||||
@ -209,7 +209,7 @@ class UIManager:
|
|||||||
cursor_pos = len(current_input)
|
cursor_pos = len(current_input)
|
||||||
window.clear()
|
window.clear()
|
||||||
window.addstr(0, 0, current_input)
|
window.addstr(0, 0, current_input)
|
||||||
window.refresh()
|
window.noutrefresh()
|
||||||
|
|
||||||
# Arrow DOWN - next command
|
# Arrow DOWN - next command
|
||||||
elif key == curses.KEY_DOWN:
|
elif key == curses.KEY_DOWN:
|
||||||
@ -226,29 +226,21 @@ class UIManager:
|
|||||||
cursor_pos = len(current_input)
|
cursor_pos = len(current_input)
|
||||||
window.clear()
|
window.clear()
|
||||||
window.addstr(0, 0, current_input)
|
window.addstr(0, 0, current_input)
|
||||||
window.refresh()
|
window.noutrefresh()
|
||||||
|
|
||||||
# Arrow LEFT - move cursor left
|
# Arrow LEFT - move cursor left
|
||||||
elif key == curses.KEY_LEFT:
|
elif key == curses.KEY_LEFT:
|
||||||
if cursor_pos > 0:
|
if cursor_pos > 0:
|
||||||
cursor_pos -= 1
|
cursor_pos -= 1
|
||||||
window.move(0, cursor_pos)
|
window.move(0, cursor_pos)
|
||||||
window.refresh()
|
window.noutrefresh()
|
||||||
|
|
||||||
# Arrow RIGHT - move cursor right
|
# Arrow RIGHT - move cursor right
|
||||||
elif key == curses.KEY_RIGHT:
|
elif key == curses.KEY_RIGHT:
|
||||||
if cursor_pos < len(current_input):
|
if cursor_pos < len(current_input):
|
||||||
cursor_pos += 1
|
cursor_pos += 1
|
||||||
window.move(0, cursor_pos)
|
window.move(0, cursor_pos)
|
||||||
window.refresh()
|
window.noutrefresh()
|
||||||
|
|
||||||
# ESC - cancel quit confirmation
|
|
||||||
elif key == 27:
|
|
||||||
if quit_confirm:
|
|
||||||
quit_confirm = False
|
|
||||||
window.clear()
|
|
||||||
window.refresh()
|
|
||||||
|
|
||||||
|
|
||||||
# Backspace
|
# Backspace
|
||||||
elif key in (curses.KEY_BACKSPACE, 127, 8):
|
elif key in (curses.KEY_BACKSPACE, 127, 8):
|
||||||
@ -259,7 +251,7 @@ class UIManager:
|
|||||||
window.clear()
|
window.clear()
|
||||||
window.addstr(0, 0, current_input)
|
window.addstr(0, 0, current_input)
|
||||||
window.move(0, cursor_pos)
|
window.move(0, cursor_pos)
|
||||||
window.refresh()
|
window.noutrefresh()
|
||||||
|
|
||||||
# Regular character
|
# Regular character
|
||||||
elif 32 <= key <= 126:
|
elif 32 <= key <= 126:
|
||||||
@ -270,7 +262,9 @@ class UIManager:
|
|||||||
window.clear()
|
window.clear()
|
||||||
window.addstr(0, 0, current_input)
|
window.addstr(0, 0, current_input)
|
||||||
window.move(0, cursor_pos)
|
window.move(0, cursor_pos)
|
||||||
window.refresh()
|
window.noutrefresh()
|
||||||
|
|
||||||
|
curses.doupdate()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import logging
|
import logging
|
||||||
@ -294,6 +288,7 @@ class UIManager:
|
|||||||
"""Print formatted message to output window"""
|
"""Print formatted message to output window"""
|
||||||
y, x = curses.getsyx()
|
y, x = curses.getsyx()
|
||||||
print_colored(self.output_window, message, attributes)
|
print_colored(self.output_window, message, attributes)
|
||||||
|
self.output_window.noutrefresh()
|
||||||
curses.setsyx(y, x)
|
curses.setsyx(y, x)
|
||||||
curses.doupdate()
|
curses.doupdate()
|
||||||
|
|
||||||
@ -367,4 +362,4 @@ class UIManager:
|
|||||||
separator = "^7" + "═" * (max_x - 1) + "^7"
|
separator = "^7" + "═" * (max_x - 1) + "^7"
|
||||||
print_colored(self.info_window, separator, 0)
|
print_colored(self.info_window, separator, 0)
|
||||||
|
|
||||||
self.info_window.refresh()
|
self.info_window.noutrefresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user