$ show sharkdp/bat
bat is a command-line tool that serves as a drop-in replacement for `cat(1)` with syntax highlighting, Git integration, and automatic paging. Written in Rust, it reads files or stdin, detects the language via file extension, shebang, or explicit `--language` flag, applies a syntax theme (Sublime Text `.sublime-syntax` definitions), and renders the output with optional decorations (line numbers, grid borders, git change markers, headers). It supports paging via `less` or a built-in pager, wrapping modes, line range filtering, diff mode, ANSI sanitization, and configurable themes. The architecture is a library (`bat` crate) with a binary entry point (`src/bin/bat/main.rs`). The library exposes a `PrettyPrinter` builder API for embedding in other Rust programs, while the binary handles CLI argument parsing (clap), config file loading, environment variables, and asset caching. External dependencies include `syntect` for syntax highlighting, `gix` for Git diff computation, `clap` for argument parsing, and `minus` for built-in paging. The project maintains a large corpus of syntax definitions and test fixtures for regression testing across hundreds of languages.
The LLM identified 3 files worth highlighting for reuse:
A standalone ANSI/VT escape sequence parser that tokenizes input into structured `AnsiStyle` and `Attributes` objects. Handles SGR parameters, hyperlinks, charset selection, and reset sequences. The `EscapeSequenceIterator` and `EscapeSequenceOffsetsIterator` provide efficient streaming parsing. This module has no internal dependencies beyond standard library types and can be extracted into a reusable crate for any terminal-related tooling.
Implements flexible line range filtering with support for absolute ranges, relative-from-end ranges (e.g., `:10` for last 10 lines), and context syntax (`N::C` for N lines with C context, `N:M:C` for range with context). The `LineRanges` struct parses comma-separated range specifications and provides efficient checking. Self-contained with no internal dependencies, this module demonstrates careful parsing and boundary handling that could be reused in any tool needing line-based filtering.
Defines `StyleComponent` enum and `StyleComponentList` with additive/removal parsing (e.g., `+numbers`, `-grid`). The `to_components()` method resolves precedence and merges multiple sources (defaults, config, CLI). This module is self-contained and demonstrates a clean pattern for composable configuration that could be extracted for any application needing style or feature toggles with override semantics.