Documentation ¶
Overview ¶
Package termdiff is a small utility designed to make it easy to print terminal-friendly diffs.
Index ¶
- func Fprint(w io.Writer, name string, diffs []Diff, opts ...Option)
- func Print(name string, diffs []Diff, opts ...Option)
- func Sprint(name string, diffs []Diff, opts ...Option) string
- type Diff
- type DiffType
- type Formatter
- type Option
- func WithAfterText(text string) Option
- func WithBeforeText(text string) Option
- func WithBuffer(buffer int) Option
- func WithDeleteLineFormatter(f Formatter) Option
- func WithDeleteTextFormatter(f Formatter) Option
- func WithEqualFormatter(f Formatter) Option
- func WithInsertLineFormatter(f Formatter) Option
- func WithInsertTextFormatter(f Formatter) Option
- func WithNameFormatter(f Formatter) Option
- type Printer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
Fprint writes a set of diffs for the given named entity to the given writer using the default configuration for printing. Configurations can be overridden using the various Option functions.
Types ¶
type Diff ¶
Diff holds a single diff with a type and text.
func DiffsFromDiffMatchPatch ¶
func DiffsFromDiffMatchPatch(diffs []diffmatchpatch.Diff) []Diff
DiffsFromDiffMatchPatch converts a set of diffmatchpatch.Diff diffs into their equivalent in this package to enable easy interoperability.
type DiffType ¶
type DiffType int
DiffType categorizes the kind of operation associated with a Diff.
type Option ¶
type Option func(p *Printer)
Option defines the contract for options to configure a Printer or a call to any of the functions like Print, Fprint and Sprint.
func WithAfterText ¶
WithAfterText customizes the text that appears in the diff header indicating what the logical "after" state in the diff means.
func WithBeforeText ¶
WithBeforeText customizes the text that appears in the diff header indicating what the logical "before" state in the diff means.
func WithBuffer ¶
WithBuffer customizes the number of lines with no insertions or deletions that will be printed both above and below each set of lines with diffs.
func WithDeleteLineFormatter ¶
WithDeleteLineFormatter customizes the text formatter/pretty printer used to format portions of a line with deleted text that are not themselves changed.
func WithDeleteTextFormatter ¶
WithDeleteTextFormatter customizes the text formatter/pretty printer used to format portions of a line where text has been deleted.
func WithEqualFormatter ¶
WithEqualFormatter customizes the text formatter/pretty printer used to format any text that is not associated with insertion or deletion.
func WithInsertLineFormatter ¶
WithInsertLineFormatter customizes the text formatter/pretty printer used to format portions of a line with inserted text that are not themselves changed.
func WithInsertTextFormatter ¶
WithInsertTextFormatter customizes the text formatter/pretty printer used to format portions of a line where text has been inserted.
func WithNameFormatter ¶
WithNameFormatter customizes the text formatter/pretty printer used to format the name of the text being diffed at the top of the overall diff.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer handles creating text-based diffs with several customization options. Use NewPrinter to create a printer that is pre-filled with the default options.
func NewPrinter ¶
NewPrinter creates a new Printer, optionally customized with the given options. This is primarily useful for scenarios where multiple diffs need to be printed with the same options. Consider using the top-level Print, Fprint and Sprint functions instead if you don't need to re-use customizations.
func (Printer) Fprint ¶
Fprint writes a set of diffs for the given named entity to the given writer. Options can be specified to override behaviors in the Printer.