Set and restore IXON tty settings

This commit is contained in:
Mark Qvist 2022-07-04 12:48:24 +02:00
parent 1b1558c769
commit 27dc1b5fb5
3 changed files with 28 additions and 43 deletions

View File

@ -32,6 +32,15 @@ class NomadNetworkApp:
RNS.log("Saving directory...", RNS.LOG_VERBOSE) RNS.log("Saving directory...", RNS.LOG_VERBOSE)
self.directory.save_to_disk() self.directory.save_to_disk()
if hasattr(self.ui, "restore_ixon"):
if self.ui.restore_ixon:
try:
os.system("stty ixon")
except Exception as e:
RNS.log("Could not restore flow control sequences. The contained exception was: "+str(e), RNS.LOG_WARNING)
RNS.log("Nomad Network Client exiting now", RNS.LOG_VERBOSE) RNS.log("Nomad Network Client exiting now", RNS.LOG_VERBOSE)
def exception_handler(self, e_type, e_value, e_traceback): def exception_handler(self, e_type, e_value, e_traceback):

View File

@ -127,6 +127,21 @@ GLYPHS = {
class TextUI: class TextUI:
def __init__(self): def __init__(self):
self.restore_ixon = False
try:
rval = os.system("stty -a | grep \"\\-ixon\"")
if rval == 0:
pass
else:
os.system("stty -ixon")
self.restore_ixon = True
except Exception as e:
RNS.log("Could not configure terminal flow control sequences, some keybindings may not work.", RNS.LOG_WARNING)
RNS.log("The contained exception was: "+str(e))
self.app = NomadNetworkApp.get_shared_instance() self.app = NomadNetworkApp.get_shared_instance()
self.app.ui = self self.app.ui = self
self.loop = None self.loop = None
@ -164,7 +179,7 @@ class TextUI:
else: else:
initial_widget = self.main_display.widget initial_widget = self.main_display.widget
self.loop = urwid.MainLoop(initial_widget, screen=self.screen, handle_mouse=mouse_enabled) self.loop = urwid.MainLoop(initial_widget, unhandled_input=self.unhandled_input, screen=self.screen, handle_mouse=mouse_enabled)
if intro_timeout > 0: if intro_timeout > 0:
self.loop.set_alarm_in(intro_timeout, self.display_main) self.loop.set_alarm_in(intro_timeout, self.display_main)
@ -194,5 +209,8 @@ class TextUI:
self.screen.set_terminal_properties(colormode) self.screen.set_terminal_properties(colormode)
self.screen.reset_default_terminal_palette() self.screen.reset_default_terminal_palette()
def unhandled_input(self, key):
pass
def display_main(self, loop, user_data): def display_main(self, loop, user_data):
self.loop.widget = self.main_display.widget self.loop.widget = self.main_display.widget

View File

@ -17,45 +17,3 @@ class IntroDisplay():
self.widget = urwid.Filler(intro) self.widget = urwid.Filler(intro)
class DemoDisplay():
def __init__(self, ui, app):
import urwid
def color_mono(btn):
ui.set_colormode(nomadnet.ui.COLORMODE_MONO)
def color_16(btn):
ui.set_colormode(nomadnet.ui.COLORMODE_16)
def color_88(btn):
ui.set_colormode(nomadnet.ui.COLORMODE_88)
def color_8bit(btn):
ui.set_colormode(nomadnet.ui.COLORMODE_256)
def color_true(btn):
ui.set_colormode(nomadnet.ui.COLORMODE_TRUE)
# pile = urwid.Pile([
# urwid.Text(("heading", "This is a heading")),
# urwid.Text(("body_text", "Hello World \U0001F332")),
# urwid.Button(("buttons", "Monochrome"), color_mono),
# urwid.Button(("buttons", "16 color"), color_16),
# urwid.Button(("buttons", "88 color"), color_88),
# urwid.Button(("buttons", "256 color"), color_8bit),
# urwid.Button(("buttons", "True color"), color_true),
# ])
gf = urwid.GridFlow([
urwid.Text(("heading", "This is a heading")),
urwid.Text(("body_text", "Hello World \U0001F332")),
urwid.Button(("buttons", "Monochrome"), color_mono),
urwid.Button(("buttons", "16 color"), color_16),
urwid.Button(("buttons", "88 color"), color_88),
urwid.Button(("buttons", "256 color"), color_8bit),
urwid.Button(("buttons", "True color"), color_true),
], cell_width=20, h_sep=0, v_sep=0, align="left")
self.widget = urwid.Filler(urwid.Padding((urwid.Text("Test"),urwid.Text("Test 2"))), 'top')
#self.widget = urwid.Filler(pile, 'top')