low-level: stdio: fix: make progress text properly optional

.. 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>
This commit is contained in:
Christoph Heiss 2024-11-25 12:27:17 +01:00 committed by Thomas Lamprecht
parent a1985ab9ab
commit 5241b6c45f
5 changed files with 25 additions and 12 deletions

View File

@ -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 {

View File

@ -205,7 +205,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" {

View File

@ -571,6 +571,6 @@ pub enum LowLevelMessage {
},
Progress {
ratio: f32,
text: String,
text: Option<String>,
},
}

View File

@ -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);
@ -310,7 +317,7 @@ mod tests {
next_msg(&mut reader),
Some(LowLevelMessage::Progress {
ratio: (i as f32) / 1000.,
text: format!("foo {i}"),
text: Some(format!("foo {i}")),
}),
);
}

View File

@ -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(