TODO: As should change creation interface of `Bar` to take `T` instead of `impl Into<T>`; otherwise, return type deduction of `T` fails. The `impl Into<T> + AsRawFd` creation functions should be moved into another `impl<T: ... + AsRawFd>` block and take `T` directly.
Fortune for termprogress's current commit: Curse − 凶
/// A progress bar with a size and optionally title. It implements the `ProgressBar` trait, and is the default progress bar.
///
/// The bar has a max size, that is usually derived from the size of your terminal (if it can be detected) or can be set yourself, to stop the title line going over the side.
// self.refresh(), with exclusive access. (XXX: Maybe move this to a non-pub `&mut self` helper function)
letout=self.output.get_mut();
//TODO: What to do about I/O errors?
let_=out.write_all(b"\r")
.and_then(|_|stackalloc::stackalloc(max_width,b' ',|spaces|out.write_all(spaces)))// Write `max_width` spaces (TODO: Is there a better way to do this? With no allocation? With a repeating iterator maybe?)
.and_then(|_|out.write_all(b"\r"))
.and_then(move|_|flush!(?out));
}
fnupdate_dimensions(&mutself,to: usize)
{
self.max_width=to;
self.refresh();
// self.refresh(), with exclusive access. (XXX: Maybe move this to a non-pub `&mut self` helper function)
letout=self.output.get_mut();
//TODO: What to do about I/O errors?
let_=out.write_all(b"\r")
.and_then(|_|stackalloc::stackalloc(to,b' ',|spaces|out.write_all(spaces)))// Write `max_width` spaces (TODO: Is there a better way to do this? With no allocation? With a repeating iterator maybe?)
// self.refresh(), with exclusive access. (XXX: Maybe move this to a non-pub `&mut self` helper function)
letout=self.output.get_mut();
//TODO: What to do about I/O errors?
let_=out.write_all(b"\r")
.and_then(|_|stackalloc::stackalloc(max_width,b' ',|spaces|out.write_all(spaces)))// Write `max_width` spaces (TODO: Is there a better way to do this? With no allocation? With a repeating iterator maybe?)
//! A simple character spinner for bars with no known size
usesuper::*;
usestd::io;
/// A single character spinner with optional title that can be told to spin whenever it wants. It implements `Spinner` trait, and is the default spinner.
///
@ -17,19 +18,83 @@ use super::*;
/// # How it looks
/// It renders in the terminal like:
/// `This is a spinner /`
pubstructSpin
///
/// # Thread `Sync`safety
/// This type is safely `Sync` (where `T` is), the behaviour is defined to prevent overlapping writes to `T`.
/// Though it is *advised* to not render a `Spin` from more than a single thread, you still safely can.
///
/// A display operation on one thread will cause any other threads attempting on to silently and safely abort their display attempt before anything is written to output.
pubstructSpin<T: ?Sized=DefaultOutputDevice>/*<T: ?Sized = DefaultOutputDevice>*///TODO: <- implement same as `Bar
{
title: String,
current: char,
chars: wheel::WheelIntoIter,
output: AtomicRefCell<T>,
}
implSpin
{
/// Create a new spinner with title and wheel.
/// Create a new spinner with title and wheel writing to `stdout`.
///
/// To give it the default wheel, you can pass `whl` `Default::default()` to use the default one.
/// Create a new blank spinner with a wheel writing to `stdout`.
///
/// # Example
/// ```rust
/// # use termprogress::prelude::*;
/// Spin::new_default(Default::default()); // Create a spinner with the default wheel ('|/-\') that writes to stdout.
/// ```
#[inline]
pubfnnew_default(whl: wheel::Wheel)-> Self
{
Self::new(create_default_output_device(),whl)
}
}
impl<T>Spin<T>
{
/// Return the backing write object
#[inline]
pubfninto_inner(self)-> T
{
self.output.into_inner()
}
}
impl<T: ?Sized>Spin<T>
{
/// Get a mutable reference to the inner object
#[inline]
pubfninner_mut(&mutself)-> &mutT
{
self.output.get_mut()
}
/// Get a shared reference to the inner object
///
/// # Returns
/// `None` is returned if a display operation is currently in progress on another thread.
///
/// ## Operation suspension
/// As long as the returned reference lives, **all** display operations will fail silently, on this thread and any other. This method should be avoided in favour of `&*inner_mut()` when exclusive ownership is avaliable.