summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-11-23 13:02:44 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-11-23 13:02:44 +0100
commitfc6cec72aead59c1d45044e8945c5b8119eab823 (patch)
tree9b40f3ce1f8e709ee18fdf0298554185f83fe66d /src/lib.rs
parent84a552f3265d82e9fa553e9ddd3597a56739cbee (diff)
downloadvtcol-fc6cec72aead59c1d45044e8945c5b8119eab823.tar.gz
optionally clear after each fade step
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 5952517..fd2d4f2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -839,19 +839,26 @@ pub struct Fade
to: Palette,
hz: u8,
duration: Duration,
+ clear: bool,
}
impl Fade
{
- pub fn new(from: Palette, to: Palette, duration: Duration, hz: u8) -> Self
+ pub fn new(
+ from: Palette,
+ to: Palette,
+ duration: Duration,
+ hz: u8,
+ clear: bool,
+ ) -> Self
{
let hz = if hz == 0 { 1 } else { hz };
- Self { from, to, hz, duration }
+ Self { from, to, hz, duration, clear }
}
pub fn commence(self, con: &Console) -> io::Result<()>
{
- let Self { from, to, hz, duration } = self;
+ let Self { from, to, hz, duration, clear } = self;
con.apply_palette(&from)?;
let fade = FadePalette::from(&con.current_palette()?);
@@ -866,6 +873,9 @@ impl Fade
let progress = f64::from(i) / f64::from(iters);
let pal = Palette::from(&fade.towards(&fade_to, progress));
con.apply_palette(&pal)?;
+ if clear {
+ con.clear()?;
+ }
let next = i * tick;
std::thread::sleep(next.saturating_sub(t_0.elapsed()));
}