printer

package
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: 8 Imported by: 0

Documentation

Overview

Package printer ports bat's printer module. It renders buffered input lines with bat's decorations (header, grid, line numbers, git change markers, snip separators), syntax-highlighted regions, tab expansion, non-printable notation, line wrapping and line highlighting. SimplePrinter implements the undecorated "cat" path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InteractivePrinter

type InteractivePrinter struct {
	// contains filtered or unexported fields
}

InteractivePrinter is the decorated, highlighted printer.

func NewInteractive

func NewInteractive(cfg config.Config, theme assets.Theme, changes map[int]decorations.ChangeKind) *InteractivePrinter

NewInteractive builds an InteractivePrinter. changes maps line numbers to git change kinds (may be nil). theme is the resolved highlighting theme.

func (*InteractivePrinter) PrintFooter

func (p *InteractivePrinter) PrintFooter(w io.Writer) error

PrintFooter prints the closing grid border.

func (*InteractivePrinter) PrintHeader

func (p *InteractivePrinter) PrintHeader(w io.Writer, name string, size int64, addPadding bool) error

PrintHeader prints the rule/grid and the filename/size header.

func (*InteractivePrinter) PrintLine

func (p *InteractivePrinter) PrintLine(w io.Writer, line Line) error

PrintLine prints one decorated, highlighted line.

func (*InteractivePrinter) PrintSnip

func (p *InteractivePrinter) PrintSnip(w io.Writer) error

PrintSnip prints the "8<" separator drawn between visible line ranges.

type Line

type Line struct {
	Number    int
	Raw       string // line content without trailing newline
	HadNewln  bool   // whether the original line ended with '\n'
	Segments  []assets.Segment
	Highlight bool // draw the line-highlight background
}

Line is a single buffered input line with its precomputed highlight segments.

type Printer

type Printer interface {
	PrintHeader(w io.Writer, name string, size int64, addPadding bool) error
	PrintFooter(w io.Writer) error
	PrintSnip(w io.Writer) error
	PrintLine(w io.Writer, line Line) error
}

Printer renders headers, footers, snip markers and lines.

type SimplePrinter

type SimplePrinter struct{}

SimplePrinter is the "cat" path: it writes raw line bytes unchanged.

func NewSimple

func NewSimple() *SimplePrinter

NewSimple returns a SimplePrinter.

func (*SimplePrinter) PrintFooter

func (p *SimplePrinter) PrintFooter(io.Writer) error

func (*SimplePrinter) PrintHeader

func (p *SimplePrinter) PrintHeader(io.Writer, string, int64, bool) error

func (*SimplePrinter) PrintLine

func (p *SimplePrinter) PrintLine(w io.Writer, line Line) error

PrintLine writes the raw line followed by a newline if the original had one.

func (*SimplePrinter) PrintSnip

func (p *SimplePrinter) PrintSnip(io.Writer) error

Jump to

Keyboard shortcuts

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