aboutsummaryrefslogtreecommitdiff
path: root/app/ui/taskview.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/ui/taskview.py')
-rw-r--r--app/ui/taskview.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/app/ui/taskview.py b/app/ui/taskview.py
index 7f8134b..ea72a86 100644
--- a/app/ui/taskview.py
+++ b/app/ui/taskview.py
@@ -143,13 +143,17 @@ def _lane_step_mark(current: Optional[int],
return "[ ]", "dim"
-def run_steps(scr, title: str, steps: List[TaskStep]) -> int:
+def run_steps(scr, title: str, steps: List[TaskStep],
+ wait_on_finish: bool = True) -> int:
"""Run STEPS in order inside the curses screen; return the first bad rc.
Returns 0 when every step succeeded, otherwise the first non-zero exit
- code (a cancelled run returns a non-zero code too).
+ code (a cancelled run returns a non-zero code too). With WAIT_ON_FINISH
+ False the view returns to the caller as soon as the run reaches a
+ terminal phase instead of waiting for a key press (used by the hub's
+ start/stop actions, which land straight back on the menu).
"""
- view = TaskView(scr, title, steps)
+ view = TaskView(scr, title, steps, wait_on_finish=wait_on_finish)
return view.run()
@@ -192,12 +196,14 @@ class TaskView:
"""Draws and drives one list of setup steps; see the module docstring."""
def __init__(self, scr, title: str, steps: List[TaskStep],
- clock: Callable[[], float] = time.time):
+ clock: Callable[[], float] = time.time,
+ wait_on_finish: bool = True):
import curses
self.curses = curses
self.scr = scr
self.title = title
self.steps = steps
+ self.wait_on_finish = wait_on_finish
self.theme = tui._ensure_theme(curses)
self._clock = clock
# -- state -----------------------------------------------------
@@ -330,6 +336,8 @@ class TaskView:
while True:
self._drain()
self.render()
+ if self.phase in _TERMINAL and not self.wait_on_finish:
+ return self._result_rc()
key = self._get_key()
if key is None:
continue
@@ -458,14 +466,15 @@ class TaskView:
break
# -- footer ----------------------------------------------------
+ suffix = "" if not self.wait_on_finish else " — press any key to return"
if self.phase == "done":
- footer = "completed — press any key to return"
+ footer = "completed" + suffix
kind = "ok"
elif self.phase == "cancelled":
- footer = "cancelled — press any key to return"
+ footer = "cancelled" + suffix
kind = "warn"
elif self.phase == "error":
- footer = "finished with errors — press any key to return"
+ footer = "finished with errors" + suffix
kind = "err"
elif self.cancelling:
footer = "cancelling..."