Skip to content

Commit

Permalink
Add more item links in docs (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-korsa authored Nov 28, 2023
1 parent f33789e commit 81aa4c6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::TermLike;

/// Target for draw operations
///
/// This tells a progress bar or a multi progress object where to paint to.
/// This tells a [`ProgressBar`](crate::ProgressBar) or a
/// [`MultiProgress`](crate::MultiProgress) object where to paint to.
/// The draw target is a stateful wrapper over a drawing destination and
/// internally optimizes how often the state is painted to the output
/// device.
Expand Down
19 changes: 10 additions & 9 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ pub trait ProgressIterator
where
Self: Sized + Iterator,
{
/// Wrap an iterator with default styling. Uses `Iterator::size_hint` to get length.
/// Returns `Some(..)` only if `size_hint.1` is `Some`. If you want to create a progress bar
/// even if `size_hint.1` returns `None` use `progress_count` or `progress_with` instead.
/// Wrap an iterator with default styling. Uses [`Iterator::size_hint()`] to get length.
/// Returns `Some(..)` only if `size_hint.1` is [`Some`]. If you want to create a progress bar
/// even if `size_hint.1` returns [`None`] use [`progress_count()`](ProgressIterator::progress_count)
/// or [`progress_with()`](ProgressIterator::progress_with) instead.
fn try_progress(self) -> Option<ProgressBarIter<Self>> {
self.size_hint()
.1
Expand Down Expand Up @@ -66,47 +67,47 @@ pub struct ProgressBarIter<T> {
impl<T> ProgressBarIter<T> {
/// Builder-like function for setting underlying progress bar's style.
///
/// See [`ProgressBar::with_style`].
/// See [`ProgressBar::with_style()`].
pub fn with_style(mut self, style: ProgressStyle) -> Self {
self.progress = self.progress.with_style(style);
self
}

/// Builder-like function for setting underlying progress bar's prefix.
///
/// See [`ProgressBar::with_prefix`].
/// See [`ProgressBar::with_prefix()`].
pub fn with_prefix(mut self, prefix: impl Into<Cow<'static, str>>) -> Self {
self.progress = self.progress.with_prefix(prefix);
self
}

/// Builder-like function for setting underlying progress bar's message.
///
/// See [`ProgressBar::with_message`].
/// See [`ProgressBar::with_message()`].
pub fn with_message(mut self, message: impl Into<Cow<'static, str>>) -> Self {
self.progress = self.progress.with_message(message);
self
}

/// Builder-like function for setting underlying progress bar's position.
///
/// See [`ProgressBar::with_position`].
/// See [`ProgressBar::with_position()`].
pub fn with_position(mut self, position: u64) -> Self {
self.progress = self.progress.with_position(position);
self
}

/// Builder-like function for setting underlying progress bar's elapsed time.
///
/// See [`ProgressBar::with_elapsed`].
/// See [`ProgressBar::with_elapsed()`].
pub fn with_elapsed(mut self, elapsed: Duration) -> Self {
self.progress = self.progress.with_elapsed(elapsed);
self
}

/// Builder-like function for setting underlying progress bar's finish behavior.
///
/// See [`ProgressBar::with_finish`].
/// See [`ProgressBar::with_finish()`].
pub fn with_finish(mut self, finish: ProgressFinish) -> Self {
self.progress = self.progress.with_finish(finish);
self
Expand Down
21 changes: 11 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
//!
//! # Progress Bars and Spinners
//!
//! indicatif comes with a `ProgressBar` type that supports both bounded
//! indicatif comes with a [`ProgressBar`] type that supports both bounded
//! progress bar uses as well as unbounded "spinner" type progress reports.
//! Progress bars are `Sync` and `Send` objects which means that they are
//! Progress bars are [`Sync`] and [`Send`] objects which means that they are
//! internally locked and can be passed from thread to thread.
//!
//! Additionally a `MultiProgress` utility is provided that can manage
//! Additionally a [`MultiProgress`] utility is provided that can manage
//! rendering multiple progress bars at once (eg: from multiple threads).
//!
//! To whet your appetite, this is what this can look like:
Expand All @@ -56,8 +56,8 @@
//! bar.finish();
//! ```
//!
//! Spinners can be manually advanced with `tick`, or you can set them up to spin automatically with
//! `enable_steady_tick`:
//! Spinners can be manually advanced with [`tick`](ProgressBar::tick), or you can set them up
//! to spin automatically with [`enable_steady_tick`](ProgressBar::enable_steady_tick):
//!
//! ```rust
//! use std::time::Duration;
Expand All @@ -74,9 +74,10 @@
//! * if a non terminal is detected the progress bar will be completely
//! hidden. This makes piping programs to logfiles make sense out of
//! the box.
//! * a progress bar only starts drawing when `set_message`, `inc`, `set_position`
//! or `tick` are called. In some situations you might have to call `tick`
//! once to draw it.
//! * a progress bar only starts drawing when [`set_message`](ProgressBar::set_message),
//! [`inc`](ProgressBar::inc), [`set_position`](ProgressBar::set_position)
//! or [`tick`](ProgressBar::tick) are called. In some situations you
//! might have to call [`tick`](ProgressBar::tick) once to draw it.
//! * progress bars should be explicitly finished to reset the rendering
//! for others. Either by also clearing them or by replacing them with
//! a new message / retaining the current message.
Expand Down Expand Up @@ -147,7 +148,7 @@
//! ```
//!
//! For the style component see [`Style::from_dotted_str`](https://docs.rs/console/0.7.5/console/struct.Style.html#method.from_dotted_str)
//! for more information. Indicatif uses the `console` base crate for all
//! for more information. Indicatif uses the `console` base crate for all
//! colorization and formatting options.
//!
//! Some examples for templates:
Expand Down Expand Up @@ -206,7 +207,7 @@
//!
//! The design of the progress bar can be altered with the integrated
//! template functionality. The template can be set by changing a
//! `ProgressStyle` and attaching it to the progress bar.
//! [`ProgressStyle`] and attaching it to the progress bar.
//!
//! # Human Readable Formatting
//!
Expand Down
28 changes: 14 additions & 14 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ impl MultiProgress {
///
/// The progress bar added will have the draw target changed to a
/// remote draw target that is intercepted by the multi progress
/// object overriding custom `ProgressDrawTarget` settings.
/// object overriding custom [`ProgressDrawTarget`] settings.
///
/// The progress bar will be positioned below all other bars currently
/// in the `MultiProgress`.
/// in the [`MultiProgress`].
///
/// Adding a progress bar that is already a member of the `MultiProgress`
/// Adding a progress bar that is already a member of the [`MultiProgress`]
/// will have no effect.
pub fn add(&self, pb: ProgressBar) -> ProgressBar {
self.internalize(InsertLocation::End, pb)
Expand All @@ -83,12 +83,12 @@ impl MultiProgress {
///
/// The progress bar inserted at position `index` will have the draw
/// target changed to a remote draw target that is intercepted by the
/// multi progress object overriding custom `ProgressDrawTarget` settings.
/// multi progress object overriding custom [`ProgressDrawTarget`] settings.
///
/// If `index >= MultiProgressState::objects.len()`, the progress bar
/// is added to the end of the list.
///
/// Inserting a progress bar that is already a member of the `MultiProgress`
/// Inserting a progress bar that is already a member of the [`MultiProgress`]
/// will have no effect.
pub fn insert(&self, index: usize, pb: ProgressBar) -> ProgressBar {
self.internalize(InsertLocation::Index(index), pb)
Expand All @@ -99,12 +99,12 @@ impl MultiProgress {
/// The progress bar inserted at position `MultiProgressState::objects.len() - index`
/// will have the draw target changed to a remote draw target that is
/// intercepted by the multi progress object overriding custom
/// `ProgressDrawTarget` settings.
/// [`ProgressDrawTarget`] settings.
///
/// If `index >= MultiProgressState::objects.len()`, the progress bar
/// is added to the start of the list.
///
/// Inserting a progress bar that is already a member of the `MultiProgress`
/// Inserting a progress bar that is already a member of the [`MultiProgress`]
/// will have no effect.
pub fn insert_from_back(&self, index: usize, pb: ProgressBar) -> ProgressBar {
self.internalize(InsertLocation::IndexFromBack(index), pb)
Expand All @@ -114,9 +114,9 @@ impl MultiProgress {
///
/// The progress bar added will have the draw target changed to a
/// remote draw target that is intercepted by the multi progress
/// object overriding custom `ProgressDrawTarget` settings.
/// object overriding custom [`ProgressDrawTarget`] settings.
///
/// Inserting a progress bar that is already a member of the `MultiProgress`
/// Inserting a progress bar that is already a member of the [`MultiProgress`]
/// will have no effect.
pub fn insert_before(&self, before: &ProgressBar, pb: ProgressBar) -> ProgressBar {
self.internalize(InsertLocation::Before(before.index().unwrap()), pb)
Expand All @@ -126,9 +126,9 @@ impl MultiProgress {
///
/// The progress bar added will have the draw target changed to a
/// remote draw target that is intercepted by the multi progress
/// object overriding custom `ProgressDrawTarget` settings.
/// object overriding custom [`ProgressDrawTarget`] settings.
///
/// Inserting a progress bar that is already a member of the `MultiProgress`
/// Inserting a progress bar that is already a member of the [`MultiProgress`]
/// will have no effect.
pub fn insert_after(&self, after: &ProgressBar, pb: ProgressBar) -> ProgressBar {
self.internalize(InsertLocation::After(after.index().unwrap()), pb)
Expand All @@ -137,7 +137,7 @@ impl MultiProgress {
/// Removes a progress bar.
///
/// The progress bar is removed only if it was previously inserted or added
/// by the methods `MultiProgress::insert` or `MultiProgress::add`.
/// by the methods [`MultiProgress::insert`] or [`MultiProgress::add`].
/// If the passed progress bar does not satisfy the condition above,
/// the `remove` method does nothing.
pub fn remove(&self, pb: &ProgressBar) {
Expand Down Expand Up @@ -494,14 +494,14 @@ impl Debug for MultiStateMember {
/// Vertical alignment of a multi progress.
///
/// The alignment controls how the multi progress is aligned if some of its progress bars get removed.
/// E.g. `Top` alignment (default), when _progress bar 2_ is removed:
/// E.g. [`Top`](MultiProgressAlignment::Top) alignment (default), when _progress bar 2_ is removed:
/// ```ignore
/// [0/100] progress bar 1 [0/100] progress bar 1
/// [0/100] progress bar 2 => [0/100] progress bar 3
/// [0/100] progress bar 3
/// ```
///
/// `Bottom` alignment
/// [`Bottom`](MultiProgressAlignment::Bottom) alignment
/// ```ignore
/// [0/100] progress bar 1
/// [0/100] progress bar 2 => [0/100] progress bar 1
Expand Down
28 changes: 14 additions & 14 deletions src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl ProgressBar {
/// [`ProgressBarIter`] completes and
/// [`ProgressBar::is_finished()`] is false.
/// If you don't want the progress bar to be automatically finished then
/// call `on_finish(None)`.
/// call `with_finish(Abandon)`.
///
/// [`ProgressBar`]: crate::ProgressBar
/// [`ProgressBarIter`]: crate::ProgressBarIter
Expand Down Expand Up @@ -237,12 +237,12 @@ impl ProgressBar {
///
/// If the progress bar is hidden (e.g. when standard output is not a terminal), `println()`
/// will not do anything. If you want to write to the standard output in such cases as well, use
/// [`suspend`] instead.
/// [`ProgressBar::suspend()`] instead.
///
/// If the progress bar was added to a [`MultiProgress`], the log line will be
/// printed above all other progress bars.
///
/// [`suspend`]: ProgressBar::suspend
/// [`ProgressBar::suspend()`]: ProgressBar::suspend
/// [`MultiProgress`]: crate::MultiProgress
pub fn println<I: AsRef<str>>(&self, msg: I) {
self.state().println(Instant::now(), msg.as_ref());
Expand Down Expand Up @@ -293,7 +293,7 @@ impl ProgressBar {
state.update_estimate_and_draw(Instant::now());
}

/// Creates a new weak reference to this `ProgressBar`
/// Creates a new weak reference to this [`ProgressBar`]
pub fn downgrade(&self) -> WeakProgressBar {
WeakProgressBar {
state: Arc::downgrade(&self.state),
Expand Down Expand Up @@ -378,14 +378,14 @@ impl ProgressBar {
/// ```
///
/// **Note:** Calling this method on a [`ProgressBar`] linked with a [`MultiProgress`] (after
/// running [`MultiProgress::add`]) will unlink this progress bar. If you don't want this
/// behavior, call [`MultiProgress::set_draw_target`] instead.
/// running [`MultiProgress::add()`]) will unlink this progress bar. If you don't want this
/// behavior, call [`MultiProgress::set_draw_target()`] instead.
///
/// Use [`ProgressBar::with_draw_target`] to set the draw target during creation.
/// Use [`ProgressBar::with_draw_target()`] to set the draw target during creation.
///
/// [`MultiProgress`]: crate::MultiProgress
/// [`MultiProgress::add`]: crate::MultiProgress::add
/// [`MultiProgress::set_draw_target`]: crate::MultiProgress::set_draw_target
/// [`MultiProgress::add()`]: crate::MultiProgress::add
/// [`MultiProgress::set_draw_target()`]: crate::MultiProgress::set_draw_target
pub fn set_draw_target(&self, target: ProgressDrawTarget) {
let mut state = self.state();
state.draw_target.disconnect(Instant::now());
Expand All @@ -396,7 +396,7 @@ impl ProgressBar {
///
/// Useful for external code that writes to the standard output.
///
/// If the progress bar was added to a [`MultiProgress`], it will suspend the entire `MultiProgress`].
/// If the progress bar was added to a [`MultiProgress`], it will suspend the entire [`MultiProgress`].
///
/// **Note:** The internal lock is held while `f` is executed. Other threads trying to print
/// anything on the progress bar will be blocked until `f` finishes.
Expand Down Expand Up @@ -593,7 +593,7 @@ impl ProgressBar {
}
}

/// A weak reference to a `ProgressBar`.
/// A weak reference to a [`ProgressBar`].
///
/// Useful for creating custom steady tick implementations
#[derive(Clone, Default)]
Expand All @@ -604,15 +604,15 @@ pub struct WeakProgressBar {
}

impl WeakProgressBar {
/// Create a new `WeakProgressBar` that returns `None` when [`upgrade`] is called.
/// Create a new [`WeakProgressBar`] that returns `None` when [`upgrade()`] is called.
///
/// [`upgrade`]: WeakProgressBar::upgrade
/// [`upgrade()`]: WeakProgressBar::upgrade
pub fn new() -> Self {
Self::default()
}

/// Attempts to upgrade the Weak pointer to a [`ProgressBar`], delaying dropping of the inner
/// value if successful. Returns `None` if the inner value has since been dropped.
/// value if successful. Returns [`None`] if the inner value has since been dropped.
///
/// [`ProgressBar`]: struct.ProgressBar.html
pub fn upgrade(&self) -> Option<ProgressBar> {
Expand Down

0 comments on commit 81aa4c6

Please sign in to comment.