editline

package
v0.0.0-...-7bff4ea Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action byte

Action returns the action that should be performed from the result of an edit.

const (
	// ReplaceEditMode indicates that the edit should be used to replace
	// the line.
	ReplaceAction Action = iota
	// RemoveAction indicates that the edit should be used to remove
	// the line.
	RemoveAction
)

type Editor

type Editor interface {
	// Edit edits and returns the provided line as well as a bool when, if true, would
	// remove the line from output.
	Edit(line string) (string, Action)
}

Editor is an editor for a line.

func Combine

func Combine(editors ...Editor) Editor

Combine combines multiple editors together.

func Prefix

func Prefix(prefix string, editor Editor) Editor

Prefix returns an Editor that conditionally executes based on whether the line has a prefix matching the specified prefix.

func Regexp

func Regexp(re *regexp.Regexp, editor Editor) Editor

Regexp returns an Editor that conditionally executes based on whether the line matches the regular expression.

func RegexpString

func RegexpString(pattern string, editor Editor) Editor

RegexpString is a helper for Regexp. It will panic if the pattern does not compile to a regexp.Regexp.

func Remove

func Remove() Editor

Replace returns an Editor that replaces a line with the provided string.

func ReplaceLiteral

func ReplaceLiteral(replacement string) Editor

ReplaceLiteral returns an Editor that replaces a line with the provided string.

func ReplaceRegexp

func ReplaceRegexp(re *regexp.Regexp, replacement string) Editor

ReplaceLiteral returns an Editor that replaces a line with the provided string.

func ReplaceRegexpString

func ReplaceRegexpString(pattern string, replacement string) Editor

ReplaceLiteral returns an Editor that replaces a line with the provided string.

type EditorFunc

type EditorFunc func(string) (string, Action)

EditorFunc is a functional implementation of an Editor.

func (EditorFunc) Edit

func (f EditorFunc) Edit(line string) (string, Action)

Edit implements the Editor interface.

type Prefixer

type Prefixer interface {
	Prefix() string
}

Prefixer allows an editor to provide a prefix in order to allow the Writer to optimize selecting the editors to run on a given line.

type Writer

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

Writer wraps another io.Writer and adds editing capabilities on a line by line basis.

func NewWriter

func NewWriter(w io.Writer, editors ...Editor) *Writer

NewWriter makes a Writer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes any buffered data to the underlying io.Writer.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write writes the provided data to the underlying io.Writer after passing it through the various line editors.

Jump to

Keyboard shortcuts

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