public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 4/6] low-level: stdio: fix: make progress text properly optional
Date: Thu, 16 May 2024 15:39:34 +0200	[thread overview]
Message-ID: <20240516133945.1087246-5-c.heiss@proxmox.com> (raw)
In-Reply-To: <20240516133945.1087246-1-c.heiss@proxmox.com>

.. such that receivers can differentiate between these two cases more
clearly.

Sometimes, the `progress` sub does not get passed a text (on purpose!),
just updating the progress ratio. This would cause log messages to be
written out which could indicate missing text and look rather weird.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 Proxmox/UI/StdIO.pm                           |  8 +++++---
 .../src/bin/proxmox-auto-installer.rs         |  6 +++++-
 proxmox-installer-common/src/setup.rs         |  2 +-
 .../src/views/install_progress.rs             | 19 +++++++++++++------
 test/ui2-stdio.pl                             |  2 +-
 5 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/Proxmox/UI/StdIO.pm b/Proxmox/UI/StdIO.pm
index 2838fcb..ec9eac9 100644
--- a/Proxmox/UI/StdIO.pm
+++ b/Proxmox/UI/StdIO.pm
@@ -70,9 +70,11 @@ sub display_html {
 sub progress {
     my ($self, $ratio, $text) = @_;
 
-    $text = '' if !defined($text);
-
-    send_msg('progress', ratio => $ratio, text => $text);
+    if (defined($text)) {
+	send_msg('progress', ratio => $ratio, text => $text);
+    } else {
+	send_msg('progress', ratio => $ratio);
+    }
 }
 
 sub process_events {
diff --git a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
index 9fc328c..96a48bd 100644
--- a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
+++ b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
@@ -172,7 +172,11 @@ fn run_installation(
                 }
                 LowLevelMessage::Progress { ratio, text } => {
                     let percentage = ratio * 100.;
-                    info!("progress {percentage:>5.1} % - {text}");
+                    if let Some(text) = text {
+                        info!("progress {percentage:>5.1} % - {text}");
+                    } else {
+                        info!("progress {percentage:>5.1} %");
+                    }
                 }
                 LowLevelMessage::Finished { state, message } => {
                     if state == "err" {
diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index 0c62bc3..d145fc5 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -578,6 +578,6 @@ pub enum LowLevelMessage {
     },
     Progress {
         ratio: f32,
-        text: String,
+        text: Option<String>,
     },
 }
diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs
index 11b12f0..629472a 100644
--- a/proxmox-tui-installer/src/views/install_progress.rs
+++ b/proxmox-tui-installer/src/views/install_progress.rs
@@ -127,11 +127,18 @@ impl InstallProgressView {
                     }),
                     LowLevelMessage::Progress { ratio, text } => {
                         counter.set((ratio * 100.).floor() as usize);
-                        cb_sink.send(Box::new(move |siv| {
-                            siv.call_on_name(Self::PROGRESS_TEXT_VIEW_ID, |v: &mut TextView| {
-                                v.set_content(text);
-                            });
-                        }))
+                        if let Some(text) = text {
+                            cb_sink.send(Box::new(move |siv| {
+                                siv.call_on_name(
+                                    Self::PROGRESS_TEXT_VIEW_ID,
+                                    |v: &mut TextView| {
+                                        v.set_content(text);
+                                    },
+                                );
+                            }))
+                        } else {
+                            Ok(())
+                        }
                     }
                     LowLevelMessage::Finished { state, message } => {
                         counter.set(100);
@@ -300,7 +307,7 @@ mod tests {
                 next_msg(),
                 Some(LowLevelMessage::Progress {
                     ratio: (i as f32) / 1000.,
-                    text: format!("foo {i}"),
+                    text: Some(format!("foo {i}")),
                 }),
             );
         }
diff --git a/test/ui2-stdio.pl b/test/ui2-stdio.pl
index 01f323d..eebb5c9 100755
--- a/test/ui2-stdio.pl
+++ b/test/ui2-stdio.pl
@@ -81,7 +81,7 @@ if ($child_pid) {
 	'should get 20% done progress message');
 
     is_deeply(
-	$next_msg->(), { type => 'progress', ratio => 0.2, text => '' },
+	$next_msg->(), { type => 'progress', ratio => 0.2, },
 	'should get progress continuation message');
 
     is_deeply(
-- 
2.44.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2024-05-16 13:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16 13:39 [pve-devel] [PATCH installer 0/6] small, overall install progress improvements Christoph Heiss
2024-05-16 13:39 ` [pve-devel] [PATCH installer 1/6] test: ui2-stdio: fix multi-process testing Christoph Heiss
2024-05-16 13:39 ` [pve-devel] [PATCH installer 2/6] auto, tui: move low-level installer message struct to common crate Christoph Heiss
2024-05-16 13:39 ` [pve-devel] [PATCH installer 3/6] auto: log non-json low-level messages into separate file Christoph Heiss
2024-05-16 13:39 ` Christoph Heiss [this message]
2024-05-16 13:39 ` [pve-devel] [PATCH installer 5/6] low-level: add proper message to 100% progress ratio update Christoph Heiss
2024-05-16 13:39 ` [pve-devel] [PATCH installer 6/6] auto: avoid printing unnecessary progress update lines Christoph Heiss
2024-07-23 10:35 ` [pve-devel] [PATCH installer 0/6] small, overall install progress improvements Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240516133945.1087246-5-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal