Skip to main content

Chrome

Struct Chrome 

Source
pub struct Chrome<W: Write> { /* private fields */ }
Expand description

The terminal’s decorations, and the promise to undo them.

Generic over its sink so the sequences are assertable. That is not a courtesy to the tests: every one of these writes is invisible to every other kind of test — a title that is never restored, a progress bar left at 41% forever, a frame that begins a synchronized update and never ends it — and the last of those leaves the reader looking at a frozen screen.

Implementations§

Source§

impl<W: Write> Chrome<W>

Source

pub fn new(out: W, decor: Decor) -> Self

A chrome that writes what decor allows, and nothing else, to out.

Source

pub fn enter(&mut self) -> Result<()>

Takes the states that have to be given back: the title, and focus reporting.

Focus reporting is only asked for when a notification could actually be sent, because it is the answer to exactly one question — is anybody looking — and a terminal that cannot show a notification is not being asked it.

The flag is set before the writes rather than after each one, which is the opposite of [super::Restore]’s rule and deliberate: a half-written enter leaves the terminal in a state this cannot know, and of the two ways to be wrong, undoing something that never happened costs five bytes at a terminal already being restored while skipping the undo leaves a shell answering every click with escape gibberish.

§Errors

Anything the terminal refuses.

Source

pub fn begin_frame(&mut self) -> Result<()>

Opens a synchronized update. Everything drawn until Chrome::end_frame lands at once.

§Errors

Anything the terminal refuses.

Source

pub fn end_frame(&mut self) -> Result<()>

Closes it. Must run even when the draw between the two failed.

§Errors

Anything the terminal refuses.

Source

pub fn show(&mut self, status: Status) -> Result<()>

Says where the run has got to, writing only what changed.

§Errors

Anything the terminal refuses.

Source

pub fn focused(&mut self, here: bool)

What the terminal reported about the reader’s attention.

Source

pub fn announce(&mut self, body: &str, took: Duration) -> Result<()>

Tells the reader something finished, if they are not here to see it and it took long enough to be worth saying.

§Errors

Anything the terminal refuses.

Source

pub fn failed(&mut self)

Records that the run is ending without having done everything it was asked.

The bar says so rather than simply going out, because the reader who wanted a bar is by definition the reader who is not looking at the exit status.

Source

pub fn restore(&mut self) -> Result<()>

Puts back everything this took, and can be called twice.

Idempotent because it runs from two places by design: the ordinary way out, and the guard that owns it being dropped by a ? or a panic. Every step is attempted and the first refusal reported, for [super::Restore]’s reason — a terminal half restored is no better than one not restored at all, and a failing call says nothing about whether the next would.

§Errors

The first thing the terminal refused.

Trait Implementations§

Source§

impl<W: Debug + Write> Debug for Chrome<W>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Chrome<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Chrome<W>
where W: RefUnwindSafe,

§

impl<W> Send for Chrome<W>
where W: Send,

§

impl<W> Sync for Chrome<W>
where W: Sync,

§

impl<W> Unpin for Chrome<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Chrome<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for Chrome<W>
where W: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.