Pure source-annotated diagnostics for Lean 4 command-line tools. A diagnostic renders to
TermColor.Text; terminal IO remains outside the package.
Command-line tools need precise source context for errors without taking on terminal IO or a particular output policy.
This project is maintained by its author with AI-assisted development tools. Changes are reviewed, tested, and remain the maintainer's responsibility.
require termcolor-diagnostics from git
"https://github.com/jonaprieto/lean-termcolor-diagnostics.git" @ "v0.1.14"import TermColor.Diagnostics
import TermColor.Detect
open TermColor TermColor.Diagnostics
def sources : Sources := #[Source.named "settings.toml" "timeout = 2x"]
def diagnostic : Diagnostic :=
(Diagnostic.error "invalid duration")
|>.withCode "E1001"
|>.withLabel (Label.primary (Span.range 0 10 12) "expected a duration")
|>.withFixIt { span := Span.range 0 10 12, replacement := "2m" }
|>.withHelp "try timeout = 2m"
#eval Text.render RenderTarget.plain (render sources diagnostic)The model supports source spans, primary and secondary labels, notes, help, fix-its, multiple files, configurable context and width, color schemes, plain output, and optional OSC-8 links. Offsets are UTF-8 byte positions, matching byte-oriented parsers such as Grip.
lake build TermColor.Diagnostics TermColor.Diagnostics.Properties tests detect readme demo
lake exe tests
lake exe demogrip-diagnostics adapts Grip parse errors;
argus uses the renderer for command-line errors;
lean-calc-chat,
termcolor-layout, and
oatp consume it directly.
Apache-2.0.
