From 43f414da1fbd06c981e77481e0cd3032427ce04f Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 23 Aug 2019 11:17:02 +1200 Subject: [PATCH] add a way to suspend the subiquity UI and run some other command This will be used for the drop to shell functionality and also to allow viewing an error report before we submit it to daisy. It is almost but not quite surprisingly easy (I added a long-ish comment about the difficulties). --- subiquitycore/core.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/subiquitycore/core.py b/subiquitycore/core.py index d6fbe97d..f49f4361 100644 --- a/subiquitycore/core.py +++ b/subiquitycore/core.py @@ -19,6 +19,7 @@ import json import logging import os import struct +import subprocess import sys import tty @@ -297,6 +298,28 @@ class Application: os.write(pipe, b'x') fut.add_done_callback(in_random_thread) + def run_command_in_foreground(self, cmd, **kw): + screen = self.loop.screen + + def run(): + subprocess.run(cmd, **kw) + + def restore(fut): + screen.start() + # Calling screen.start() sends the INPUT_DESCRIPTORS_CHANGED + # signal. This calls _reset_input_descriptors() which calls + # unhook_event_loop / hook_event_loop on the screen. But this all + # happens before _started is set on the screen, so hook_event_loop + # does not actually do anything -- and we end up not listening to + # stdin, obviously a defective situation for a console + # application. So send it again now the screen is started... + urwid.emit_signal( + screen, urwid.display_common.INPUT_DESCRIPTORS_CHANGED) + tty.setraw(0) + + screen.stop() + self.run_in_bg(run, restore) + def _connect_base_signals(self): """ Connect signals used in the core controller """