Browse Source

utilities/widgets: ensure ProgressSpinner is cleaned up

tags/alpha-0.6.2
Manos Pitsidianakis 2 months ago
parent
commit
f83df69d2f
Signed by: epilys GPG Key ID: 73627C2F690DF710
2 changed files with 23 additions and 14 deletions
  1. +3
    -2
      src/components/utilities.rs
  2. +20
    -12
      src/components/utilities/widgets.rs

+ 3
- 2
src/components/utilities.rs View File

@ -663,7 +663,7 @@ impl StatusBar {
height: 1,
id: ComponentId::new_v4(),
auto_complete: AutoComplete::new(Vec::new()),
progress_spinner: ProgressSpinner::new(3),
progress_spinner: ProgressSpinner::new(1),
in_progress_jobs: HashSet::default(),
done_jobs: HashSet::default(),
cmd_history: crate::command::history::old_cmd_history(),
@ -1182,8 +1182,8 @@ impl Component for StatusBar {
self.in_progress_jobs.remove(job_id);
if self.in_progress_jobs.is_empty() {
self.progress_spinner.stop();
self.set_dirty(true);
}
self.progress_spinner.set_dirty(true);
}
UIEvent::StatusEvent(StatusEvent::NewJob(ref job_id))
if !self.done_jobs.contains(job_id) =>
@ -1191,6 +1191,7 @@ impl Component for StatusBar {
if self.in_progress_jobs.is_empty() {
self.progress_spinner.start();
}
self.progress_spinner.set_dirty(true);
self.in_progress_jobs.insert(*job_id);
}
UIEvent::Timer(_) => {

+ 20
- 12
src/components/utilities/widgets.rs View File

@ -996,12 +996,13 @@ pub struct ProgressSpinner {
timer: crate::timer::PosixTimer,
stage: usize,
kind: usize,
active: bool,
dirty: bool,
id: ComponentId,
}
impl ProgressSpinner {
const KINDS: &'static [&'static [&'static str]] = &[
const KINDS: [&'static [&'static str]; 15] = [
&["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"],
&["⣀", "⣄", "⣤", "⣦", "⣶", "⣷", "⣿"],
&["⣀", "⣄", "⣆", "⣇", "⣧", "⣷", "⣿"],
@ -1029,16 +1030,19 @@ impl ProgressSpinner {
nix::sys::signal::Signal::SIGALRM,
)
.unwrap();
debug!("Requested timer {:?} for ProgressSpinner", timer.si_value);
ProgressSpinner {
timer,
stage: 0,
kind: kind % Self::KINDS.len(),
dirty: true,
active: false,
id: ComponentId::new_v4(),
}
}
pub fn start(&mut self) {
self.active = true;
self.timer
.set_interval(Self::INTERVAL)
.set_value(Self::VALUE)
@ -1046,6 +1050,8 @@ impl ProgressSpinner {
}
pub fn stop(&mut self) {
self.active = false;
self.stage = 0;
self.timer
.set_interval(std::time::Duration::from_millis(0))
.set_value(std::time::Duration::from_millis(0))
@ -1064,17 +1070,19 @@ impl Component for ProgressSpinner {
if self.dirty {
let theme_attr = crate::conf::value(context, "status.bar");
clear_area(grid, area, theme_attr);
let stage = self.stage;
self.stage = (self.stage + 1).wrapping_rem(Self::KINDS[self.kind].len());
write_string_to_grid(
Self::KINDS[self.kind][stage],
grid,
theme_attr.fg,
theme_attr.bg,
theme_attr.attrs,
area,
None,
);
if self.active {
let stage = self.stage;
self.stage = (self.stage + 1).wrapping_rem(Self::KINDS[self.kind].len());
write_string_to_grid(
Self::KINDS[self.kind][stage],
grid,
theme_attr.fg,
theme_attr.bg,
theme_attr.attrs,
area,
None,
);
}
context.dirty_areas.push_back(area);
self.dirty = false;
}

Loading…
Cancel
Save