util

package
v0.0.0-...-e489f9a Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateFlexWidth

func CalculateFlexWidth(totalWidth int, fixedWidths []int, flexFactors []int, inputFactor int) int

CalculateFlexWidth calculates the width of a flex column in a table.

func DeleteColumn

func DeleteColumn[T any](matrix [][]T, colIndex int) [][]T

func DeleteElement

func DeleteElement[T any](slice []T, index int) []T

func DrawLine

func DrawLine(width int) string

Draw a line

func FormatSize

func FormatSize(bytes int) string

FormatSize takes an input in bytes and returns a human-readable size string.

func FormatSpeed

func FormatSpeed(bytesPerSecond int) string

FormatSpeed takes an input in bytes per second and returns a human-readable speed string.

func FormatTime

func FormatTime(seconds uint64) string

FormatTime takes an input in seconds (as uint64) and returns a human-readable time string.

func GetColumn

func GetColumn[T any](matrix [][]T, colIndex int) []T

func IfElse

func IfElse[T any](cond bool, exp1, exp2 T) T

Ternary Operator

func IsEmptyOrWhitespace

func IsEmptyOrWhitespace(str string) bool

func MarginHor

func MarginHor(s string, amt int) string

func PrintMatrix

func PrintMatrix(matrix [][]int) (s string)

func Repl

func Repl(s string, amt int) string

func SetColumn

func SetColumn[T any](matrix [][]T, colIndex int, value T)

func Sum

func Sum(arr []int) int

func TrimString

func TrimString(str string, maxLength int) string

func UpdateTeaModel

func UpdateTeaModel[T interface{ tea.Model }](model T, msg tea.Msg) (T, tea.Cmd)

UpdateTeaModel safely updates a Bubble Tea model and returns the concrete type

Types

type Counter

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

func (*Counter) Value

func (c *Counter) Value() int

func (*Counter) ValueAdd

func (c *Counter) ValueAdd() int

type ResizeHandler

type ResizeHandler interface {
	Resize(width int, height int)
}

type StateHandler

type StateHandler[T comparable] struct {
	// contains filtered or unexported fields
}

func NewStateHandler

func NewStateHandler[T comparable](states []T, cur int) *StateHandler[T]

NewStateHandler initializes the state handler with a slice of states.

func (*StateHandler[T]) CurrentState

func (sh *StateHandler[T]) CurrentState() T

CurrentState returns the current state.

func (*StateHandler[T]) Index

func (sh *StateHandler[T]) Index() int

Returns current state's index

func (*StateHandler[T]) NextState

func (sh *StateHandler[T]) NextState() T

NextState transitions to the next state, wrapping around if necessary.

func (*StateHandler[T]) PrevState

func (sh *StateHandler[T]) PrevState() T

PrevState transitions to the previous state, wrapping around if necessary.

func (*StateHandler[T]) SetState

func (sh *StateHandler[T]) SetState(state T)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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