[pve-devel] [PATCH installer v2 5/8] tui: install_progress: split out prompt logic into own function

Christoph Heiss c.heiss at proxmox.com
Fri Nov 10 15:17:23 CET 2023


No functional changes.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
Changes v1 -> v2:
  * use static member function instead of top-level function

 .../src/views/install_progress.rs             | 42 ++++++++++---------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs
index 9f4b8c4..fceb785 100644
--- a/proxmox-tui-installer/src/views/install_progress.rs
+++ b/proxmox-tui-installer/src/views/install_progress.rs
@@ -106,26 +106,7 @@ impl InstallProgressView {
                     })),
                     UiMessage::Prompt(s) => cb_sink.send({
                         let writer = writer.clone();
-                        Box::new(move |siv| {
-                            yes_no_dialog(
-                                siv,
-                                "Prompt",
-                                &s,
-                                Box::new({
-                                    let writer = writer.clone();
-                                    move |_| {
-                                        if let Ok(mut writer) = writer.lock() {
-                                            let _ = writeln!(writer, "ok");
-                                        }
-                                    }
-                                }),
-                                Box::new(move |_| {
-                                    if let Ok(mut writer) = writer.lock() {
-                                        let _ = writeln!(writer);
-                                    }
-                                }),
-                            );
-                        })
+                        Box::new(move |siv| Self::show_prompt(siv, &s, writer))
                     }),
                     UiMessage::Progress(ratio, s) => {
                         counter.set(ratio);
@@ -186,6 +167,27 @@ impl InstallProgressView {
             });
         }
     }
+
+    fn show_prompt<W: Write + 'static>(siv: &mut Cursive, text: &str, writer: Arc<Mutex<W>>) {
+        yes_no_dialog(
+            siv,
+            "Prompt",
+            text,
+            Box::new({
+                let writer = writer.clone();
+                move |_| {
+                    if let Ok(mut writer) = writer.lock() {
+                        let _ = writeln!(writer, "ok");
+                    }
+                }
+            }),
+            Box::new(move |_| {
+                if let Ok(mut writer) = writer.lock() {
+                    let _ = writeln!(writer);
+                }
+            }),
+        );
+    }
 }

 impl ViewWrapper for InstallProgressView {
--
2.42.0






More information about the pve-devel mailing list