utils

package
v0.0.0-...-e867e26 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const RepoTag = "<repo>"

PluginTag to identify variable component name in a Document path.

View Source
const StringCompressMin = 7

Variables

This section is empty.

Functions

func Abs

func Abs(name string) (string, error)

Abs returns an absolute path

It expands ~ to $HOME
If path is already absolute, it cleans up (shortest path).
If the path is relative, it adds current directory to create it as absolute path

func ArrayStringDelete

func ArrayStringDelete(a []string, element string) []string

func BuildURLPath

func BuildURLPath(aPath, repo, subpath, document string) (fullFileName string)

BuildURLPath build the path logic introducing the pluginTag to replace.

func Cumulative

func Cumulative(ref, value int) int

Max is the default function to evaluate values and result as Max

func DefColor

func DefColor(colorNum int) (color, reset string)

func EnsureDir

func EnsureDir(dir, mess string) (_ error)

EnsureDir ensure the given dir exist and recreate it if needed.

func Evaluate

func Evaluate(value string, tmpl *template.Template, data interface{}, funcs template.FuncMap) (_ string, _ error)

func InStringList

func InStringList(element string, elements ...string) string

func Max

func Max(ref, value int) int

Max is the default function to evaluate values and result as Max

func Min

func Min(ref, value int) int

Max is the default function to evaluate values and result as Max

func ReadDocumentFrom

func ReadDocumentFrom(urls []*url.URL, repos, subPaths []string, document, contentType string) ([]byte, error)

ReadDocumentFrom is used to read a document from a url like github raw or directly from a local path It supports file or url stored in url.URL structure each urls can be defined with a plugin tag "<plugin>" which will be replaced by the document name(document) the file name and the extension is added at the end of the string.

func RunCmd

func RunCmd(command string, args ...string) int

Simple function to call a shell command and display to stdout stdout is displayed as is when it arrives, while stderr is displayed in Red, line per line.

func RunCmdOutput

func RunCmdOutput(command string, args ...string) (string, int)

RunCmdOutput run a command and return the standard output as result. stderr is displayed in Red, line per line.

func StringCompress

func StringCompress(str string, min, max int) (ret string)

StringCompress compress a string to display to a maximum given if the str is higher, it will be cut in the middle with "..." min must be higher than 7 bytes. If max is lower than min, max will be set to min to ensure the size returned is never under min or 7 bytes

func Touch

func Touch(file string) error

Types

type EvalValues

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

EvalSizes stores max for each elements evaluated.

func NewEvalValues

func NewEvalValues(index int) (ret *EvalValues)

NewEvalValues creates an EvalValues object

index : Number of evaluated values

func (*EvalValues) CountOf

func (m *EvalValues) CountOf(index int) (ret int)

CountOf returns how many evaluation were executed on an indexed item

func (*EvalValues) Eval

func (m *EvalValues) Eval(index, value int)

Eval is used to evaluate an item value with the select eval function

func (*EvalValues) EvalFunc

func (m *EvalValues) EvalFunc(index int, evalFunc func(int, int) int)

EvalFunc change the default Eval method to your Method

Default is utils.Max

Some predefined Eval functions:

- utils.Cumulative - utils.Max - utils.Min

func (*EvalValues) PrintfFormat

func (m *EvalValues) PrintfFormat(format string, indexes ...int) string

PrintfFormat format an Printf format with indexed ValueOf() The format is interpreted by Sprintf

Ex: "%%-%ds" could be evaluated by "%-10s"

func (*EvalValues) ValueOf

func (m *EvalValues) ValueOf(index int) (ret int)

ValueOf return the evaluated indexed value after multiple EvalValues.Eval().

type MLoop

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

func NewMLoop

func NewMLoop(max ...int) (ml *MLoop)

func (*MLoop) Cur

func (ml *MLoop) Cur() (_ []int)

func (*MLoop) Eol

func (ml *MLoop) Eol() bool

func (*MLoop) Increment

func (ml *MLoop) Increment() (_ []int)

type TerminalArray

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

func NewTerminalArray

func NewTerminalArray(linesNum, colsNum int) (ret *TerminalArray)

func (*TerminalArray) EvalLine

func (t *TerminalArray) EvalLine(key string, cols ...int)

func (*TerminalArray) Print

func (t *TerminalArray) Print(getLineData func(key string, compressedMax int) []interface{})

func (*TerminalArray) SetCol

func (t *TerminalArray) SetCol(index int, header string)

Jump to

Keyboard shortcuts

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