#icons #terminal #formatting #terminal-colors #nerdfonts #color

murmur

This library provides a simple and flexible way to format colored messages with optional NerdFonts or Unicode icons

6 stable releases

2.0.0 Dec 26, 2023
1.2.1 Dec 22, 2023
0.3.6 Dec 21, 2023
0.1.0 Nov 26, 2023

#864 in Command line utilities

Download history 649/week @ 2023-12-21 14/week @ 2024-01-18 122/week @ 2024-01-25 41/week @ 2024-02-01 21/week @ 2024-02-08 77/week @ 2024-02-15 4/week @ 2024-02-22 2/week @ 2024-02-29 11/week @ 2024-03-07 7/week @ 2024-03-14 55/week @ 2024-03-28 27/week @ 2024-04-04

92 downloads per month

MIT license

51KB
611 lines

murmur

GitHub Crates.io Documentation GitHub Actions License

A flexible library to build messages with NerdFonts or Unicode icons.

Table of Contents

  1. Intro
  2. IconKind Variants
  3. Whisper Methods
  4. WhisperError
  5. Examples

Intro

There is only a Whisper struct and an IconKind enum.

use murmur::{Whisper, IconKind};

IconKind Variants

The IconKind enum variants map to a specific Unicode or NerdFont icon, each icon has a default color. Casing conforms to Rust API Guidelines.

  • NfFaTimes
  • NfFaCheck
  • NfFaInfoCircle
  • NfFaRefresh
  • NfFaWarning
  • NfFaBug
  • UnicodeCrossMark
  • UnicodeCheckMark
  • UnicodeInformationSource
  • UnicodeGear
  • UnicodeWarningSign
  • UnicodeBug

For a full list of the currently supported icons, see the IconKind enum.

use murmur::{Whisper, IconKind};
use owo_colors::OwoColorize;

Whisper::new()
    .icon(IconKind::NfFaCheck)
    .message("message")
    .message("message".red())
    .whisper()
    .unwrap();


You must have NerdFonts installed to use the `Nf` variants.

Whisper methods:

The Whisper struct provides the following methods:

  • new(): Creates a new Whisper instance
  • .icon(): Adds an icon to the Whisper instance
  • .message(): Adds a message to the Whisper instance
  • .messages(): Adds multiple messages to the Whisper instance
  • .whisper(): Builds the Whisper instance and prints the messages

Here are some examples of how to use the Whisper struct.

new

use murmur::{Whisper, IconKind};

Whisper::new()
    .icon(IconKind::NfFaCheck)
    .message("message")
    .whisper()
    .ok();

icon

use murmur::{Whisper, IconKind};

Whisper::new().icon(IconKind::UnicodeCheckMark).whisper().ok();

message

use murmur::Whisper;
use std::io::{Error, ErrorKind};

fn main() -> Result<(), Error> {
    Whisper::new()
        .message("1 message")
        .message("2 message")
        .message("3 message")
        .whisper()
        .map_err(|err| Error::new(ErrorKind::Other, err))?;
    Ok(())
}

Output:

1 message without icon
  2 message without icon indents by 2 spaces all messages after the first
  3 message

messages

use murmur::Whisper;

Whisper::new()
    .messages(["1 message without icon", "2 message", "3 message"])
    .whisper()
    .ok();

Whisper::new()
    .messages(vec!["1 message without icon", "2 message", "3 message"])
    .whisper()
    .ok();

Whisper Error

The whisper method returns -> Result<(), WhisperError>

use murmur::{Whisper, IconKind, WhisperError};
use std::io::{Error, ErrorKind};

fn whisper_new() -> Result<(), WhisperError> {
    let whisper = Whisper::new()
        .icon(IconKind::NfFaBug)
        .message("The `whisper` method returns  `-> Result<(), WhisperError>`")
        .whisper()?;
    Ok(())
}

Dependencies

~0.5–1MB
~23K SLoC