summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs16
-rw-r--r--src/vtcol.rs17
2 files changed, 27 insertions, 6 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()));
}
diff --git a/src/vtcol.rs b/src/vtcol.rs
index 3694753..e3ab5f2 100644
--- a/src/vtcol.rs
+++ b/src/vtcol.rs
@@ -34,7 +34,7 @@ enum Job
/** Toggle between two schemes. */
Toggle(Scheme, Scheme),
/** Fade from current scheme to another. */
- Fade(Option<Scheme>, Scheme, Duration, u8),
+ Fade(Option<Scheme>, Scheme, Duration, u8, bool),
}
impl<'a> Job
@@ -126,6 +126,13 @@ impl<'a> Job
.takes_value(true),
)
.arg(
+ Arg::with_name("clear")
+ .short("c")
+ .long("clear")
+ .help("clear terminal on each fade step")
+ .takes_value(false),
+ )
+ .arg(
Arg::with_name("frequency")
.value_name("HZ")
.short("h")
@@ -202,6 +209,7 @@ impl<'a> Job
} else {
DEFAULT_FADE_UPDATE_HZ
};
+ let clear = subm.is_present("clear");
let dur = Duration::from_millis(dur);
match (subm.value_of("from"), subm.value_of("to")) {
@@ -213,6 +221,7 @@ impl<'a> Job
Scheme::from(to),
dur,
hz,
+ clear,
)),
}
},
@@ -280,7 +289,8 @@ impl<'a> Job
Self::Set(scm) => Self::set_scheme(scm)?,
Self::Get => Self::get_scheme()?,
Self::Toggle(one, two) => Self::toggle_scheme(one, two)?,
- Self::Fade(from, to, ms, hz) => Self::fade(from, to, ms, hz)?,
+ Self::Fade(from, to, ms, hz, clear) =>
+ Self::fade(from, to, ms, hz, clear)?,
}
Ok(())
@@ -335,6 +345,7 @@ impl<'a> Job
to: Scheme,
dur: Duration,
hz: u8,
+ clear: bool,
) -> Result<()>
{
let fd = Console::current()?;
@@ -347,7 +358,7 @@ impl<'a> Job
};
let to = Palette::try_from(&to)?;
- let fade = Fade::new(from, to, dur, hz);
+ let fade = Fade::new(from, to, dur, hz, clear);
fade.commence(&fd)?;
Ok(())