Skip to content
nilzxPublic

About

rdice is a Rust workspace for reusable dice logic, a command-line tool, and a terminal UI.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

rdice

English | 中文

rdice is a Rust workspace for reusable dice logic, a command-line tool, and a terminal UI.

Projects

Project Type Package Output Publish target
rdice-core Library rdice-core Rust crate rdice_core crates.io
rdice-cli CLI rdice-cli rdice binary crates.io
rdice-tui TUI rdice-tui rdice-tui binary crates.io

Repository Layout

.
├── Cargo.toml
├── LICENSE
├── README.md
├── README_zh.md
├── crates/
│   ├── rdice-core/
│   ├── rdice-cli/
│   └── rdice-tui/
└── docs/
    ├── ARCHITECTURE.md
    └── RELEASING.md

Install

Install the command-line dice roller:

cargo install rdice-cli
rdice roll 3d6

Install the terminal UI:

cargo install rdice-tui
rdice-tui

Use the core library from another Rust project:

[dependencies]
rdice-core = "0.2"
use rdice_core::{DiceEngine, parse_roll_exprs};

fn main() -> Result<(), rdice_core::DiceError> {
    let engine = DiceEngine::new();
    let parsed = parse_roll_exprs(&["2d6", "3"])?;
    let dice = parsed
        .dice
        .iter()
        .map(|name| engine.resolve_die(name))
        .collect::<Result<Vec<_>, _>>()?;
    let analysis = engine.analyze_roll(&dice, &parsed.modifiers)?;

    assert_eq!(analysis.point_range.min, 5);
    Ok(())
}

Build

cargo build --workspace
cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings

CLI

rdice roll [-f|--folded] [-x|--expanded] [-E|--ev] [-R|--range] <dice-expr...>
rdice <analysis-option...> <dice-expr...>
rdice list
rdice config path
rdice config edit
rdice config check
rdice help [roll|list|config]
rdice --version

Examples:

rdice roll 5d6
rdice roll -x 4d6
rdice roll -f -E -R 3d13 2coin 5 -3
rdice -E -R 3d6 5 -3

The top-level form performs analysis without rolling and requires at least one of -E/--ev or -R/--range. Use rdice roll for an actual roll, and do not combine --folded with --expanded. Both rolling and analysis require at least one die; modifiers are not a standalone calculator. 3d13 rolls three dynamic numeric 13-sided dice, while 2coin rolls the configured coin die twice.

CLI output uses ANSI colors on terminals and disables them automatically for pipes or redirection. Pass --no-color or set NO_COLOR to disable color explicitly. The TUI also respects NO_COLOR.

Custom dice are loaded from RDICE_CONFIG_PATH when set, otherwise from:

~/.config/rdice/config.toml

Example config:

[[dice]]
name = "coin"
faces = ["heads", "tails"]

[[dice]]
name = "fate"
faces = [-1, 0, 1]

The CLI config remains a declarative definition source rather than a persisted engine state. Legacy custom names prefixed with ✽ are accepted by the CLI adapter without rewriting the config file. CLI die names cannot be empty, contain whitespace, be integers, or begin with an ASCII digit or -; they must also avoid ASCII case-insensitive conflicts with numeric and custom dice. These restrictions belong to the CLI adapter, not to rdice-core. Use rdice config check to validate the file after editing. If the optional file does not exist, the command reports that only built-in dice are active. Unknown TOML fields are rejected, and an explicitly set RDICE_CONFIG_PATH must not be empty.

TUI

rdice-tui is an interactive virtual tray workspace for persistent dice trays, repeated tray rolling, slot locking, and compact keyboard-driven operation.

The TUI state path can be overridden with RDICE_TUI_STATE_PATH; otherwise it uses:

~/.local/state/rdice-tui/state.toml

Legacy TUI state is migrated on first load. Duplicate legacy face values select the first matching index deterministically; this is necessarily lossy because the original physical face cannot be recovered. Unmatched values remain explicitly detached. Legacy custom names that conflict with 0.2 numeric or case-insensitive names retain a legacy-compatible ✽ name, and the migration warning reports the mapping. Legacy tray names that differ only by ASCII case keep the first spelling and receive deterministic ~N suffixes thereafter.

Start it with:

rdice-tui
rdice-tui --help
rdice-tui --version

The TUI derives page capacity from terminal width and height, so trays, slots, dice, and history remain reachable with PgUp/PgDn. State uses atomic replacement, legacy migration keeps a one-time .v0.bak backup beside the state file, and concurrent writers to the same state path are rejected. Guided custom-die creation and editing can move back before a final confirmation; deleting a non-empty tray also requires confirmation. q quits from normal screens; Ctrl+C quits from every screen and input mode. Detached current or historical values are labeled DETACHED, and attempts to delete an in-use custom die report the referencing Tray names.

Documentation

License

Licensed under the MIT License.

About

rdice is a Rust workspace for reusable dice logic, a command-line tool, and a terminal UI.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages