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>
impl<W: Write> Chrome<W>
Sourcepub fn new(out: W, decor: Decor) -> Self
pub fn new(out: W, decor: Decor) -> Self
A chrome that writes what decor allows, and nothing else, to out.
Sourcepub fn enter(&mut self) -> Result<()>
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.
Sourcepub fn begin_frame(&mut self) -> Result<()>
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.
Sourcepub fn end_frame(&mut self) -> Result<()>
pub fn end_frame(&mut self) -> Result<()>
Closes it. Must run even when the draw between the two failed.
§Errors
Anything the terminal refuses.
Sourcepub fn announce(&mut self, body: &str, took: Duration) -> Result<()>
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.
Sourcepub fn failed(&mut self)
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.
Sourcepub fn restore(&mut self) -> Result<()>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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