How sharkdp/bat works
bat is a terminal file viewer and cat replacement. A user invokes the CLI with files or piped input; the application configures a controller, which opens inputs, optionally preprocesses them, and prints highlighted or plain output. Output may include Git change markers, non-printable notation, line selection and decorations, and can go to stdout or a pager. The README documents these capabilities; some subsystem links below rely on that documentation because their implementation paths were not sampled.
Main entry points: controller.rs Run controller · printer.rs Content printer · main.rs CLI entry · output.rs Output routing
Components 18
CLI and orchestration
- CLI entry
src/bin/bat/main.rs - CLI application
src/bin/bat/app.rs - Configuration
src/config.rs - Run controller
src/controller.rs
Input and highlighting
- Input reader
src/input.rs - LESSOPEN adapter
src/lessopen.rs - Highlight assets
src/assets.rs - Syntax mapping
src/syntax_mapping.rs
Rendering and features
- Content printer
src/printer.rs - Text preprocessing
src/preprocessor.rs - Git changes
src/diff.rs - Line ranges
src/line_range.rs - Style components
src/style.rs
Output and paging
- Output routing
src/output.rs - Pager selection
src/pager.rs
Other components
- User
- Terminal
- Git
Connections 19
- User → CLI entry: invokes
README.md - CLI entry → CLI application: dispatches
src/bin/bat/main.rs - CLI entry → Run controller: runs
src/bin/bat/main.rs - CLI application → Configuration: configures
src/bin/bat/app.rs - Run controller → Configuration: uses
src/controller.rs - Run controller → Input reader: opens
src/controller.rs - Run controller → LESSOPEN adapter: optionally opens
src/controller.rs - Run controller → Content printer: prints
src/controller.rs - Run controller → Git changes: gets changes
src/controller.rs - Highlight assets → Syntax mapping: maps syntax
src/assets.rs - Content printer → Highlight assets: selects highlighting
src/printer.rs - Content printer → Text preprocessing: sanitizes text
src/printer.rs - Content printer → Line ranges: limits lines
src/printer.rs - Content printer → Style components: formats components
src/printer.rs - Content printer → Git changes: renders changes
src/printer.rs - Run controller → Output routing: writes output
src/controller.rs - Output routing → Pager selection: selects pager
src/output.rs - Output routing → Terminal: writes to
README.md - Git changes → Git: reads index
README.md