Skip to main content

Style

Struct Style 

Source
pub struct Style {
    pub feather: f32,
    pub body: (u8, u8, u8),
    pub head: (u8, u8, u8),
    pub color: bool,
    pub palette: Palette,
}
Expand description

Visual options for the reveal.

Fields§

§feather: f32

Width of the soft leading edge, in rank units. The band of cells within feather of the frontier is the glowing “head”. 0.0 disables the glow.

§body: (u8, u8, u8)

Colour of settled (fully revealed) ink, under the Glow palette.

§head: (u8, u8, u8)

Colour at the very frontier, blended toward body across the feather.

§color: bool

Emit colour. Defaults off when NO_COLOR is set.

§palette: Palette

How revealed cells are coloured.

Implementations§

Source§

impl Style

Source

pub fn rainbow() -> Self

A rainbow palette in the spirit of lolcat: each glyph takes its hue from its position, so the art reveals in diagonal bands of colour.

Examples found in repository?
examples/loader.rs (line 53)
21fn main() {
22    match std::env::args().nth(1).as_deref() {
23        Some("iter") => {
24            for _ in (0..100).inkling() {
25                work(20);
26            }
27        }
28        Some("spinner") => {
29            let loader = Loader::spinner();
30            loader.set_message("Doing something mysterious");
31            work(2500);
32            loader.finish();
33        }
34        Some("threads") => {
35            let loader = Loader::new(120);
36            loader.set_message("Four workers, one dragon");
37            thread::scope(|s| {
38                for _ in 0..4 {
39                    let handle = loader.handle();
40                    s.spawn(move || {
41                        for _ in 0..30 {
42                            work(30);
43                            handle.inc(1);
44                        }
45                    });
46                }
47            });
48            loader.finish();
49        }
50        Some("rainbow") => {
51            let loader = Loader::builder()
52                .total(100)
53                .style(inkling::render::Style::rainbow())
54                .message("Tasting the rainbow")
55                .start();
56            for _ in 0..100 {
57                work(20);
58                loader.inc(1);
59            }
60            loader.finish();
61        }
62        _ => {
63            let total: u64 = 100;
64            let loader = Loader::new(total);
65            loader.set_message("Summoning the dragon");
66            for _ in 0..total {
67                work(20);
68                loader.inc(1);
69            }
70            loader.finish();
71        }
72    }
73}
More examples
Hide additional examples
examples/download.rs (line 90)
36fn main() {
37    let args: Vec<String> = std::env::args().skip(1).collect();
38    let rainbow = args.iter().any(|a| a == "rainbow");
39    let geodesic = args.iter().any(|a| a == "geodesic");
40    let art_path = args.iter().find(|a| a.ends_with(".txt")).cloned();
41    let started = Instant::now();
42    let gold = Color::Rgb {
43        r: 232,
44        g: 180,
45        b: 85,
46    };
47
48    // Clear to a fresh screen and print the tool banner.
49    let _ = execute!(
50        io::stdout(),
51        Clear(ClearType::All),
52        MoveTo(0, 0),
53        Print("\r\n  "),
54        SetForegroundColor(gold),
55        Print("dragonctl"),
56        ResetColor,
57        Print("  v0.2.0\r\n\r\n")
58    );
59
60    step("\u{2713}", Color::Green, "Initializing demo environment");
61    pause(450);
62    step("\u{2713}", Color::Green, "Updating base image index");
63    pause(500);
64    step("\u{2193}", Color::Cyan, "Downloading base image");
65    let _ = execute!(io::stdout(), Print("\r\n"));
66
67    // The download itself, paced unevenly: a connect stall, a hiccup, a burst, a
68    // mid stall, and a slow tail.
69    let total: u64 = 48 * 1024 * 1024;
70    let mb = 1024.0 * 1024.0;
71    let schedule: &[(f64, u64)] = &[
72        (0.0, 600),
73        (5.0, 300),
74        (8.0, 250),
75        (8.0, 650),
76        (16.0, 220),
77        (27.0, 180),
78        (38.0, 200),
79        (45.0, 450),
80        (56.0, 200),
81        (67.0, 220),
82        (78.0, 260),
83        (87.0, 320),
84        (93.0, 480),
85        (97.0, 520),
86        (100.0, 300),
87    ];
88
89    let style = if rainbow {
90        Style::rainbow()
91    } else {
92        Style::default()
93    };
94    let mut builder = Loader::builder().total(total).style(style);
95    if geodesic {
96        builder = builder.ordering(Geodesic::default());
97    }
98    if let Some(path) = &art_path {
99        let text = std::fs::read_to_string(path).unwrap_or_else(|e| {
100            eprintln!("could not read {path}: {e}");
101            std::process::exit(1);
102        });
103        builder = builder.art(inkling::Art::parse(&text));
104    }
105    let loader = builder.start();
106    for &(percent, dwell) in schedule {
107        let done = (percent / 100.0 * total as f64) as u64;
108        loader.set(done);
109        loader.set_message(format!(
110            "dragon.iso   {:.1} / {:.1} MB",
111            done as f64 / mb,
112            total as f64 / mb
113        ));
114        pause(dwell);
115    }
116    loader.finish();
117
118    // A finish that ties it together.
119    let _ = execute!(io::stdout(), Print("\r\n"));
120    step(
121        "\u{2713}",
122        Color::Green,
123        "Verified checksum  sha256:a1b2c3d4e5",
124    );
125    pause(400);
126    let _ = execute!(
127        io::stdout(),
128        Print("\r\n  "),
129        SetForegroundColor(Color::Green),
130        Print("Done"),
131        ResetColor,
132        Print(format!(
133            " in {:.1}s. dragon.iso (48.0 MB) ready.\r\n\r\n",
134            started.elapsed().as_secs_f64()
135        ))
136    );
137    let _ = io::stdout().flush();
138}

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Style

Source§

impl Debug for Style

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Style

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnsafeUnpin for Style

§

impl UnwindSafe for Style

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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.