Skip to main content

Reveal

Struct Reveal 

Source
pub struct Reveal<'a> { /* private fields */ }
Expand description

A live terminal reveal session.

Construct it, call render with each new progress value as your task advances, then finish. The terminal is restored on drop, on panic, and on Ctrl+C, and everything degrades to a no-op when stdout is not a TTY (piped, redirected, CI), so the same code is safe everywhere.

Progress may move backwards as well as forwards; the reveal is seekable.

use inkling::{Art, ordering::{Ordering, Geodesic}, render::{Reveal, Style}};

let art = Art::parse(include_str!("../assets/dragon.txt"));
let ranks = Geodesic::default().rank(&art);

let mut reveal = Reveal::new(&art, &ranks, Style::default())?;
for done in 0..=100 {
    reveal.render(done as f32 / 100.0)?;
    // ... do a slice of real work ...
}
reveal.finish()?;

Implementations§

Source§

impl<'a> Reveal<'a>

Source

pub fn new(art: &'a Art, ranks: &'a RankMap, style: Style) -> Result<Self>

Begin a reveal session. On a TTY this switches to the alternate screen and hides the cursor; otherwise it is inert until finish.

Source

pub fn render(&mut self, progress: f32) -> Result<()>

Render the frame at progress. A no-op when stdout is not a TTY.

Source

pub fn finish(self) -> Result<()>

Restore the terminal and leave the completed art in normal scrollback.

Trait Implementations§

Source§

impl Drop for Reveal<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Reveal<'a>

§

impl<'a> RefUnwindSafe for Reveal<'a>

§

impl<'a> Send for Reveal<'a>

§

impl<'a> Sync for Reveal<'a>

§

impl<'a> Unpin for Reveal<'a>

§

impl<'a> UnsafeUnpin for Reveal<'a>

§

impl<'a> UnwindSafe for Reveal<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.