rubric

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 2 Imported by: 0

README

rubric

rubric is bat written in Go — a cat(1) clone with wings. It ports sharkdp/bat (reference: v0.26.1 in ref_impl/bat) to Go, aiming for feature parity while tracking the latest upstream behavior (e.g. no phantom git-change column, Size: in the full style) rather than the quirks of older releases.

Syntax highlighting and themes are provided by chroma (the Go analogue of Rust's syntect): ~296 languages and ~74 themes out of the box.

Build & run

go build -o rubric ./projects/rubric
./rubric src/main.go
./rubric --style=full --theme=GitHub README.md
git diff | ./rubric -l diff

Features

  • Syntax highlighting (language auto-detection by name, extension and content)
  • Themes (--theme, --list-themes; bat theme names aliased to chroma styles)
  • Decorations: line numbers, grid, header (filename/size), rule, snip (--style, with +add/-remove/override list semantics)
  • Git integration: +/~//_ change markers (--style=changes) via the git CLI; --diff / --diff-context to show only changed regions
  • Line ranges (-r, supports N, N:M, N:, :M, N:+K, N:-K, N::C, N:M:C, and end-relative :-K) and line highlighting (-H)
  • Wrapping (--wrap, character wrapping with a continuation gutter) and --chop-long-lines
  • Non-printable rendering (-A, --nonprintable-notation=unicode|caret)
  • Tab expansion (--tabs), squeeze blank lines (-s/--squeeze-limit)
  • Paging through less (--paging, --pager, -P); auto when interactive
  • Syntax mapping (-m '<glob>:<syntax>'), ignored suffixes (--ignored-suffix)
  • Config file ($BAT_CONFIG_PATH or ~/.config/rubric/config), --no-config
  • Env vars: BAT_THEME, BAT_STYLE, BAT_PAGER, PAGER, NO_COLOR, COLORTERM, COLUMNS
  • Reads files, multiple files (concatenation with per-file headers), and stdin
  • UTF-16 (LE/BE) and UTF-8 BOM decoding; binary detection + --binary=as-text
  • --strip-ansi, man-page overstrike stripping, word/character wrapping
  • Light/dark theme switching (--theme-light/--theme-dark, COLORFGBG)
  • Shell completions (--completion bash|zsh|fish), --acknowledgements, --diagnostic, --config-file/--config-dir/--cache-dir/ --generate-config-file, $LESSOPEN preprocessing, --set-terminal-title
Intentional divergence from bat

bat's cache subcommand (--build/--clear/--source/--target) builds and caches custom .sublime-syntax / .tmTheme assets. rubric uses chroma's bundled syntaxes and themes, so there is no asset-cache step; --no-custom-assets and --no-config are accepted, and --cache-dir still reports a path for tooling compatibility.

Architecture (goforge / Polylith)

The workspace is organized with goforge into single- responsibility components (each an interface package + private internal boundary), an entry-point base, and a deployable project. Run goforge check to validate boundaries, goforge info for the brick matrix.

Brick Role (bat module it ports)
config config.rs — Config struct, option enums, syntax mapping
style style.rs — StyleComponent set + list parsing
linerange line_range.rs — range parsing & membership
inputsrc input.rs — file / stdin / bytes sources
termdetect terminal width, tty, truecolor, color enablement
assets assets.rs — chroma lexer/theme lookup, styled segments
decorations decorations.rs — gutter elements
printer printer.rs — interactive + simple printers
pager output.rs — stdout vs less
gitdiff diff.rs — per-line git changes
controller controller.rs — orchestration
cli (base) bin/bat — flag surface, config building, wiring
rubric (project) the rubric binary

Tests

go test ./...
goforge check

Unit tests cover line-range parsing, the style-list precedence rules, and end-to-end rendering (numbers, ranges, grid/header, cat mode, -A).

Documentation

Overview

Command rubric is a cat(1) clone with wings — a Go port of bat with syntax highlighting, git integration, line numbers, paging and more.

This root entry point exists so `go install goforge.dev/rubric@latest` works. The canonical project lives under projects/rubric (goforge Polylith layout); both share the same bases/cli entry point.

Directories

Path Synopsis
bases
cli
Package cli is rubric's entry-point layer.
Package cli is rubric's entry-point layer.
components
assets
Package assets wraps the chroma syntax-highlighting engine to provide bat's asset layer: lexer (syntax) detection by language name, file name and content; theme (style) lookup with bat-compatible theme-name aliases; and the per-line styled-segment output the printer consumes.
Package assets wraps the chroma syntax-highlighting engine to provide bat's asset layer: lexer (syntax) detection by language name, file name and content; theme (style) lookup with bat-compatible theme-name aliases; and the per-line styled-segment output the printer consumes.
config
Package config ports bat's config module: the central Config struct plus the option enums (paging, wrapping, non-printable notation, binary behavior, strip-ansi, visible lines) and the SyntaxMapping used to override language detection by glob.
Package config ports bat's config module: the central Config struct plus the option enums (paging, wrapping, non-printable notation, binary behavior, strip-ansi, visible lines) and the SyntaxMapping used to override language detection by glob.
controller
Package controller ports bat's controller module: it drives the whole pipeline for each input — open and buffer it, detect the syntax (honoring language overrides, syntax mappings and ignored suffixes), highlight it, gather git changes, then walk the lines emitting headers, snip separators, highlighted content and footers through the printer.
Package controller ports bat's controller module: it drives the whole pipeline for each input — open and buffer it, detect the syntax (honoring language overrides, syntax mappings and ignored suffixes), highlight it, gather git changes, then walk the lines emitting headers, snip separators, highlighted content and footers through the printer.
decorations
Package decorations ports bat's decorations module: the gutter elements drawn to the left of each line (line numbers, git change markers, grid border).
Package decorations ports bat's decorations module: the gutter elements drawn to the left of each line (line numbers, git change markers, grid border).
gitdiff
Package gitdiff ports bat's diff module: it computes per-line modifications (added / removed / modified) between a file's working-tree state and the git index, so the printer can draw change markers in the gutter.
Package gitdiff ports bat's diff module: it computes per-line modifications (added / removed / modified) between a file's working-tree state and the git index, so the printer can draw change markers in the gutter.
inputsrc
Package input ports bat's input module: the description of an input source (an ordinary file, standard input, or in-memory bytes), how it is opened for reading, and the display name / size metadata the printer needs for headers.
Package input ports bat's input module: the description of an input source (an ordinary file, standard input, or in-memory bytes), how it is opened for reading, and the display name / size metadata the printer needs for headers.
linerange
Package linerange ports bat's line_range module: parsing of "N", "N:M", "N:", ":M", "N:+K", "N:-K", "N::C", "N:M:C" and end-relative ":-K"/"K:" offsets, plus the LineRanges / HighlightedLineRanges containers used to decide which lines are visible or highlighted.
Package linerange ports bat's line_range module: parsing of "N", "N:M", "N:", ":M", "N:+K", "N:-K", "N::C", "N:M:C" and end-relative ":-K"/"K:" offsets, plus the LineRanges / HighlightedLineRanges containers used to decide which lines are visible or highlighted.
pager
Package output ports bat's output module: it decides whether to write to stdout directly or through a pager (less by default), builds the correct less arguments, and exposes a single io.Writer plus Close that waits for the pager to exit.
Package output ports bat's output module: it decides whether to write to stdout directly or through a pager (less by default), builds the correct less arguments, and exposes a single io.Writer plus Close that waits for the pager to exit.
printer
Package printer ports bat's printer module.
Package printer ports bat's printer module.
style
Package style ports bat's style module: the StyleComponent enum, the StyleComponents set queried by the printer, and the StyleComponentList parser that understands override / "+add" / "-remove" semantics.
Package style ports bat's style module: the StyleComponent enum, the StyleComponents set queried by the printer, and the StyleComponentList parser that understands override / "+add" / "-remove" semantics.
termdetect
Package terminfo detects terminal properties bat relies on: whether stdout/ stdin are interactive ttys, the terminal width, true-color support and whether color output should be enabled at all.
Package terminfo detects terminal properties bat relies on: whether stdout/ stdin are interactive ttys, the terminal width, true-color support and whether color output should be enabled at all.
Package development wires every brick into one place for IDE and REPL use.
Package development wires every brick into one place for IDE and REPL use.
projects
rubric command
Command rubric is a cat(1) clone with wings — a Go port of bat with syntax highlighting, git integration, line numbers, paging and more.
Command rubric is a cat(1) clone with wings — a Go port of bat with syntax highlighting, git integration, line numbers, paging and more.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL