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>

source

pub fn print(self)

Print this Line into the Spinner. This is equivalent to dropping.

source

pub fn discard(self)

Discard and drop this buffer without printing it

source

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>§

source

pub fn push_inline<T: Inline>(&mut self, thing: &T) -> &mut Self

Append thing onto the buffer using the Inline trait

source

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 parameter M (i.e. trait Pushable<M>) that is not used except to make distinct implementations possible for the same type
  • impl<T: Display> Pushable<marker::AsDisplay> for T
  • impl<T: Inline> Pushable<marker::AsInline> for T
  • push is implemented for any T: Pushable<M> with any M
  • 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> Deref for Line<'s>

§

type Target = Buffer

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'s> DerefMut for Line<'s>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'s> Drop for Line<'s>

source§

fn drop(&mut self)

The Line prints itself to the Spinner when dropped

source§

impl<'s> EmitEscapes for Line<'s>

source§

fn escapes_recognized(&self) -> bool

If this returns true, escape codes will be emitted. Read more
source§

fn set_color(&mut self, color: ColorCode) -> IoResult<()>

Write a “foreground color” escape code (\x1B[3???m)
source§

fn set_bold(&mut self) -> IoResult<()>

Write a “bold text” escape code (\x1B[1m)
source§

fn reset(&mut self) -> IoResult<()>

Write a “reset style and color” escape code (\x1B[0m)
source§

fn write_with_color<T: Display + ?Sized>(&mut self, color: ColorCode, thing: &T)

set_color, then write! and then reset, provided for convenience
source§

fn write_with_color_bold<T: Display + ?Sized>( &mut self, color: ColorCode, thing: &T )

set_bold & set_color, then write! and then reset, provided for convenience
source§

impl<'s> Write for Line<'s>

source§

fn write(&mut self, buf: &[u8]) -> IoResult<usize>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> IoResult<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

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> 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> Paint for T
where T: EmitEscapes,

source§

fn tag(&mut self, color: Color, tag: &str) -> &mut Self

Add a tag to this buffer: [ $tag ]
source§

fn push_plain<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

Append thing onto the buffer using the Display trait (plain uncolored text)
source§

fn push_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

Append thing onto the buffer using the Display trait (plain uncolored text but in bold)
source§

fn push_alpha<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_beta<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_gamma<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_delta<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_zeta<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_iota<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_omega<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_alpha_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_beta_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_gamma_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_delta_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_zeta_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_iota_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_omega_bold<T: Display + ?Sized>(&mut self, thing: &T) -> &mut Self

source§

fn push_with_color<T: Display + ?Sized>( &mut self, color: Color, thing: &T ) -> &mut Self

Append to the buffer using Display but use the provided Color.
source§

fn push_with_color_bold<T: Display + ?Sized>( &mut self, color: Color, thing: &T ) -> &mut Self

Same as push_with_color but bold
source§

fn push_with_any_color<T: Display + ?Sized>( &mut self, color: ColorCode, thing: &T ) -> &mut Self

Append to the buffer using Display but use any ColorCode.
source§

fn push_with_any_color_bold<T: Display + ?Sized>( &mut self, color: ColorCode, thing: &T ) -> &mut Self

Same as push_with_any_color but bold
source§

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

§

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>,

§

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.