fortune-rs

Crates.iofortune-rs
lib.rsfortune-rs
version0.1.0
sourcesrc
created_at2024-11-26 08:51:58.081166
updated_at2024-11-26 08:51:58.081166
descriptionA Rust implementation of the classic BSD fortune program
homepagehttps://github.com/twang2218/fortune-rs
repositoryhttps://github.com/twang2218/fortune-rs
max_upload_size
id1461332
size90,546
Tao Wang (twang2218)

documentation

https://docs.rs/fortune-rs

README

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

Commit count: 34

cargo fmt