pub struct Whisper {
pub icon_kind: Option<IconKind>,
pub messages: Vec<String>,
}Expand description
Represents a collection of messages with an optional icon and message
Fields
icon_kind- An optional field that specifies the kind of icon to be displayed.messages- A vector of messages to be displayed.
Example
use murmur::{Whisper, IconKind};
let whisper = Whisper::new()
.icon(IconKind::NfFaBug)
.message("test_whisper_unwrap")
.whisper()
.ok();Fields§
§icon_kind: Option<IconKind>An optional field that specifies the kind of icon to be displayed.
messages: Vec<String>A vector of messages to be displayed.
Implementations§
source§impl Whisper
impl Whisper
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Whisper instance.
Example
use murmur::{Whisper, IconKind};
let whisper = Whisper::new()
.icon(IconKind::NfFaBug)
.message("message")
.whisper()
.ok();sourcepub fn icon(self, icon_kind: IconKind) -> Self
pub fn icon(self, icon_kind: IconKind) -> Self
Adds an icon to the Whisper instance.
Arguments
icon_kind: The kind of icon to be displayed. See theIconKindenum for a list of available icons.
Returns
A Whisper instance with the specified icon.
Examples
use murmur::{Whisper, IconKind};
let whisper = Whisper::new()
.icon(IconKind::NfFaCheck)
.message("Nerd Font icons if you have them installed")
.message("Another message")
.whisper()
.expect("Failed to print message");
let whisper = Whisper::new()
.icon(IconKind::UnicodeWarningSign)
.message("Unicode icons")
.whisper()
.or_else(|err| Err(err));sourcepub fn message<T: Display + Debug>(self, message: T) -> Self
pub fn message<T: Display + Debug>(self, message: T) -> Self
Adds a single message to the Whisper instance.
Arguments
message: The message to be added.
Returns
A Whisper instance with the added message.
Example
use murmur::Whisper;
let whisper = Whisper::new()
.message("1 message without icon")
.message("2 message")
.message("3 message")
.whisper()
.ok();Output
1 message without icon
2 message without icon indents by 2 spaces all messages after the first
3 message
sourcepub fn messages<I, S>(self, messages: I) -> Self
pub fn messages<I, S>(self, messages: I) -> Self
Adds multiple messages to the Whisper instance.
Arguments
messages: An iterable collection of items, each implementingDisplay,Debug, andAsRef<str>.
Returns a Whisper instance with the added messages.
Examples
use murmur::Whisper;
Whisper::new()
.messages(["1 message", "2 message", "3 message"])
.whisper()
.ok();
Whisper::new()
.messages(vec!["1 message", "2 message", "3 message"])
.whisper()
.ok();
Output
1 message
2 message
3 message
sourcepub fn whisper(&self) -> Result<(), WhisperError>
pub fn whisper(&self) -> Result<(), WhisperError>
The whisper function is responsible for building the Whisper instance and printing the messages.
It performs several steps to ensure the messages are printed correctly:
- It first tries to lock the
ICON_MAPto safely access the global variable in a concurrent environment. - If the lock is successfully acquired, it checks the
icon_kindfield of theWhisperinstance. - If
icon_kindisSome, it tries to get the corresponding icon and color from theicon_map. - If
icon_kindisNoneor if theicon_kinddoes not exist in theicon_map, it defaults to an empty string for bothiconandcolor. - Finally, it prints the messages with the specified color and an optional icon prefix.
Returns
This function returns a Result. If the operation is successful, it returns Ok(()). If there is an error during the operation, it returns WhisperError.
Errors
This function will return WhisperError::Lock if it fails to acquire a lock on the ICON_MAP.
It will return WhisperError::Print if there is an error while printing the messages.
Example
use murmur::{Whisper, IconKind};
use std::io::{Error, ErrorKind};
fn main() -> Result<(), Error> {
let whisper = Whisper::new()
.icon(IconKind::NfFaBug)
.message("test_whisper_unwrap")
.whisper()
.map_err(|err| Error::new(ErrorKind::Other, err))?;
Ok(())
}Trait Implementations§
source§impl PartialEq for Whisper
impl PartialEq for Whisper
impl Eq for Whisper
impl StructuralEq for Whisper
impl StructuralPartialEq for Whisper
Auto Trait Implementations§
impl RefUnwindSafe for Whisper
impl Send for Whisper
impl Sync for Whisper
impl Unpin for Whisper
impl UnwindSafe for Whisper
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moresource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more