Documentation
¶
Overview ¶
Package stripes is a streaming, ANSI-colored pretty-printer for structured data formats: JSON, YAML, XML, HTML, CSV, protobuf, and plain text.
All renderers share a common shape:
stripes.JSON(w, r, &stripes.DefaultStyles)
where w is the styled output sink, r is the raw input stream, and the Styles value selects colors and layout. Func dispatches by MIME type, and Detect sniffs an unknown stream into a content-type string.
The companion command github.com/firetiger-oss/stripes/cmd/stripes is a file viewer that wraps these primitives with format auto-detection, TTY-aware coloring, and built-in paging.
Index ¶
- Variables
- func CSV(w io.Writer, r io.Reader, styles *Styles)
- func Detect(name string, peek []byte) string
- func Dockerfile(w io.Writer, r io.Reader, styles *Styles)
- func HTML(w io.Writer, r io.Reader, styles *Styles)
- func JSON(w io.Writer, r io.Reader, styles *Styles)
- func Markdown(w io.Writer, r io.Reader, styles *Styles)
- func NewPrefixWriter(writer io.Writer, prefix string) io.Writer
- func Plain(w io.Writer, r io.Reader, _ *Styles)
- func Text(w io.Writer, r io.Reader, styles *Styles)
- func XML(w io.Writer, r io.Reader, styles *Styles)
- func YAML(w io.Writer, r io.Reader, styles *Styles)
- type Renderer
- type Styles
Constants ¶
This section is empty.
Variables ¶
var DefaultStyles = &Styles{ Name: lipgloss.NewStyle().Foreground(lipgloss.Color("12")).Bold(true), Text: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), String: lipgloss.NewStyle().Foreground(lipgloss.Color("2")), Number: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), Boolean: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), Null: lipgloss.NewStyle().Foreground(lipgloss.Color("8")), Syntax: lipgloss.NewStyle().Foreground(lipgloss.Color("7")).Bold(true), Anchor: lipgloss.NewStyle().Foreground(lipgloss.Color("12")), Comment: lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Faint(true), Title: lipgloss.NewStyle().Foreground(lipgloss.Color("7")).Bold(true), Columns: lipgloss.NewStyle().Bold(true), Rows: lipgloss.NewStyle(), Border: lipgloss.NormalBorder(), Indent: " ", Width: 80, }
DefaultStyles provides a grayscale styling theme using shades of grey, dimming, and bold
Functions ¶
func Detect ¶
Detect resolves a content type for a stream.
The lookup order is:
- Filename extension (when name has a recognized extension).
- Magic-byte sniffing of peek (first ~512 bytes of the stream).
- net/http.DetectContentType fallback.
- "text/plain" if nothing else matched.
The returned string is a MIME media type compatible with Func. Empty name and nil peek both return "text/plain".
func Dockerfile ¶ added in v0.2.0
Dockerfile renders a Dockerfile (or Containerfile) with ANSI styling applied to instruction keywords, comments, flags, quoted strings, heredoc bodies, and line-continuation backslashes.
Parsing is done via github.com/moby/buildkit/frontend/dockerfile/parser so that line continuations, escape directives, parser directives, and heredocs are handled the same way docker build itself handles them.
Types ¶
type Renderer ¶
Renderer writes styled output for a single input format. All format functions in this package (JSON, YAML, XML, ...) match this signature.
func Code ¶ added in v0.2.0
Code returns a Renderer that highlights source code using the chroma lexer named lang. When lang is empty the renderer falls back to chroma's content-based language detection; if no lexer can be resolved the input is written verbatim.
func Func ¶
Func returns the Renderer matching contentType (a MIME media type), or nil if the content type is unsupported. For application/protobuf, schemaURL is interpreted as the full message name used to look up the descriptor in protoregistry.GlobalTypes / protoregistry.GlobalFiles; for other formats it is ignored.
func Protobuf ¶
func Protobuf(d protoreflect.MessageDescriptor, t protoregistry.MessageTypeResolver) Renderer
type Styles ¶
type Styles struct {
Name lipgloss.Style
Text lipgloss.Style
String lipgloss.Style
Number lipgloss.Style
Boolean lipgloss.Style
Null lipgloss.Style
Syntax lipgloss.Style
Anchor lipgloss.Style
Comment lipgloss.Style
Title lipgloss.Style
Columns lipgloss.Style
Rows lipgloss.Style
Border lipgloss.Border
Indent string
Width int
}
Styles defines the styling configuration for rendering various data types