Documentation ¶
Index ¶
- Constants
- Variables
- func AddPostFilter(filter PostFilter)
- func ClearPostFilters()
- func Content() string
- func CtxOut(msg ...interface{})
- func CutNotifier(notifier string) string
- func Extend() string
- func Fill(with string) string
- func FilterId() string
- func FitWordsToMaxLen(line string, max int) string
- func Fixed() string
- func ForceFilterUpdate(info PostFilterInfo)
- func GetLastEscapeSequence(text string) string
- func GetRunInfos() []string
- func GetRunInfosF(pattern string) []string
- func HaveBasicColors(input string) bool
- func IsPrinterInterface(msg interface{}) bool
- func Left() string
- func Margin(margin int) string
- func MarkupFilter(msg string) string
- func Message(msg ...interface{}) []interface{}
- func NewRoundSerial() *roundSerial
- func NewTabCell(parent *tabRow) *tabCell
- func NewTabRow(parent *tableHandle) *tabRow
- func NewTableHandle(parent *TabOut) *tableHandle
- func Origin(origin int) string
- func Overflow(mode string) string
- func OverflowContent(content string) string
- func OverflowIgnore() string
- func OverflowWordWrap() string
- func OverflowWrap() string
- func PadStrLeft(line string, max int, fillChar string) string
- func PadStrRight(line string, max int, fillChar string) string
- func PostMarkupFilter(msgSlice []interface{}) []interface{}
- func Print(msg ...interface{})
- func PrintLn(msg ...interface{})
- func Prop(name string, value interface{}) string
- func Relative() string
- func Right() string
- func Round(percentage int, max int) int
- func RoundHelp(percentage int, max int) (intResult int, result float64, rest float64)
- func RoundHelpWithOffest(percentage int, max int, offset float64) (intResult int, result float64, rest float64)
- func Row(cells ...string) string
- func SetBehavior(behave CtxOutBehavior)
- func Size(size int) string
- func StringCleanEscapeCodes(s string) string
- func StringCut(s string, size int) (cutStr string, rest string)
- func StringCutFromRight(s string, size int) (cutStr string, rest string)
- func StringPure(s string) string
- func TD(content interface{}, props ...string) string
- func Tab(size int) string
- func TabF(props ...string) string
- func Table(rows ...string) string
- func ToString(msg ...interface{}) string
- func UniseqLen(s string) int
- func UpdateFilterByName(nameOfFilter string, info PostFilterInfo) error
- func UpdateFilterByRef(filter PostFilter, info PostFilterInfo) error
- func VisibleLen(s string) int
- type BasicColors
- type CtxOutBehavior
- type CtxOutCtrl
- type CtxOutLabel
- type CursorFilter
- type FmtWarper
- type MOWrap
- type Markup
- func (m *Markup) BuildInnerSlice(parsed []Parsed, outerMarkup string) ([]Parsed, []Parsed)
- func (m *Markup) BuildInnerSliceEach(parsed []Parsed, outerMarkup string, handleFn func(markup []Parsed) bool) []Parsed
- func (m *Markup) Parse(orig string) []Parsed
- func (m *Markup) SetAccepptedTags(tags []string) *Markup
- func (m *Markup) SetCloseIdent(token rune) *Markup
- func (m *Markup) SetEndToken(token rune) *Markup
- func (m *Markup) SetStartToken(token rune) *Markup
- type Parsed
- type PostFilter
- type PostFilterInfo
- type PrintInterface
- type Sign
- type SignFilter
- func (sf *SignFilter) AddSign(sign Sign) *SignFilter
- func (sf *SignFilter) CanHandleThis(text string) bool
- func (sf *SignFilter) Command(cmd string) string
- func (sf *SignFilter) Disable()
- func (sf *SignFilter) Enable()
- func (sf *SignFilter) Enabled() bool
- func (sf *SignFilter) ForceEmpty(forceEmpty bool)
- func (sf *SignFilter) GetSign(name string) Sign
- func (sf *SignFilter) Update(info PostFilterInfo)
- type SignSet
- type StreamInterface
- type TabOut
- func (t *TabOut) CanHandleThis(text string) bool
- func (t *TabOut) Clear()
- func (t *TabOut) Command(cmd string) string
- func (t *TabOut) Filter(msg interface{}) interface{}
- func (t *TabOut) GetInfo() PostFilterInfo
- func (t *TabOut) GetRoundTool() *roundSerial
- func (t *TabOut) GetSize(orig int) int
- func (t *TabOut) IsRow(text string) bool
- func (t *TabOut) IsTab(text string) bool
- func (t *TabOut) IsTable(text string) bool
- func (t *TabOut) RowParse(text string) string
- func (t *TabOut) ScanForCells(tokens []Parsed, table *tableHandle) *tabRow
- func (t *TabOut) ScanForRows(tokens []Parsed) *tableHandle
- func (t *TabOut) TableParse(text string) string
- func (t *TabOut) Update(info PostFilterInfo)
Constants ¶
const ( BaseSignInfo = "<sign info>" BaseSignWarning = "<sign warning>" BaseSignError = "<sign error>" BaseSignSuccess = "<sign success>" BaseSignDebug = "<sign debug>" BaseSignScreen = "<sign screen>" )
const ( OpenTable = "<table>" TO = "<table>" CloseTable = "</table>" TC = "</table>" OpenRow = "<row>" RO = "<row>" CloseRow = "</row>" CR = "</row>" OpenTab = "<tab>" OTB = "<tab>" CloseTab = "</tab>" CTB = "</tab>" CloseTabRow = "</tab></row>" CTR = "</tab></row>" CloseTabRowTable = "</tab></row></table>" CTRT = "</tab></row></table>" OpenTableRow = "<table><row>" OTR = "<table><row>" CloseRowTable = "</row></table>" CRT = "</row></table>" )
just shortcuts for table tags
const ( TableStart = "<table" TableEnd = "</table>" RowStart = "<row>" RowEnd = "</row>" TabStart = "<tab" TabEnd = "</tab>" // defines the size of the cell in relation to the max length of the screen. 10 means 10% of the screen AttrSize = "size" // defines the char if the cell should fill the remaining space of the cell // default is " " (space) ATTR_FILL = "fill" // defines how the cell should be aligned // 1 = left, 2 = right AttrOrigin = "origin" // defines how the space is calculated. // fixed = if the calculated size is bigger than the cell size, then we will use the cell size // extend = fill the rest of the row with the space if prevoius fixed or content cells are smaller than the calculated size // content = we will use the max size of the content if they is smaller than the calculated size AttrDraw = "draw" DrawFixed = "fixed" DrawExtend = "extend" DrawContent = "content" // if the text is cutted, then this string will be added to the end of the text AttrCutAdd = "cut-add" // this is the mode how the overflow is handled. ignore = the text is ignored, wrap = wrap the text AttrOverflow = "overflow" // this is the suffix for the cell that will be added to the content all the time. is ment for colorcodes. here and clear code is usually used AttrSuffix = "suffix" // this is the prefix for the cell that will be placed in front of the content all the time. is ment for colorcodes AttrPrefix = "prefix" // additonal margin for the cell. this will be subtracted from the cell size AttrMargin = "margin" // overflow constants OfIgnore = "ignore" OfWrap = "wrap" OfWordWrap = "wordwrap" OfAny = "any" // origin constants OriginLeft = 0 OriginRight = 2 )
const ( // terminal reset code ResetCode = "\033[0m" // CleanTag is the tag to reset to default CleanTag = "</>" // ForeBlack black foreground color ForeBlack = "<f:black>" // ForeRed red foreground color ForeRed = "<f:red>" // ForeGreen red foreground color ForeGreen = "<f:green>" // ForeYellow red foreground color ForeYellow = "<f:yellow>" // ForeBlue red foreground color ForeBlue = "<f:blue>" // ForeMagenta red foreground color ForeMagenta = "<f:magenta>" // ForeCyan red foreground color ForeCyan = "<f:cyan>" // ForeLightGrey red foreground color ForeLightGrey = "<f:light-grey>" // ForeDarkGrey red foreground color ForeDarkGrey = "<f:dark-grey>" // ForeLightRed red foreground color ForeLightRed = "<f:light-red>" // ForeLightGreen red foreground color ForeLightGreen = "<f:light-green>" // ForeLightYellow red foreground color ForeLightYellow = "<f:light-yellow>" // ForeLightBlue red foreground color ForeLightBlue = "<f:light-blue>" // ForeLightCyan red foreground color ForeLightCyan = "<f:light-cyan>" // ForeLightMagenta red foreground color ForeLightMagenta = "<f:light-magenta>" // ForeWhite red foreground color ForeWhite = "<f:white>" // BoldTag writes bolder text BoldTag = "<b>" // Dim dim Dim = "<dim>" // Underlined tag Underlined = "<u>" // Reverse tag Reverse = "<r>" // Hidden tag Hidden = "<hide>" // ResetBold tag ResetBold = "</b>" // ResetDim tag ResetDim = "</dim>" // ResetUnderline tag ResetUnderline = "</u>" //ResetReverse tag ResetReverse = "</r>" //ResetHidden tag ResetHidden = "</hide>" // BackBlack black Background color BackBlack = "<b:black>" // BackRed red Background color BackRed = "<b:red>" // BackGreen red Background color BackGreen = "<b:green>" // BackYellow red Background color BackYellow = "<b:yellow>" // BackBlue red Background color BackBlue = "<b:blue>" // BackMagenta red Background color BackMagenta = "<b:magenta>" // BackCyan red Background color BackCyan = "<b:cyan>" // BackLightGrey red Background color BackLightGrey = "<b:light-grey>" // BackDarkGrey red Background color BackDarkGrey = "<b:dark-grey>" // BackLightRed red Background color BackLightRed = "<b:light-red>" // BackLightGreen red Background color BackLightGreen = "<b:light-green>" // BackLightYellow red Background color BackLightYellow = "<b:light-yellow>" // BackLightBlue red Background color BackLightBlue = "<b:light-blue>" // BackLightCyan red Background color BackLightCyan = "<b:light-cyan>" // BackLightMagenta red Background color BackLightMagenta = "<b:light-magenta>" // BackWhite red Background color BackWhite = "<b:white>" )
Variables ¶
var ( // NotFoundSign is the sign that is returned if the sign is not found NotFoundSign = Sign{ Name: "notfound", Glyph: "?", Fallback: "[?]", } )
var ( // PreHook is a function that can be used to intercept the message before it is printed // it is a very simple way to hook in the whole output process. // the return value is a bool. if false is returned the message will not be longer processed. // if true is returned the message will be processed further. // use this function with care. it is ment for testing or debugging. // an simple example is: // // messages := []string{} // ctxout.PreHook = func(msg ...interface{}) bool { // messages = append(messages, ctxout.ToString(msg...)) // return true // } // ctxout.Print("hello world") // // now you can inspect the messages slice PreHook func(msg ...interface{}) bool = nil )
Functions ¶
func AddPostFilter ¶
func AddPostFilter(filter PostFilter)
AddPostFilter adds a post filter to the list of post filters these filters are called after the markup filter they works only on strings
func CutNotifier ¶
func FitWordsToMaxLen ¶
FitWordsToMaxLen fits the words of a string to the given max length and add a new line if the word would exceed the max length and then proceed with the next line until the string is done if the string contains words, they are longer than the max length then the words will not be cutted. they will be placed on a new line. result := ctxout.FitWordsToMaxLen("ab 1234567890 cdef", 5) result will be "ab\n1234567890\ncdef"
func ForceFilterUpdate ¶
func ForceFilterUpdate(info PostFilterInfo)
Updates all registered post filters with the new terminal information
func GetLastEscapeSequence ¶
func GetRunInfos ¶
func GetRunInfos() []string
GetRunInfos returns the list of run infos while the message is processed, we add infos to this list
func GetRunInfosF ¶
GetRunInfosF returns the list of run infos but only the ones that contains the pattern
func HaveBasicColors ¶
func IsPrinterInterface ¶
func IsPrinterInterface(msg interface{}) bool
func MarkupFilter ¶
MarkupFilter is the function that will be called by the Message function it handles the filtering of the message depending on the type of the message.
func Message ¶
func Message(msg ...interface{}) []interface{}
Message is the function that will be called by the Print and PrintLn functions it handles the filtering and streaming of the message depending on the type of the message. so here er can also inject the filters and the output stream
func NewRoundSerial ¶
func NewRoundSerial() *roundSerial
func NewTabCell ¶
func NewTabCell(parent *tabRow) *tabCell
func NewTableHandle ¶
func NewTableHandle(parent *TabOut) *tableHandle
func OverflowContent ¶
func OverflowIgnore ¶
func OverflowIgnore() string
func OverflowWordWrap ¶
func OverflowWordWrap() string
func OverflowWrap ¶
func OverflowWrap() string
func PadStrLeft ¶
PadStrLeft is a shortcut for PadString on a cell
func PadStrRight ¶
PadStrRight is a shortcut for PadString on a cell
func PostMarkupFilter ¶
func PostMarkupFilter(msgSlice []interface{}) []interface{}
func Print ¶
func Print(msg ...interface{})
Print is parsing the message and then printing it by using the output interface if is defined or by using the fmt.Print function
func PrintLn ¶
func PrintLn(msg ...interface{})
PrintLn is parsing the message and then printing it by using the output interface if is defined or by using the fmt.Println function
func RoundHelpWithOffest ¶
func SetBehavior ¶
func SetBehavior(behave CtxOutBehavior)
func StringCleanEscapeCodes ¶
func StringCut ¶
splits a string into two parts. one part is the cut string, the other part is the rest the cut string is the first part of the string with the given size the rest is the remaining part of the string
func StringCutFromRight ¶
splits a string into two parts. one part is the cut string, the other part is the rest the cut string is the last part of the string with the given size starting from the right side the rest is the remaining part of the string so if you have a string "1234567890" and you call StringCutFromRight("1234567890", 5) then the result will be "67890" and "12345"
func StringPure ¶
func ToString ¶
func ToString(msg ...interface{}) string
ToString is parsing the message into a string
func UniseqLen ¶
UniseqLen returns the length of a string, but only counts printable characters it ignores ANSI escape codes and also ignores the length of the ANSI escape codes
func UpdateFilterByName ¶
func UpdateFilterByName(nameOfFilter string, info PostFilterInfo) error
func UpdateFilterByRef ¶
func UpdateFilterByRef(filter PostFilter, info PostFilterInfo) error
func VisibleLen ¶
returns the length of a string, but only counts printable characters it ignores ANSI escape codes makes use of the ansi package from muesli
Types ¶
type BasicColors ¶
type BasicColors struct {
// Foreground colors
Black, Red, Green, Yellow, Blue, Magenta, Cyan, LightGrey, DarkGrey, LightRed, LightGreen, LightYellow, LightBlue, LightCyan, LightMagenta, White string
// Background colors
BackBlack, BackRed, BackGreen, BackYellow, BackBlue, BackMagenta, BackCyan, BackLightGrey, BackDarkGrey, BackLightRed, BackLightGreen, BackLightYellow, BackLightBlue, BackLightCyan, BackLightMagenta, BackWhite string
// contains filtered or unexported fields
}
func NewBasicColors ¶
func NewBasicColors() *BasicColors
func (*BasicColors) InitColors ¶
func (bc *BasicColors) InitColors()
func (*BasicColors) IsBasicColor ¶
func (bc *BasicColors) IsBasicColor(text string) bool
type CtxOutBehavior ¶
type CtxOutBehavior struct { NoColored bool ANSI bool ANSI256 bool ANSI16M bool Info *PostFilterInfo }
func GetBehavior ¶
func GetBehavior() CtxOutBehavior
type CtxOutCtrl ¶
type CtxOutCtrl struct {
IgnoreCase bool
}
CtxOutCtrl is a control structure that can be used to control the output
type CtxOutLabel ¶
type CtxOutLabel struct { Message interface{} FColor string }
CtxOutLabel is a control structure that can be used to control the output
type CursorFilter ¶
type CursorFilter struct { // Info is the PostFilterInfo Info PostFilterInfo //Last error that occured LastError error }
CursorFilter is a filter that sets the cursor position
func NewCursorFilter ¶
func NewCursorFilter() *CursorFilter
func (*CursorFilter) CanHandleThis ¶
func (t *CursorFilter) CanHandleThis(text string) bool
CanHandleThis returns true if the text is requesting a cursor position interface fulfills the PostFilter interface
func (*CursorFilter) Command ¶
func (t *CursorFilter) Command(str string) string
func (*CursorFilter) Filter ¶
func (t *CursorFilter) Filter(msg interface{}) interface{}
Filter is called when the context is updated interface fulfills the PostFilter interface
func (*CursorFilter) IsCursor ¶
func (t *CursorFilter) IsCursor(text string) bool
Command is called when the text is a cursor position interface fulfills the PostFilter interface
func (*CursorFilter) Update ¶
func (t *CursorFilter) Update(info PostFilterInfo)
Update is called when the context is updated interface fulfills the PostFilter interface
type MOWrap ¶
type MOWrap struct {
// contains filtered or unexported fields
}
func (*MOWrap) GetInfo ¶
func (m *MOWrap) GetInfo() CtxOutBehavior
func (*MOWrap) Update ¶
func (m *MOWrap) Update(info CtxOutBehavior)
type Markup ¶
type Markup struct {
// contains filtered or unexported fields
}
general markup parser. this defines a single markup and NOT the markup itself so a markup is created by openeing the markup with START-TOKEN + something + END-TOKEN and closing it with START-TOKEN + CLOSE-IDENT + something + END-TOKEN the default markup is <something> and </something>
func NewMarkup ¶
func NewMarkup() *Markup
NewMarkup creates a new markup parser with the default markup
func (*Markup) BuildInnerSlice ¶
BuildInnerSlice builds a slice of Parsed elements from a slice of Parsed elements it searches for the outerMarkup and returns the inner slice of Parsed elements and the outer slice of Parsed elements
func (*Markup) BuildInnerSliceEach ¶
func (m *Markup) BuildInnerSliceEach(parsed []Parsed, outerMarkup string, handleFn func(markup []Parsed) bool) []Parsed
BuildInnerSliceEach builds a slice of Parsed elements from a slice of Parsed elements it searches for the outerMarkup and returns the inner slice of Parsed elements and the outer slice of Parsed elements it calls the handleFn for each inner slice of Parsed elements if the handleFn returns false, the iteration stops
func (*Markup) SetAccepptedTags ¶
SetAcceptedTags sets the accepted tags of a markup. anything else is ignored and parsed as content/text
func (*Markup) SetCloseIdent ¶
SetCloseIdent sets the close identifier of a markup like / so the markup would looks like <something/>
func (*Markup) SetEndToken ¶
SetEndToken sets the end token of a markup like > so the markup would looks like <something/>
func (*Markup) SetStartToken ¶
SetStartToken sets the start token of a markup like < so the markup would looks like <something/>
type Parsed ¶
type Parsed struct { IsMarkup bool // flag if is plain text or a markup Text string // the text of the parsed markup. this is on a markup like <something> the something. on a plain text it is the plain text }
Parsed is a single parsed markup. it can be a plain text or a markup
func (*Parsed) GetMarkupIntValue ¶
GetMarkupIntValue returns the int value of a markup for example if the markup is <something value='123'> and the key is value, it returns 123
func (*Parsed) GetMarkupStringValue ¶
GetMarkupStringValue returns the string value of a markup for example if the markup is <something value='123'> and the key is value, it returns 123
func (*Parsed) GetProperty ¶
GetProperty returns the value of a property of a markup
type PostFilter ¶
type PostFilter interface { Update(info PostFilterInfo) CanHandleThis(text string) bool Command(cmd string) string }
PostFilter is an interface that can be used to filter the message after the markup filter they works only on strings
func GetPostFilter ¶
func GetPostFilter(nameOfFilter string) PostFilter
func GetPostFilterbyRef ¶
func GetPostFilterbyRef(filter PostFilter) PostFilter
func GetPostFilters ¶
func GetPostFilters() []PostFilter
GetPostFilters returns the list of post filters
type PostFilterInfo ¶
type PostFilterInfo struct { IsTerminal bool // if the output is a terminal Colored bool // if the output can be colored Disabled bool // if the whole filter is enabled. the filter is still called, but it should not change the message. but remove the markup Width int // the width of the terminal Height int // the height of the terminal Id string // the id of the filter }
type PrintInterface ¶
type PrintInterface interface { Update(info CtxOutBehavior) Filter(msg interface{}) interface{} }
PrintInterface is an interface that can be used to filter the message
type Sign ¶
type Sign struct { Name string // name of the sign. used also as identifier Glyph string // the utf-8 character Fallback string // the fallback string }
defining an sign that can be used to display information as an sign. this sign is an utf-8 character. and a fallback string that is used if the device is not able to display the sign.
type SignFilter ¶
type SignFilter struct {
// contains filtered or unexported fields
}
func NewSignFilter ¶
func NewSignFilter(signSet *SignSet) *SignFilter
NewSignFilter returns a new SignFilter if signSet is nil, the default signs are used
func (*SignFilter) AddSign ¶
func (sf *SignFilter) AddSign(sign Sign) *SignFilter
func (*SignFilter) CanHandleThis ¶
func (sf *SignFilter) CanHandleThis(text string) bool
the format for an sign is:
anything before <sign info> and anything afterwards <sign warning> and again anything afterwards
func (*SignFilter) Command ¶
func (sf *SignFilter) Command(cmd string) string
func (*SignFilter) Enabled ¶
func (sf *SignFilter) Enabled() bool
Enabled returns true if the filter is enabled
func (*SignFilter) ForceEmpty ¶
func (sf *SignFilter) ForceEmpty(forceEmpty bool)
func (*SignFilter) GetSign ¶
func (sf *SignFilter) GetSign(name string) Sign
func (*SignFilter) Update ¶
func (sf *SignFilter) Update(info PostFilterInfo)
Update updates the filter with the new info
type SignSet ¶
type SignSet struct {
Signs []Sign
}
func NewBaseSignSet ¶
func NewBaseSignSet() *SignSet
NewBaseSignSet returns a new SignSet with the basic signs
type StreamInterface ¶
type StreamInterface interface { Stream(msg ...interface{}) StreamLn(msg ...interface{}) }
StreamInterface is an interface that can be used to stream the message
type TabOut ¶
type TabOut struct { RowCalcMode int // 0 = size is relative to with of terminal where maxsize is 100, 1 = absolute size // contains filtered or unexported fields }
func (*TabOut) CanHandleThis ¶
CanHandleThis returns true if the text is a table interface fulfills the PostFilter interface
func (*TabOut) Command ¶
Command is called when the text is a table interface fulfills the PostFilter interface
func (*TabOut) Filter ¶
func (t *TabOut) Filter(msg interface{}) interface{}
Filter is called when the context is updated interface fulfills the PostFilter interface
func (*TabOut) GetInfo ¶
func (t *TabOut) GetInfo() PostFilterInfo
func (*TabOut) GetRoundTool ¶
func (t *TabOut) GetRoundTool() *roundSerial
GetRoundTool returns the round tool what is used to calculate the size of the cells without rounding errors
func (*TabOut) GetSize ¶
GetSize returns the size of the cell if the cell is relative to the terminal width, the size is calculated if the cell is absolute, the size is returned
func (*TabOut) RowParse ¶
similar to TableParse, but for a single row and we do not wait for a table end
func (*TabOut) ScanForCells ¶
func (*TabOut) ScanForRows ¶
func (*TabOut) TableParse ¶
TableParse parses a table If a Table is created, we also enters table mode. In this mode the created table is not rendered until the table is closed.
func (*TabOut) Update ¶
func (t *TabOut) Update(info PostFilterInfo)
Update is called when the context is updated interface fulfills the PostFilter interface