reformat

package
v0.0.0-...-c936f35 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package reformat provides a module that "wraps" an existing module and transforms it's output. This can be useful for adding extra formatting simple bar modules.

For example, a time module might use strftime-style format strings, which don't allow for colours or borders. You can add those using reformat:

t := localtime.New(...)
r := reformat.New(t).Format(func(o bar.Output) bar.Output {
  return o.Background("red").Padding(20)
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hide

func Hide(in bar.Segments) bar.Output

Hide replaces all outputs with nil, hiding them from the bar.

func Original

func Original(in bar.Segments) bar.Output

Original returns the original output unchanged.

func Texts

func Texts(f func(string) string) func(bar.Segments) bar.Output

Texts reformats a module's output with just the text content as input.

Types

type FormatFunc

type FormatFunc = func(bar.Segments) bar.Output

FormatFunc takes the module's output and returns a modified version.

func EachSegment

func EachSegment(f SegmentFunc) FormatFunc

EachSegment transforms each segment individually.

type Module

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

Module wraps a bar.Module with a re-formatting function.

func New

func New(original bar.Module) *Module

New wraps an existing bar.Module, allowing the format to be changed before being sent to the bar.

func (*Module) Format

func (m *Module) Format(f FormatFunc) *Module

Format sets the reformat function.

func (*Module) Stream

func (m *Module) Stream(s bar.Sink)

Stream sets up the output pipeline to filter outputs when hidden.

type SegmentFunc

type SegmentFunc func(*bar.Segment) *bar.Segment

SegmentFunc is a reformatting function at the segment level.

func SkipErrors

func SkipErrors(f SegmentFunc) SegmentFunc

SkipErrors wraps a segment transformation function so that error segments pass through unchanged.

Jump to

Keyboard shortcuts

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