utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(str string, object interface{}) string

func AsJson

func AsJson(i interface{}) string

func ColoredString

func ColoredString(str string, colorAttribute color.Attribute) string

ColoredString takes a string and a colour attribute and returns a colored string with that attribute

func ColoredStringDirect

func ColoredStringDirect(str string, colour *color.Color) string

ColoredStringDirect used for aggregating a few color attributes rather than just sending a single one

func Decolorise

func Decolorise(str string) string

Decolorise strips a string of color

func FormatBinaryBytes

func FormatBinaryBytes(b int) string

func FormatDecimalBytes

func FormatDecimalBytes(b int) string

func GetColorAttribute

func GetColorAttribute(key string) color.Attribute

GetColorAttribute gets the color attribute from the string

func GetGocuiAttribute

func GetGocuiAttribute(key string) gocui.Attribute

GetGocuiAttribute gets the gocui color attribute from the string

func IncludesString

func IncludesString(list []string, a string) bool

IncludesString if the list contains the string

func IsFocused

func IsFocused(isFocused bool) func(c *RenderListConfig)

func Loader

func Loader() string

Loader dumps a string to be displayed as a loader

func Max

func Max(x, y int) int

Max returns the maximum of two integers

func Min

func Min(x, y int) int

Min returns the minimum of two integers

func NextIndex

func NextIndex(numbers []int, currentNumber int) int

NextIndex returns the index of the element that comes after the given number

func NormalizeLinefeeds

func NormalizeLinefeeds(str string) string

NormalizeLinefeeds - Removes all Windows and Mac style line feeds

func PrevIndex

func PrevIndex(numbers []int, currentNumber int) int

PrevIndex returns the index that comes before the given number, cycling if we reach the end

func RenderList

func RenderList(slice interface{}, options ...func(*RenderListConfig)) (string, error)

RenderList takes a slice of items, confirms they implement the Displayable interface, then generates a list of their displaystrings to write to a panel's buffer

func RenderTable

func RenderTable(stringArrays [][]string) (string, error)

RenderTable takes an array of string arrays and returns a table containing the values

func ResolvePlaceholderString

func ResolvePlaceholderString(str string, arguments map[string]string) string

ResolvePlaceholderString populates a template with values

func SplitLines

func SplitLines(multilineString string) []string

SplitLines takes a multiline string and splits it on newlines currently we are also stripping \r's which may have adverse effects for windows users (but no issues have been raised yet)

func TrimTrailingNewline

func TrimTrailingNewline(str string) string

TrimTrailingNewline - Trims the trailing newline TODO: replace with `chomp` after refactor

func WithHeader

func WithHeader(header []string) func(c *RenderListConfig)

func WithPadding

func WithPadding(str string, padding int) string

WithPadding pads a string as much as you want

Types

type Displayable

type Displayable interface {
	GetDisplayStrings(bool) []string
}

type RenderListConfig

type RenderListConfig struct {
	IsFocused bool
	Header    []string
}

Jump to

Keyboard shortcuts

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