Skip to content

Commit

Permalink
Minor documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 committed Jul 15, 2023
1 parent 0932024 commit edbbe2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<C: Component> AsRGB for rgb::alt::Gray<C> {
fn as_u32(&self) -> u32 { self.into_u8() as u32 * 0x010101 }

/// Returns index of a colour in 256-colour ANSI palette approximating given
/// shade grey.
/// shade of grey.
///
/// This implementation is present only if `rgb` crate feature is enabled.
/// Implementation is provided for `u8` and `u16` colour component types.
Expand Down Expand Up @@ -131,16 +131,15 @@ impl<C: Component> AsRGB for rgb::alt::BGR<C> {

#[cfg(feature = "ansi_term")]
impl AsRGB for ansi_term::Colour {
/// Returns sRGB colour corresponding to escape code represented by
/// [`ansi_term::Colour`].
/// Returns sRGB colour corresponding to escape code represented by the
/// object.
///
/// Behaves slightly differently depending on the variant of the enum.
/// - For named colour variants (`Black`, `Red` etc. up till `White`),
/// returns corresponding system colour with indexes going from 0 to 7.
/// - Similarly, for `Fixed` variant returns colour corresponding to
/// specified index. See [`rgb_from_ansi256`](`rgb_from_ansi256`).
/// - Lastly, for `RGB` variant converts it to 24-bit `0xRRGGBB`
/// representation.
/// - For `Fixed` variant returns colour corresponding to specified index.
/// See [`rgb_from_ansi256`](`rgb_from_ansi256`).
/// - For `RGB` variant converts it to 24-bit `0xRRGGBB` representation.
///
/// This implementation is present only if `ansi_term` crate feature is
/// enabled.
Expand All @@ -155,7 +154,7 @@ impl AsRGB for ansi_term::Colour {
Self::Purple => ansi256::ANSI_COLOURS[5],
Self::Cyan => ansi256::ANSI_COLOURS[6],
Self::White => ansi256::ANSI_COLOURS[7],
Self::Fixed(idx) => ansi256::ANSI_COLOURS[idx as usize],
Self::Fixed(idx) => ansi256::ANSI_COLOURS[usize::from(idx)],
Self::RGB(r, g, b) => (r, g, b).as_u32(),
}
}
Expand Down Expand Up @@ -306,10 +305,9 @@ impl AsRGB for termcolor::Color {
/// Behaves slightly differently depending on the variant of the enum.
/// - For named colour variants (`Black`, `Red` etc. up till `White`),
/// returns corresponding system colour with indexes going from 0 to 7.
/// - Similarly, for `Ansi256` variant returns colour corresponding to
/// specified index. See [`rgb_from_ansi256`](`rgb_from_ansi256`).
/// - Lastly, for `Rgb` variant converts it to 24-bit `0xRRGGBB`
/// representation.
/// - For `Ansi256` variant returns colour corresponding to specified index.
/// See [`rgb_from_ansi256`](`rgb_from_ansi256`).
/// - For `Rgb` variant converts it to 24-bit `0xRRGGBB` representation.
///
/// This implementation is present only if `termcolor` crate feature is
/// enabled.
Expand All @@ -324,7 +322,7 @@ impl AsRGB for termcolor::Color {
Self::Magenta => ansi256::ANSI_COLOURS[5],
Self::Yellow => ansi256::ANSI_COLOURS[3],
Self::White => ansi256::ANSI_COLOURS[7],
Self::Ansi256(idx) => ansi256::ANSI_COLOURS[idx as usize],
Self::Ansi256(idx) => ansi256::ANSI_COLOURS[usize::from(idx)],
Self::Rgb(r, g, b) => (r, g, b).as_u32(),
_ => unreachable!(),
}
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ mod test;
/// ramp. Those are standardised and thus should be the same on every terminal
/// which supports 256-colour colour palette.
///
/// The palette can be viewed on [helpful
/// chart](https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg).
///
/// # Examples
///
///
Expand Down Expand Up @@ -183,8 +186,8 @@ pub fn ansi256_from_grey(component: u8) -> u8 {
ansi256::ANSI256_FROM_GREY[component as usize]
}

/// Type which (can) represent an sRGB colour. Used to provide overloaded
/// versions of `ansi256_from_rgb` function.
/// Type which represents a colour convertible to sRGB. Used to provide
/// overloaded versions of `ansi256_from_rgb` function.
pub trait AsRGB {
/// Returns representation of the sRGB colour as a 24-bit `0xRRGGBB`
/// integer.
Expand Down

0 comments on commit edbbe2b

Please sign in to comment.