#fortune #quote #command-line #game #cli

app fortune-rs

A Rust implementation of the classic BSD fortune program

1 unstable release

new 0.1.0 Nov 26, 2024

#126 in Text processing

MIT license

57KB
1K SLoC

fortune-rs 🎲

Rust Crates.io Documentation build codecov dependency status MSRV License: MIT PRs Welcome

A modern, feature-rich implementation of the classic BSD fortune program in Rust. This implementation aims to be a drop-in replacement for traditional fortune programs on Unix-like systems while maintaining compatibility with various fortune database formats.

πŸ“‘ Table of Contents

✨ Features

  • πŸ”„ Full compatibility with traditional fortune program options
  • πŸ“š Support for multiple fortune database formats
  • πŸ” Pattern matching with regular expressions
  • πŸ“Š Weighted fortune selection
  • 🌳 Recursive directory searching
  • πŸ“ Precise control over fortune length
  • 🎨 Support for both regular and offensive fortunes
  • πŸ› Debug output for troubleshooting

πŸ“₯ Installation

From Source

# Clone the repository
git clone https://github.com/twang2218/fortune-rs.git

# Change into the directory
cd fortune-rs

# Build with optimizations
cargo build --release

The compiled binary will be available at target/release/fortune

πŸš€ Usage

Basic Usage

# Display a random fortune
fortune

# Display a random fortune from specific files or directories
fortune /path/to/fortune/file

# Display a random offensive fortune
fortune -o

Common Options

Option Description
-a Choose from all lists of maxims
-c Show the cookie file source
-f Print out the list of files
-o Choose only offensive fortunes
-s Display short fortunes only
-l Display long fortunes only
-n length Set length cutoff
-m pattern Display matching fortunes
-i Ignore case in pattern matching
-w Wait based on message length
-e Equal size file handling
-D Enable debugging output

Advanced Usage

# Pattern matching (case-insensitive)
fortune -i -m "pattern"

# Short fortunes only
fortune -s

# Show fortune sources
fortune -c

# List available fortune files
fortune -f

# Weighted selection
fortune 30% /path/to/fortunes1 70% /path/to/fortunes2

πŸ›  Development

Project Structure

fortune-rs/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ fortune.rs    # Main implementation
β”‚   β”œβ”€β”€ strfile.rs    # Database generator
β”‚   └── metadata.rs   # Metadata handling
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ integration.rs # Integration tests
β”‚   β”œβ”€β”€ data/         # Test files
β”‚   └── data2/        # Additional tests
└── Cargo.toml        # Project manifest

Building

# Debug build
cargo build

# Release build with optimizations
cargo build --release

Testing

# Run all tests
cargo test

Test Coverage

  • βœ… Pattern matching (-m)
  • βœ… Case-insensitive search (-i)
  • βœ… Length-based filtering (-l, -s, -n)
  • βœ… File listing (-f)
  • βœ… Weighted selection
  • βœ… Offensive fortunes (-o)
  • βœ… Equal-size handling (-e)

πŸ”§ Implementation Details

  • βœ… Compatible with traditional fortune database formats
  • βœ… Supports regular and offensive fortunes
  • βœ… Implements weighted selection
  • βœ… Pattern matching with regex
  • βœ… Recursive directory traversal
  • βœ… Multiple file formats and encodings
  • βœ… Strfile index compatibility

πŸ—Ί Roadmap

Current Status

  • βœ… Core Functionality

    • βœ… Random fortune display
    • βœ… Strfile index support
    • βœ… Directory searching
  • βœ… Traditional Options

    • βœ… Standard flags
    • βœ… Pattern matching
    • βœ… Length control
    • βœ… Debug output

Future Plans

  • πŸ”„ Modern Enhancements

    • ⏳ TOML configuration
    • ⏳ Embedded fortune database
  • πŸ“ˆ Project Growth

    • ⏳ Extended docs
    • βœ… Comprehensive testing
    • ⏳ CI/CD pipeline

πŸ‘₯ Contributing

We welcome contributions! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create a branch for your feature
  3. βœ… Add tests for new features
  4. πŸ§ͺ Ensure all tests pass
  5. πŸ“¬ Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“š References

Rust Implementations

Dependencies

~4–5.5MB
~99K SLoC