Struct conciliator::spin::Message

source ·
pub struct Message<'s> { /* private fields */ }
Expand description

Special Buffer that sets the Spinner message when dropped

Make sure that the Buffer does not contain any newlines and that it is short enough to fit onto a single line. If you don’t, the output will get messed up, and the user might not be able to read all of it (since some parts might get overwritten).

There’s no (easy) way to guarantee this doesn’t happen, the user can resize their terminal however they see fit, at any point. In the future, there may be support for automatically truncating messages that are too long to fit into a single line, but currently there is not (it’s quite a bit more complicated than just checking the length of the Buffer).

So, for the time being, just make sure that, together with the width of the animation (+3 for the brackets), the total stays well under the 80 columns rule.

Implementations§

source§

impl<'s> Message<'s>

source

pub fn set(self)

Set the contents of this buffer as the persistent Spinner status message. This is equivalent to dropping.

source

pub fn discard(self)

Discard and drop this buffer without changing the Spinner status message

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 Message<'s>

§

type Target = Buffer

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'s> DerefMut for Message<'s>

source§

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

Mutably dereferences the value.
source§

impl<'s> Drop for Message<'s>

source§

fn drop(&mut self)

The Message sends itself to the Spinner thread when dropped

source§

impl<'s> EmitEscapes for Message<'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 Message<'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 Message<'s>

§

impl<'s> Send for Message<'s>

§

impl<'s> Sync for Message<'s>

§

impl<'s> Unpin for Message<'s>

§

impl<'s> !UnwindSafe for Message<'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.