Improved remote tui error handling
This commit is contained in:
parent
e4fe1cedb7
commit
0ff1af3ee4
1 changed files with 24 additions and 6 deletions
30
nxbt/tui.py
30
nxbt/tui.py
|
|
@ -264,13 +264,28 @@ class InputTUI():
|
||||||
"9": "ZR",
|
"9": "ZR",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, reconnect_target=None, debug=False, logfile=False):
|
def __init__(self, reconnect_target=None, debug=False, logfile=False, force_remote=False):
|
||||||
|
|
||||||
self.reconnect_target = reconnect_target
|
self.reconnect_target = reconnect_target
|
||||||
self.term = Terminal()
|
self.term = Terminal()
|
||||||
self.remote_connection = self.detect_remote_connection()
|
if force_remote:
|
||||||
|
self.remote_connection = True
|
||||||
|
else:
|
||||||
|
self.remote_connection = self.detect_remote_connection()
|
||||||
self.controller = ControllerTUI(self.term)
|
self.controller = ControllerTUI(self.term)
|
||||||
|
|
||||||
|
# Check if direct connection will fail
|
||||||
|
if not self.remote_connection:
|
||||||
|
try:
|
||||||
|
from pynput import keyboard
|
||||||
|
except ImportError as e:
|
||||||
|
print("Unable to import pynput for direct input.")
|
||||||
|
print("If you're accessing NXBT over a remote shell, ", end="")
|
||||||
|
print("please use the 'remote_tui' option instead of 'tui'.")
|
||||||
|
print("The original pynput import is displayed below:\n")
|
||||||
|
print(e)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.logfile = logfile
|
self.logfile = logfile
|
||||||
|
|
||||||
|
|
@ -391,7 +406,7 @@ class InputTUI():
|
||||||
if len(term._keyboard_buf) > 1:
|
if len(term._keyboard_buf) > 1:
|
||||||
term._keyboard_buf = deque([term._keyboard_buf.pop()])
|
term._keyboard_buf = deque([term._keyboard_buf.pop()])
|
||||||
|
|
||||||
inp = term.inkey(1/60)
|
inp = term.inkey(1/66)
|
||||||
|
|
||||||
pressed_key = None
|
pressed_key = None
|
||||||
if inp.is_sequence:
|
if inp.is_sequence:
|
||||||
|
|
@ -426,9 +441,6 @@ class InputTUI():
|
||||||
self.check_for_disconnect(term)
|
self.check_for_disconnect(term)
|
||||||
|
|
||||||
def direct_input_loop(self, term):
|
def direct_input_loop(self, term):
|
||||||
|
|
||||||
# pynput must be imported here since earlier imports
|
|
||||||
# will cause errors on remote connections
|
|
||||||
from pynput import keyboard
|
from pynput import keyboard
|
||||||
|
|
||||||
self.controller.toggle_auto_keypress_deactivation(False)
|
self.controller.toggle_auto_keypress_deactivation(False)
|
||||||
|
|
@ -610,6 +622,12 @@ class InputTUI():
|
||||||
print(term.bold_black_on_red(term.center(state.title())))
|
print(term.bold_black_on_red(term.center(state.title())))
|
||||||
print(term.bold_black_on_red(term.center("")))
|
print(term.bold_black_on_red(term.center("")))
|
||||||
|
|
||||||
|
if state == 'crashed':
|
||||||
|
time.sleep(3)
|
||||||
|
term.clear()
|
||||||
|
errors = self.nx.state[self.controller_index]["errors"]
|
||||||
|
raise ConnectionError(errors)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
inp = term.inkey(1/30)
|
inp = term.inkey(1/30)
|
||||||
if inp == chr(113):
|
if inp == chr(113):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue