Struct conciliator::spin::Line
source · pub struct Line<'s> { /* private fields */ }
Expand description
Wrap a Buffer
to print it and a newline when dropped, (Spinner
version)
This struct “borrows” (figuratively) a Buffer
from a Spinner
.
It holds a reference to this Spinner
, and the destructor uses this reference to print the buffer to the terminal.
Before the buffer is printed, a newline character is appended to it.
This can be avoided by using Line::no_newline
to turn it into a NoNewLine
.
Implementations§
source§impl<'s> Line<'s>
impl<'s> Line<'s>
sourcepub fn no_newline(self) -> NoNewLine<'s>
pub fn no_newline(self) -> NoNewLine<'s>
No longer add the newline when dropped
Make sure to end every chunk of output with a newline, otherwise the last line will get overwritten by the Spinner
message!
Additionally, be careful with using this and sending a newline in another Buffer
afterwards: if you get unlucky, the Spinner
thread might print and overwrite the contents of this one before it gets to the one that contains the newline.
Just how unlucky you would have to be is hard to say, and it probably depends on the refresh-rate of the animation you use, but in my estimation it is extremely unlikely.
Methods from Deref<Target = Buffer>§
sourcepub fn push_inline<T: Inline>(&mut self, thing: &T) -> &mut Self
pub fn push_inline<T: Inline>(&mut self, thing: &T) -> &mut Self
Append thing
onto the buffer using the Inline
trait
sourcepub fn push<M, T: Pushable<M>>(&mut self, thing: T) -> &mut Self
pub fn push<M, T: Pushable<M>>(&mut self, thing: T) -> &mut Self
Append thing
onto the buffer using either Inline
or Display
, doesn’t work if both are implemented for T
Pushable
is blanket-implemented for both Inline
and Display
types.
This would normally not be possible, because both blanket implementations could apply to the same type, thereby causing a conflict (Rust does not have any specialization or way to express where T: NOT Trait
).
So instead, this uses a trick that relies on a “marker type” being inferred.
This workaround is described in detail on Pushable
, but in short:
Pushable
has a type parameterM
(i.e.trait Pushable<M>
) that is not used except to make distinct implementations possible for the same typeimpl<T: Display> Pushable<marker::AsDisplay> for T
impl<T: Inline> Pushable<marker::AsInline> for T
push
is implemented for anyT: Pushable<M>
with anyM
- when there is only one applicable implementation, the marker type
M
can be inferred and won’t need to be specified - Surprisingly, it just works!
If, however, there are multiple applicable implementations (i.e. for a type implements Inline
and Display
), the type cannot be inferred: type annotations needed
.
In this case, it is easier to just use the more specific function instead of bothering with the type annotations.
(For the time being, the marker types are private, so type annotations are also impossible.)
use conciliator::{Conciliator, Wrap};
let con = conciliator::init();
con.line(..)
.push("Test") // &str,
.push(123) // i32 and
.push(' ') // char all implement Display
.push(Wrap::Alpha(":^)")); // Wrap implements Inline
Trait Implementations§
source§impl<'s> EmitEscapes for Line<'s>
impl<'s> EmitEscapes for Line<'s>
source§fn escapes_recognized(&self) -> bool
fn escapes_recognized(&self) -> bool
true
, escape codes will be emitted. Read moresource§fn set_color(&mut self, color: ColorCode) -> IoResult<()>
fn set_color(&mut self, color: ColorCode) -> IoResult<()>
\x1B[3???m
)source§impl<'s> Write for Line<'s>
impl<'s> Write for Line<'s>
source§fn write(&mut self, buf: &[u8]) -> IoResult<usize>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
source§fn flush(&mut self) -> IoResult<()>
fn flush(&mut self) -> IoResult<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)Auto Trait Implementations§
impl<'s> !RefUnwindSafe for Line<'s>
impl<'s> Send for Line<'s>
impl<'s> Sync for Line<'s>
impl<'s> Unpin for Line<'s>
impl<'s> !UnwindSafe for Line<'s>
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> Paint for Twhere
T: EmitEscapes,
impl<T> Paint for Twhere
T: EmitEscapes,
source§fn push_plain<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self
fn push_plain<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self
thing
onto the buffer using the Display
trait (plain uncolored text)source§fn push_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self
fn push_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self
thing
onto the buffer using the Display
trait (plain uncolored text but in bold)source§fn push_with_color_bold<T: Display + ?Sized>(
&mut self,
color: Color,
thing: &T
) -> &mut Self
fn push_with_color_bold<T: Display + ?Sized>( &mut self, color: Color, thing: &T ) -> &mut Self
push_with_color
but boldsource§fn push_with_any_color<T: Display + ?Sized>(
&mut self,
color: ColorCode,
thing: &T
) -> &mut Self
fn push_with_any_color<T: Display + ?Sized>( &mut self, color: ColorCode, thing: &T ) -> &mut Self
source§fn push_with_any_color_bold<T: Display + ?Sized>(
&mut self,
color: ColorCode,
thing: &T
) -> &mut Self
fn push_with_any_color_bold<T: Display + ?Sized>( &mut self, color: ColorCode, thing: &T ) -> &mut Self
push_with_any_color
but bold