utils

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const AnsiEsc = "\x1B"
View Source
const AnsiResetCursor = "\r"

Variables

View Source
var AnsiEraseLine = fmt.Sprintf("%s[K", AnsiEsc)
View Source
var ArchMap = map[string][]string{
	"amd64": {"amd64", "x86_64", "x86-64"},
	"386":   {"i386", "i686"},
	"arm64": {"armhf", "aarch64"},
	"arm":   {"arm"},
}
View Source
var AtomicFilePrefix = "pho"
View Source
var LogDebugEnabled = os.Getenv("DEBUG") == "1"
View Source
var LogDebugPrefix = color.HiBlackString("debug:")
View Source
var LogErrorPrefix = color.RedString("error:")
View Source
var LogExclamationPrefix = color.RedString("!")
View Source
var LogQuestionPrefix = color.GreenString("?")
View Source
var LogRightArrowPrefix = color.MagentaString(">")
View Source
var LogTickPrefix = color.GreenString("√")
View Source
var LogWarnPrefix = color.YellowString("warning")

Functions

func AnsiCursorLineUp

func AnsiCursorLineUp(lines int) string

func AnsiCursorToColumn

func AnsiCursorToColumn(offset int) string

func BoolToYesNo added in v0.1.10

func BoolToYesNo(value bool) string

func CleanId

func CleanId(text string) string

func CommandBoolSetAndValue added in v0.1.7

func CommandBoolSetAndValue(cmd *cli.Command, name string) (bool, bool)

func CreateTempFile added in v0.0.7

func CreateTempFile(name string) (*os.File, error)

func EncloseWhen added in v0.1.0

func EncloseWhen(text string, when string, start string, end string) string

func ExecUnameM

func ExecUnameM() (string, error)

func FileExists

func FileExists(name string) (bool, error)

func FindFileInDir added in v0.1.12

func FindFileInDir(dir string, names []string) (bool, string)

func GetSystemArch

func GetSystemArch() string

func HumanizeSeconds

func HumanizeSeconds(n int64) string

func LogDebug

func LogDebug(msg string)

func LogError

func LogError(err any)

func LogInfo

func LogInfo(msg string)

func LogLn

func LogLn()

func LogWarning

func LogWarning(msg string)

func PromptTextInput

func PromptTextInput(reader *bufio.Reader, question string, defaultValue string) (string, error)

func PromptYesNoInput

func PromptYesNoInput(reader *bufio.Reader, question string) (bool, error)

func QuotedWhenSpace added in v0.1.0

func QuotedWhenSpace(text string) string

func ReadJsonFile

func ReadJsonFile[T any](name string) (*T, error)

func ReaderReadLine

func ReaderReadLine(reader *bufio.Reader) (string, error)

func ReplaceIllegalChars

func ReplaceIllegalChars(text string) string

func ResolvePath

func ResolvePath(name string) (string, error)

func SliceContains added in v0.1.3

func SliceContains[T comparable](slice []T, value T) bool

func StartDetachedProcess added in v0.1.3

func StartDetachedProcess(options *StartDetachedProcessOptions) error

func StripAnsi

func StripAnsi(text string) string

func TerminalErasePreviousLine

func TerminalErasePreviousLine()

func TerminalLoadingSymbol

func TerminalLoadingSymbol(v int) string

\ | / -

func TimeNowSeconds

func TimeNowSeconds() int64

func WriteFileAtomic

func WriteFileAtomic(name string, bytes []byte) error

func WriteJsonFile

func WriteJsonFile[T any](name string, data *T) error

func WriteJsonFileAtomic

func WriteJsonFileAtomic[T any](name string, data *T) error

Types

type LogTable

type LogTable struct {
	Columns         [][]string
	RowsCount       int
	ColumnsCount    int
	RowWidths       []int
	RowSeparator    string
	ColumnSeparator string
}

func NewLogTable

func NewLogTable() *LogTable

func (*LogTable) Add

func (table *LogTable) Add(values ...string)

func (*LogTable) AddColumn

func (table *LogTable) AddColumn(column []string)

func (*LogTable) Build

func (table *LogTable) Build() string

func (*LogTable) Print

func (table *LogTable) Print()

type StartDetachedProcessOptions added in v0.1.3

type StartDetachedProcessOptions struct {
	Dir  string
	Exec string
	Args []string
}

Jump to

Keyboard shortcuts

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