formatter

package
v0.0.0-...-0efc7b6 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Unlicense Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(message string) string

Escapes "<" special char in given text.

func EscapeTrailingBackslash

func EscapeTrailingBackslash(message string) string

Escapes trailing "\" in given text.

Types

type OutputFormatter

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

Formatter class for console output.

func NewOutputFormatter

func NewOutputFormatter() *OutputFormatter

output formatter constructor

func (*OutputFormatter) FindTagsInString

func (o *OutputFormatter) FindTagsInString(text string) []TagPos

Make a tagMap from a message

func (*OutputFormatter) Format

func (o *OutputFormatter) Format(message string) string

Formats a message according to the given styles.

func (*OutputFormatter) GetStyle

func (o *OutputFormatter) GetStyle(name string) *OutputFormatterStyle

Gets style from cache with specified name.

func (*OutputFormatter) GetStyleStack

func (o *OutputFormatter) GetStyleStack() *OutputFormatterStyleStack

Gets style stack

func (*OutputFormatter) HasStyle

func (o *OutputFormatter) HasStyle(name string) bool

Checks if output formatter has style in cache with specified name.

func (*OutputFormatter) IsDecorated

func (o *OutputFormatter) IsDecorated() bool

Gets the decorated flag.

func (*OutputFormatter) SetDecorated

func (o *OutputFormatter) SetDecorated(decorated bool)

Sets the decorated flag.

func (*OutputFormatter) SetStyle

func (o *OutputFormatter) SetStyle(name string, style OutputFormatterStyle)

Sets a new style to cache.

type OutputFormatterInterface

type OutputFormatterInterface interface {
	// Sets the decorated flag.
	SetDecorated(decorated bool)

	// Gets the decorated flag.
	IsDecorated() bool

	// Sets a new style to cache.
	SetStyle(name string, style OutputFormatterStyle)

	// Gets style from cache with specified name.
	GetStyle(name string) *OutputFormatterStyle

	// Gets style stack
	GetStyleStack() *OutputFormatterStyleStack

	// Checks if output formatter has style in cache with specified name.
	HasStyle(name string) bool

	// Formats a message according to the given styles.
	Format(message string) string

	// Return a list of tags found in the given text.
	FindTagsInString(text string) []TagPos
}

Formatter interface for console output

type OutputFormatterStyle

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

Formatter style class for defining styles

func NewOutputFormatterStyle

func NewOutputFormatterStyle(
	foreground string,
	background string,
	options []string,
) *OutputFormatterStyle

Formatter style constructor

func (*OutputFormatterStyle) Apply

func (style *OutputFormatterStyle) Apply(text string) string

Applies the style to a given text.

func (*OutputFormatterStyle) SetBackground

func (style *OutputFormatterStyle) SetBackground(name string)

Sets style background color.

func (*OutputFormatterStyle) SetForeground

func (style *OutputFormatterStyle) SetForeground(name string)

Sets style foreground color.

func (*OutputFormatterStyle) SetOption

func (style *OutputFormatterStyle) SetOption(name string)

Sets some specific style option.

func (*OutputFormatterStyle) SetOptions

func (style *OutputFormatterStyle) SetOptions(options []string)

Sets multiple style options at once.

func (*OutputFormatterStyle) UnsetOption

func (style *OutputFormatterStyle) UnsetOption(name string)

Unsets some specific style option.

type OutputFormatterStyleStack

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

Formatter style stack class for defining styles

func NewOutputFormatterStyleStack

func NewOutputFormatterStyleStack(style *OutputFormatterStyle) *OutputFormatterStyleStack

output formatter style constructor

func (*OutputFormatterStyleStack) GetCurrent

func (stack *OutputFormatterStyleStack) GetCurrent() *OutputFormatterStyle

Computes current style with stacks top codes

func (*OutputFormatterStyleStack) GetDefaultStyle

func (stack *OutputFormatterStyleStack) GetDefaultStyle() *OutputFormatterStyle

get default style

func (*OutputFormatterStyleStack) Pop

Pops a style from the stack, pop the first if style equal nil.

func (*OutputFormatterStyleStack) Push

func (stack *OutputFormatterStyleStack) Push(style *OutputFormatterStyle)

Pushes a style in the stack.

func (*OutputFormatterStyleStack) Reset

func (stack *OutputFormatterStyleStack) Reset()

Resets stack (ie. empty internal arrays).

func (*OutputFormatterStyleStack) SetDefaultStyle

func (stack *OutputFormatterStyleStack) SetDefaultStyle(style OutputFormatterStyle)

set default style

type TagPos

type TagPos struct {
	Text    string
	Tag     string
	Style   string
	Start   int
	End     int
	Opening bool
}

struct to describe a color tag

Jump to

Keyboard shortcuts

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