Thanks to visit codestin.com
Credit goes to lib.rs

#card #divination

app tarot

A command-line tarot card reading application

1 unstable release

Uses new Rust 2024

0.4.0 Dec 2, 2025

#1207 in Command line utilities

AGPL-3.0-only

31KB
386 lines

๐Ÿ”ฎ Tarot Card Reader

A beautiful command-line tarot card reading application written in Rust. Draw random tarot cards and receive mystical insights with colorful, formatted output.

โœจ Features

  • ๐Ÿƒ Multi-Card Draws: Draw multiple unique cards for a more detailed reading.
  • ๐ŸŽด Complete Tarot Deck: Full 78-card tarot deck (22 Major Arcana + 56 Minor Arcana)
  • ๐ŸŽฒ Random Card Drawing: Statistically accurate card distribution
  • ๐Ÿ”„ Card Positions: Support for upright and reversed card positions
  • ๐ŸŽจ Beautiful Output: Colorful, well-formatted terminal display
  • ๐Ÿ“Š JSON Export: Machine-readable output for integrations
  • ๐Ÿงช Comprehensive Testing: Full test suite with 12 test cases
  • ๐Ÿ“– Rich Meanings: Detailed interpretations for all Major Arcana cards

๐Ÿš€ Installation

Prerequisites

  • Rust (2021 edition or later)
  • Cargo (comes with Rust)

Build from Source

git clone https://gitlab.com/dump-stuff/tarot.git 
cd tarot
cargo build --release

Run Directly

cargo run

๐ŸŽฏ Usage

Basic Usage

# Draw a random tarot card with beautiful formatting
tarot

# Example output:
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
#            โ™ฆ TAROT CARD READING โ™ฆ            
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# Card: The Fool
# Type: Major Arcana
# Position: Upright
# Meaning: Folly, mania, extravagance, intoxication, delirium, frenzy, bewrayment
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

Command Line Options

Flag Short Description
--help -h Show help message and usage information
--version -v Display version information
--json -j Output reading in JSON format
--number -n Set the number of cards to draw (default: 1)

Examples

# Show help
tarot --help

# Show version
tarot --version

# Get JSON output for programmatic use
tarot --json

# Draw 3 cards
tarot --number 3

# Short flags work too
tarot -h
tarot -v
tarot -j
tarot -n 5

๐ŸŽด Card Types

Major Arcana (22 cards)

Complete set of Major Arcana cards with detailed meanings:

  • The Fool, The Magician, The High Priestess, The Empress
  • The Emperor, The Hierophant, The Lovers, The Chariot
  • Strength, The Hermit, Wheel of Fortune, Justice
  • The Hanged Man, Death, Temperance, The Devil
  • The Tower, The Star, The Moon, The Sun
  • Judgement, The World

Minor Arcana (56 cards)

Four suits with 14 cards each:

  • Wands (Fire): Creativity, passion, energy
  • Cups (Water): Emotions, relationships, spirituality
  • Swords (Air): Thoughts, communication, conflict
  • Pentacles (Earth): Material, career, resources

Each suit contains: Ace, 2-10, Page, Knight, Queen, King

๐ŸŽจ Visual Features

  • Color-coded output: Different colors for card types and positions
  • Styled text: Bold headers, italic meanings, bright highlights
  • Centered layout: Professional-looking card reading display
  • Unicode symbols: Decorative elements (โ™ฆ, โ•) for visual appeal

๐Ÿ”ง Development

Running Tests

# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test
cargo test test_get_tarot_meaning_valid_card

CI/CD Pipeline

This project includes a comprehensive GitLab CI/CD pipeline (.gitlab-ci.yml) that:

  • โœ… Automated Testing: Runs tests, clippy, and formatting checks on all MRs
  • ๐Ÿ—๏ธ Release Builds: Creates optimized binaries on main branch merges
  • ๐Ÿ“ฆ Automatic Releases: Generates GitLab releases with artifacts

Project Structure

tarot/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ main.rs          # Main application code
โ”œโ”€โ”€ cards.json           # Tarot card meanings data
โ”œโ”€โ”€ .gitlab-ci.yml       # GitLab CI/CD pipeline configuration
โ”œโ”€โ”€ Cargo.toml           # Dependencies and metadata
โ”œโ”€โ”€ Cargo.lock           # Dependency lock file
โ”œโ”€โ”€ README.md            # This file
โ””โ”€โ”€ target/              # Build artifacts

Dependencies

  • rand = "0.8" - Random number generation for card drawing
  • colored = "2.0" - Terminal color and styling
  • serde = "1.0" - Serialization framework
  • serde_json = "1.0" - JSON serialization support
  • once_cell = "1.19.0" - Lazy initialization of static data

๐Ÿงช Testing

The project includes comprehensive tests covering:

  • โœ… Card meaning retrieval and validation
  • โœ… Random card drawing functionality
  • โœ… Case-insensitive card lookup
  • โœ… Error handling for invalid cards
  • โœ… JSON serialization
  • โœ… Text formatting and centering
  • โœ… All Major Arcana cards validation

Run cargo test to execute the full test suite.

๐Ÿ“Š API Reference

Core Functions

get_tarot_meaning(card_name: &str) -> Result<CardMeaning, String>

Retrieves the meaning for a specific tarot card.

draw_random_tarot_cards(count: usize) -> Vec<(String, &'static str)>

Draws a specified number of unique random cards from the full 78-card deck.

Data Structures

CardMeaning

pub struct CardMeaning {
    pub upright: String,
    pub reversed: String,
}

TarotReading (JSON output)

struct TarotReading {
    card: String,
    arcana_type: String,
    position: String,
    meaning: String,
}

๐ŸŽช Examples in Practice

Integration with Scripts

# Get a daily reading in JSON format
READING=$(tarot --json)
echo "Today's card: $(echo $READING | jq -r '.card')"

Sample JSON Output (for tarot -n 2 --json)

[
  {
    "card": "The Fool",
    "arcana_type": "Major Arcana",
    "position": "Upright",
    "meaning": "Folly, mania, extravagance, intoxication, delirium, frenzy, bewrayment"
  },
  {
    "card": "Three of Cups",
    "arcana_type": "Minor Arcana",
    "position": "Reversed",
    "meaning": "Independence, alone time, hardcore partying"
  }
]

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (cargo test)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

๐Ÿ“ License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the LICENSE file for details.

What this means:

  • โœ… You can freely use, modify, and distribute this software
  • โœ… You must share any modifications under the same license
  • โœ… If you use this in a network service, you must provide the source code to users
  • ๐Ÿšซ Commercial entities typically avoid AGPL due to its copyleft requirements

This license ensures the software remains free and open source while preventing proprietary commercialization.

๐Ÿ”ฎ Future Enhancements

  • Custom card spreads (Celtic Cross, Three Card, etc.)
  • Historical reading log
  • Card image display in terminal
  • Interactive card selection mode
  • Configuration file for custom meanings
  • Web API server mode
  • Multiple language support

๐Ÿ™ Acknowledgments

  • Tarot card meanings compiled from traditional interpretations
  • Built with the amazing Rust ecosystem
  • Colored terminal output powered by the colored crate

"The cards don't lie, but they do speak in riddles." ๐Ÿ”ฎ

Dependencies

~1โ€“12MB
~89K SLoC