tnr 0.2.0

A macOS notification library and CLI tool using terminal-notifier
Documentation
  • Coverage
  • 0%
    0 out of 24 items documented0 out of 13 items with examples
  • Size
  • Source code size: 22.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 321.98 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • naoto0822/tnr
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • naoto0822

tnr

A macOS notification library and CLI tool that provides a simple interface to send notifications using terminal-notifier.

Features

  • đŸŽ¯ Simple and intuitive API
  • 🔧 Both CLI tool and Rust library
  • ✨ Support for different notification types (error, warning, info, success)
  • 🔗 Clickable notifications with URL support
  • đŸŽĩ Custom sounds for different notification types
  • đŸ“Ļ Zero external dependencies (except terminal-notifier)

Prerequisites

This tool requires terminal-notifier to be installed on your macOS system:

brew install terminal-notifier

System Configuration

To use terminal-notifier, you need to configure macOS notification settings:

  1. Open System Preferences → Notifications
  2. Find and select terminal-notifier
  3. Check "Allow Notifications"
  4. Set notification style (Banner/Alert) as needed

Installation

As a CLI tool

cargo install tnr

As a library dependency

Add this to your Cargo.toml:

[dependencies]
tnr = "0.1.0"

CLI Usage

# Basic notification
tnr --message "Hello, World!"

# Notification with title and type
tnr --title "Build Status" --message "Build completed successfully" --type success

# Notification with clickable URL
tnr --message "Check the results" --url "https://github.com"

# Error notification
tnr --message "Something went wrong" --type error

CLI Options

  • --title <TITLE>: Notification title
  • --message <MESSAGE>: Notification message (required)
  • --type <TYPE>: Notification type (error, warning, info, success)
  • --url <URL>: URL to open when notification is clicked

Library Usage

use tnr::{Notify, Type};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Basic notification
    Notify::new("Hello from Rust!")
        .send()?;
    
    // Notification with all options
    Notify::new("Task completed successfully!")
        .with_title("Build Status")
        .with_type(Type::Success)
        .with_url("https://github.com")
        .send()?;
    
    // Error notification
    Notify::new("Something went wrong")
        .with_type(Type::Error)
        .send()?;
    
    Ok(())
}

Available Notification Types

  • Type::Error - ❌ with "Sosumi" sound
  • Type::Warning - âš ī¸ with "Funk" sound
  • Type::Info - â„šī¸ with "Glass" sound
  • Type::Success - ✅ with "Hero" sound

API Documentation

Notify

The main struct for creating and sending notifications.

Methods

  • new(message: impl Into<String>) -> Self - Create a new notification with a message
  • with_title(self, title: impl Into<String>) -> Self - Set the notification title
  • with_type(self, notification_type: Type) -> Self - Set the notification type
  • with_url(self, url: impl Into<String>) -> Self - Set a URL to open when clicked
  • send(&self) -> Result<(), TnrError> - Send the notification

Type

Enum representing different types of notifications with associated emojis and sounds.

Error Handling

The library uses TnrError enum for error handling:

  • TnrError::ExecutionFailed - terminal-notifier execution failed
  • TnrError::CommandNotFound - terminal-notifier not found on system

Examples

See the examples/ directory for more usage examples.

License

MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.