[pve-devel] [PATCH installer 4/7] tui: install progress: split out prompt logic into own function

Christoph Heiss c.heiss at proxmox.com
Wed Jul 26 16:03:58 CEST 2023


No functional changes.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 .../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 bd27628..3046a26 100644
--- a/proxmox-tui-installer/src/views/install_progress.rs
+++ b/proxmox-tui-installer/src/views/install_progress.rs
@@ -80,6 +80,27 @@ fn spawn_low_level_installer() -> io::Result<process::Child> {
         .spawn()
 }
 
+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);
+            }
+        }),
+    );
+}
+
 fn prepare_for_reboot(siv: &mut Cursive, success: bool, msg: &str) {
     let title = if success { "Success" } else { "Failure" };
 
@@ -159,26 +180,7 @@ fn progress_task(
                 })),
                 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| show_prompt(siv, &s, writer))
                 }),
                 UiMessage::Progress(ratio, s) => {
                     counter.set(ratio);
-- 
2.41.0






More information about the pve-devel mailing list