systools

package module
v0.0.0-...-3dbd443 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 13 Imported by: 8

Documentation

Index

Constants

View Source
const (
	ExitOk               = 0   // Everything is fine
	ErrorExitDefault     = 1   // any exit depending an error that do not need being specific
	ErrorInitApp         = 2   // any application error while setting up
	ErrorWhileLoadCfg    = 3   // any error while loading configuration
	ErrorOnConfigImport  = 5   // a import could not handled
	ErrorTemplate        = 6   // template related error. depending reported issues about version, lint, yaml structure
	ErrorTemplateReading = 7   // errors processing the template
	ErrorCheatMacros     = 8   // errors processing the cheat macros
	ErrorBySystem        = 10  // errors related to the system, like while change dir or reading a file
	ExitByStopReason     = 101 // ExitByStopReason the process stopped because of a defined reason
	ExitNoCode           = 102 // ExitNoCode means there was no code associated
	ExitCmdError         = 103 // ExitCmdError means the execution of the command fails. a error by the command itself
	ExitByRequirement    = 104 // ExitByRequirement means a requirement was not fulfills
	ExitAlreadyRunning   = 105 // ExitAlreadyRunning means the task is not started, because it is already created
	ExitByNoTargetExists = 106 // none of the targets are matching in requirements
	ExitByNothingToDo    = 107 // none of the targets have any usefull work to do or did not match any requirements
)

Variables

View Source
var CurrentBgColor = "42"

CurrentBgColor current used background color

View Source
var CurrentColor = "32"

CurrentColor current used foreground color

Functions

func AddExitListener

func AddExitListener(name string, callbk func(int) ExitBehavior)

adds a callback as listener

func AnyToStrNoTabs

func AnyToStrNoTabs(any interface{}) string

func CheckForCleanString

func CheckForCleanString(s string) (cleanString string, err error)

func CopyFile

func CopyFile(source, target string) error

func CreateBgColor

func CreateBgColor() string

CreateBgColor defines a random color and returns a id

func CreateBgColorCode

func CreateBgColorCode() string

CreateBgColorCode returns the colorcode by a random number

func CreateColorCode

func CreateColorCode() (string, string)

CreateColorCode returns the colorcode by a random number

func Exists

func Exists(path string) (bool, error)

Exists reports whether the named file or directory exists.

func Exit

func Exit(code int) bool

Exit maps the os.Exit but executes all callbacks before it the exit was aborted, you will get false in return

func FillString

func FillString(str string, length int) string

func FindStartChars

func FindStartChars(str string) string

create a string that is an shortcut of the given string so hello-my-friend will be hmf or hello_my_friend will be hmf or hello my friend will be hmf

func GetArgQuotedEntries

func GetArgQuotedEntries(oristr string) ([]string, bool)

func GetDefaultBg

func GetDefaultBg() string

GetDefaultBg Get the Default Background

func GetReset

func GetReset() string

GetReset gets the reset code

func GetStdOutTermSize

func GetStdOutTermSize() (width, height int, err error)

func IsDirWriteable

func IsDirWriteable(path string) bool

func IsStdOutTerminal

func IsStdOutTerminal() bool

func LabelPrint

func LabelPrint(message string, attribute int) string

LabelPrint prints message by using current fore and background

func LabelPrintWithArg

func LabelPrintWithArg(message string, fg string, bg string, attribute int) string

LabelPrintWithArg prints message by using current fore and background

func MapRangeSortedFn

func MapRangeSortedFn(m map[string]any, fn func(key string, value any))

an callback handler to sort the entries in a map by key first and then call the callback function with the key and value

func NoEscapeSequences

func NoEscapeSequences(str string) string

func PadString

func PadString(line string, max int) string

PadString Returns max len string filled with spaces

func PadStringToR

func PadStringToR(line string, max int) string

PadStringToR Returns max len string filled with spaces right placed

func PathCompare

func PathCompare(left, right string) bool

func PrintColored

func PrintColored(code string, outputs string) string

PrintColored formats string colored by the color id

func PrintableChars

func PrintableChars(str string) string

func PrintableCharsByUnquote

func PrintableCharsByUnquote(str string) (string, error)

func RemoveBadCharacters

func RemoveBadCharacters(input string, dictionary []string) string

func RemoveFromSliceOnce

func RemoveFromSliceOnce(slice []string, search string) []string

RemoveFromSliceOnce removes the first occurence of search in slice

func ResetColors

func ResetColors(print bool) string

ResetColors resets terminal colors if print false you get the ansi code only

func SanitizeFilename

func SanitizeFilename(name string, relativePath bool) string

func ShortLabel

func ShortLabel(label string, max int) string

func SliceContains

func SliceContains(slice []string, search string) bool

func SliceContainsSub

func SliceContainsSub(slice []string, search string) bool

like SliceContains but with strings.Contains so we can search for substrings

func SplitArgs

func SplitArgs(cmdList []string, prefix string, arghandler func(string, map[string]string)) []string

func SplitQuoted

func SplitQuoted(oristr string, sep string) []string

func StrLen

func StrLen(str string) int

func StringInSlice

func StringInSlice(search string, slice []string) bool

Alias for SliceContains

func StringSplitArgs

func StringSplitArgs(argLine string, prefix string) (string, map[string]string)

func StringSubLeft

func StringSubLeft(path string, max int) string

func StringSubRight

func StringSubRight(path string, max int) string

func TestColorCombinations

func TestColorCombinations()

func TrimAllSpaces

func TrimAllSpaces(s string) string

returns the string where any spaces, with an length of more than 1 are replaced by one space so "hello my friend" will be "hello my friend"

func UpdateExistingFileIfNotContains

func UpdateExistingFileIfNotContains(filename, content, doNotContain string) (bool, error)

UpdateExistingFileIfNotContains updates a file if it does not contain a string this is made to avoid multiple updates of the same file

func WatchSigTerm

func WatchSigTerm(callback func(os.Signal))

WatchSigTerm adds a callback function that will be executed if the app receives a SIGTERM signal if no callback is given, the app will exit with code 0 and all registered callbacks will be executed

func WriteFileIfNotExists

func WriteFileIfNotExists(filename, content string) (int, error)

WriteFileIfNotExists writes a file if it does not exist reports 0 if file was written, 1 if file exists, 2 if error on error, error is returned

Types

type ExitBehavior

type ExitBehavior struct {
	// contains filtered or unexported fields
}
var (
	Continue  ExitBehavior = ExitBehavior{/* contains filtered or unexported fields */}
	Interrupt ExitBehavior = ExitBehavior{/* contains filtered or unexported fields */}
)

type LabelColor

type LabelColor struct {
	Color   string
	BgColor string
}

LabelColor contains fore and background color

Jump to

Keyboard shortcuts

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