Skip to main content

jt_consoleutils/
lib.rs

1//! Console and shell utilities for Rust CLI tools.
2//!
3//! `jt-consoleutils` provides a set of composable building blocks used across
4//! CLI tools in the `jt-*` ecosystem. Everything is designed to be testable:
5//! traits with mock/test implementations are provided for every abstraction
6//! that touches I/O or process execution.
7//!
8//! # Modules at a glance
9//!
10//! | Module | What it provides |
11//! |---|---|
12//! | [`output`] | [`output::Output`] trait, [`output::ConsoleOutput`], [`output::StringOutput`], [`output::OutputMode`] |
13//! | [`shell`] | [`shell::Shell`] trait, [`shell::ProcessShell`], [`shell::DryRunShell`], [`shell::MockShell`] |
14//! | [`colorize`] | Rainbow ANSI colorizer |
15//! | [`colors`] | ANSI escape-code constants |
16//! | [`help`] | Help / version printing helpers |
17//! | [`terminal`] | Terminal width detection |
18//! | [`str_utils`] | Human-readable byte formatting and other string helpers |
19//! | [`fs_utils`] | Filesystem comparison and permission helpers |
20//! | [`version`] | Build-info version string formatter |
21//! | `build_support` *(feature `build-support`)* | `build.rs` helper that emits `BUILD_DATE` / `GIT_HASH` |
22//!
23//! # Quick start — output
24//!
25//! ```rust
26//! use jt_consoleutils::output::{ConsoleOutput, Output, OutputMode};
27//!
28//! let mode = OutputMode { verbose: false, quiet: false, dry_run: false };
29//! let mut out = ConsoleOutput::new(mode);
30//! out.writeln("Hello, world!");
31//! ```
32//!
33//! # Quick start — shell
34//!
35//! ```rust
36//! use jt_consoleutils::shell;
37//! use jt_consoleutils::output::{StringOutput, OutputMode};
38//!
39//! let mode = OutputMode::default();
40//! let sh = shell::create(/*dry_run=*/ false);
41//! // sh is a Box<dyn Shell> backed by ProcessShell.
42//! ```
43
44#![warn(missing_docs)]
45
46/// Rainbow ANSI colorizer for terminal output.
47pub mod colorize;
48
49/// Raw ANSI escape-code constants (`RESET`, `BOLD`, `RED`, etc.).
50pub mod colors;
51
52/// Filesystem helpers: path comparison, permission bits, symlink removal.
53pub mod fs_utils;
54
55/// Help and version printing helpers for CLI entry points.
56pub mod help;
57
58/// The [`output::Output`] trait and its standard implementations.
59pub mod output;
60
61/// The [`shell::Shell`] trait and its standard implementations.
62pub mod shell;
63
64/// String formatting helpers: byte counts, plurals, path conversion.
65pub mod str_utils;
66
67/// Terminal introspection helpers (e.g. column width).
68pub mod terminal;
69
70/// Build-info version string formatter.
71pub mod version;
72
73#[cfg(feature = "build-support")]
74/// Build-script helper that emits `BUILD_DATE` and `GIT_HASH` env vars.
75pub mod build_support;