1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
//! Example showing that progress bar that are too wide for the terminal are
//! horizontally truncated, even if `State::render` ignores the advised width.
use std::thread::sleep;
use std::time::Duration;
struct Model {
i: usize,
width: usize,
}
impl nutmeg::Model for Model {
fn render(&mut self, _width: usize) -> String {
let mut s = format!("i={} | ", self.i);
let ii = self.i % self.width;
for _ in 0..ii {
s.push('_');
}
s.push('🦀');
for _ in (ii + 1)..self.width {
s.push('_');
}
s
}
}
fn main() {
let options = nutmeg::Options::default().update_interval(Duration::from_millis(50));
let model = Model { i: 0, width: 120 };
let view = nutmeg::View::new(model, options);
for _ in 1..=360 {
view.update(|state| state.i += 1);
sleep(Duration::from_millis(100));
}
// Should show nothing because progress is disabled
}
|