Crate unicode_rs

Source
Expand description

§Unicode-rs

A comprehensive Unicode character library for Rust applications, particularly useful for terminal applications, editors, and CLI tools that need consistent Unicode symbol support across different environments and themes.

§Features

  • Multiple themes: Support for Minimal (ASCII), Basic, Rich, and Fancy Unicode themes
  • Categorized symbols: Organized into logical groups (arrows, blocks, shapes, git, etc.)
  • Fallback support: Graceful degradation to ASCII when Unicode isn’t supported
  • Global configuration: Set theme and overrides globally for your application
  • Type-safe: All symbols are strongly typed enums

§Quick Start

use unicode_rs::prelude::*;

// Use with default theme (Rich)
let check = Symbol::Check.get_char(UnicodeTheme::Rich); // ✓
let arrow = Arrow::Right.get_char(UnicodeTheme::Rich);  // →

// Configure globally
set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Minimal));
let check_ascii = get_char(&Symbol::Check, None); // v

§Theme Comparison

SymbolMinimalBasicRichFancy
Checkv
Arrow Right>
Git ModifiedM

§Advanced Usage

§Custom Configuration

use unicode_rs::prelude::*;

// Create a config with fallback and custom overrides
let config = UnicodeConfig::with_theme(UnicodeTheme::Rich)
    .with_fallback()  // Fall back to ASCII if Unicode fails
    .with_override("custom_bullet", '•');

set_global_config(config);

§Terminal Compatibility

use unicode_rs::prelude::*;

// Detect terminal capabilities and choose appropriate theme
let theme = if std::env::var("TERM").unwrap_or_default().contains("xterm") {
    UnicodeTheme::Rich
} else {
    UnicodeTheme::Minimal
};

set_global_config(UnicodeConfig::with_theme(theme));

§Modules

  • symbols - General symbols (checkmarks, exclamation, etc.)
  • arrows - Directional arrows and navigation symbols
  • blocks - Block drawing characters
  • shapes - Geometric shapes
  • git - Git status and diff symbols
  • file_types - File type indicators
  • ui - UI elements (borders, separators, etc.)
  • editor - Editor-specific symbols (cursor, selection)
  • status - Status indicators
  • security - Unicode security utilities for detecting dangerous characters

Re-exports§

pub use unicode::*;

Modules§

prelude
Prelude module for convenient imports
unicode
Unicode character library for the editor Provides categorized Unicode characters for consistent visual design