From 86f748c59909aa9bc5e0b98890674f9c36d45562 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 4 Jun 2023 18:08:59 -0700 Subject: [PATCH] Clear ddrescue pane when resizing This replaces the clear every 30s/60s/etc. It's only enabled while ddrescue is running to prevent clearing warning messages if printed. --- scripts/wk/clone/ddrescue.py | 5 ++--- scripts/wk/ui/tmux.py | 10 +++++++++- scripts/wk/ui/tui.py | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/wk/clone/ddrescue.py b/scripts/wk/clone/ddrescue.py index afbc2fc0..e64ed94a 100644 --- a/scripts/wk/clone/ddrescue.py +++ b/scripts/wk/clone/ddrescue.py @@ -1953,6 +1953,7 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True) -> None: poweroff_source_after_idle = True state.update_progress_pane('Active') state.ui.clear_current_pane() + state.ui.clear_on_resize = True warning_message = '' def _poweroff_source_drive(idle_minutes) -> None: @@ -2030,9 +2031,6 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True) -> None: exe.stop_process(proc) cli.print_error(warning_message) break - - # Clear ddrescue pane - state.ui.clear_current_pane() _i += 1 # Update progress @@ -2062,6 +2060,7 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True) -> None: # NOTE: Using 'Active' here to avoid flickering between block pairs block_pair.update_progress(pass_name) state.update_progress_pane('Active') + state.ui.clear_on_resize = False # Check result if proc.poll(): diff --git a/scripts/wk/ui/tmux.py b/scripts/wk/ui/tmux.py index 45981264..14b89daf 100644 --- a/scripts/wk/ui/tmux.py +++ b/scripts/wk/ui/tmux.py @@ -40,7 +40,11 @@ def clear_pane(pane_id: str | None = None) -> None: run_program(cmd, check=False) -def fix_layout(layout: dict[str, dict[str, Any]], forced: bool = False) -> None: +def fix_layout( + layout: dict[str, dict[str, Any]], + clear_on_resize: bool = False, + forced: bool = False, + ) -> None: """Fix pane sizes based on layout.""" resize_kwargs = [] @@ -49,6 +53,10 @@ def fix_layout(layout: dict[str, dict[str, Any]], forced: bool = False) -> None: # Layout should be fine return + # Clear current pane if needed + if clear_on_resize: + clear_pane() + # Remove closed panes for data in layout.values(): data['Panes'] = [pane for pane in data['Panes'] if poll_pane(pane)] diff --git a/scripts/wk/ui/tui.py b/scripts/wk/ui/tui.py index 80960ea8..465b67e5 100644 --- a/scripts/wk/ui/tui.py +++ b/scripts/wk/ui/tui.py @@ -31,6 +31,7 @@ TMUX_LAYOUT = { # NOTE: This needs to be in order from top to bottom class TUI(): """Object for tracking TUI elements.""" def __init__(self, title_text: str | None = None): + self.clear_on_resize = False self.layout: dict[str, dict[str, Any]] = deepcopy(TMUX_LAYOUT) self.side_width: int = TMUX_SIDE_WIDTH self.title_text: str = title_text if title_text else 'Title Text' @@ -159,7 +160,7 @@ class TUI(): def fix_layout(self, forced: bool = True) -> None: """Fix tmux layout based on self.layout.""" try: - tmux.fix_layout(self.layout, forced=forced) + tmux.fix_layout(self.layout, clear_on_resize=self.clear_on_resize, forced=forced) except RuntimeError: # Assuming self.panes changed while running pass