utils

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 29 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsJson added in v0.7.1

func AsJson(i interface{}) string

func Clamp added in v0.35.0

func Clamp(x int, min int, max int) int

func Decolorise added in v0.7.1

func Decolorise(str string) string

Decolorise strips a string of color

func EditRebaseTodo added in v0.38.0

func EditRebaseTodo(filePath string, sha string, oldAction todo.TodoCommand, newAction todo.TodoCommand) error

Read a git-rebase-todo file, change the action for the given sha to newAction, and write it back

func EscapeSpecialChars added in v0.30.1

func EscapeSpecialChars(str string) string

EscapeSpecialChars - Replaces all special chars like \n with \\n

func FilePath added in v0.36.0

func FilePath(skip int) string

returns the path of the file that calls the function. 'skip' is the number of stack frames to skip.

func FindNamedMatches added in v0.32.1

func FindNamedMatches(regex *regexp.Regexp, str string) map[string]string

func FindStringSubmatch added in v0.20.1

func FindStringSubmatch(str string, regexpStr string) (bool, []string)

func ForEachLineInFile added in v0.28.2

func ForEachLineInFile(path string, f func(string, int)) error

func FuzzySearch added in v0.24.1

func FuzzySearch(needle string, haystack []string) []string

func GetCurrentRepoName

func GetCurrentRepoName() string

GetCurrentRepoName gets the repo's base name

func GetProjectRoot added in v0.1.71

func GetProjectRoot() string

GetProjectRoot returns the path to the root of the project. Only to be used in testing contexts, as with binaries it's unlikely this path will exist on the machine

func IsValidHexValue added in v0.30.1

func IsValidHexValue(v string) bool

func Limit added in v0.30.1

func Limit(values []string, limit int) []string

func LimitStr added in v0.31.1

func LimitStr(value string, limit int) string

func Loader added in v0.2.0

func Loader() string

Loader dumps a string to be displayed as a loader

func Max added in v0.31.1

func Max(x, y int) int

func Min added in v0.3.0

func Min(x, y int) int

Min returns the minimum of two integers

func ModuloWithWrap added in v0.11.1

func ModuloWithWrap(n, max int) int

used to keep a number n between 0 and max, allowing for wraparounds

func MoveElement added in v0.38.0

func MoveElement[T any](slice []T, from int, to int) []T

Returns a new slice with the element at index 'from' moved to index 'to'. Does not mutate original slice.

func MoveFixupCommitDown added in v0.38.0

func MoveFixupCommitDown(fileName string, originalSha string, fixupSha string) error

func MoveTodoDown added in v0.38.0

func MoveTodoDown(fileName string, sha string, action todo.TodoCommand) error

func MoveTodoUp added in v0.38.0

func MoveTodoUp(fileName string, sha string, action todo.TodoCommand) error

func MuiltiGroupBy added in v0.35.0

func MuiltiGroupBy[T any, K comparable](slice []T, f func(T) []K) map[K][]T

Similar to a regular GroupBy, except that each item can be grouped under multiple keys, so the callback returns a slice of keys instead of just one key.

func MustConvertToInt added in v0.22.0

func MustConvertToInt(s string) int

func NewDummyCommon added in v0.32.1

func NewDummyCommon() *common.Common

func NewDummyCommonWithUserConfig added in v0.32.1

func NewDummyCommonWithUserConfig(userConfig *config.UserConfig) *common.Common

func NewDummyLog added in v0.23.1

func NewDummyLog() *logrus.Entry

NewDummyLog creates a new dummy Log for testing

func NextIndex added in v0.7.1

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

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

func NextIntInCycle added in v0.15.1

func NextIntInCycle(sl []int, current int) int

NextIntInCycle returns the next int in a slice, returning to the first index if we've reached the end

func NormalizeLinefeeds added in v0.1.79

func NormalizeLinefeeds(str string) string

NormalizeLinefeeds - Removes all Windows and Mac style line feeds

func PrependStrToTodoFile added in v0.38.0

func PrependStrToTodoFile(filePath string, linesToPrepend []byte) error

func PrevIndex added in v0.7.1

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

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

func PrevIntInCycle added in v0.15.1

func PrevIntInCycle(sl []int, current int) int

PrevIntInCycle returns the prev int in a slice, returning to the first index if we've reached the end

func ReadRebaseTodoFile added in v0.38.0

func ReadRebaseTodoFile(fileName string) ([]todo.Todo, error)

func RenderDisplayStrings added in v0.14.4

func RenderDisplayStrings(displayStringsArr [][]string) string

func ResolvePlaceholderString added in v0.2.2

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

ResolvePlaceholderString populates a template with values

func ResolveTemplate added in v0.23.1

func ResolveTemplate(templateStr string, object interface{}, funcs template.FuncMap) (string, error)

func Safe added in v0.23.1

func Safe(f func())

Safe will close tcell if a panic occurs so that we don't end up in a malformed terminal state

func SafeTruncate added in v0.30.1

func SafeTruncate(str string, limit int) string

func SafeWithError added in v0.27.1

func SafeWithError(f func() error) error

func SetCustomColors added in v0.35.0

func SetCustomColors(customColors map[string]string) map[string]style.TextStyle

func ShortSha added in v0.35.0

func ShortSha(sha string) string

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 SplitNul added in v0.36.0

func SplitNul(str string) []string

func StackTrace added in v0.27.1

func StackTrace() string

func StringArraysOverlap added in v0.22.0

func StringArraysOverlap(strArrA []string, strArrB []string) bool

func TruncateWithEllipsis added in v0.15.3

func TruncateWithEllipsis(str string, limit int) string

TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis

func UnixToDate added in v0.20.1

func UnixToDate(timestamp int64, timeFormat string) string

func UnixToTimeAgo added in v0.20.1

func UnixToTimeAgo(timestamp int64) string

func WithPadding

func WithPadding(str string, padding int) string

WithPadding pads a string as much as you want

func WrapError added in v0.23.1

func WrapError(err error) error

WrapError wraps an error for the sake of showing a stack trace at the top level the go-errors package, for some reason, does not return nil when you try to wrap a non-error, so we're just doing it here

func WriteRebaseTodoFile added in v0.38.0

func WriteRebaseTodoFile(fileName string, todos []todo.Todo) error

Types

type OnceWriter added in v0.36.0

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

func NewOnceWriter added in v0.36.0

func NewOnceWriter(writer io.Writer, f func()) *OnceWriter

func (*OnceWriter) Write added in v0.36.0

func (self *OnceWriter) Write(p []byte) (n int, err error)

type StringStack added in v0.35.0

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

func (*StringStack) Clear added in v0.35.0

func (self *StringStack) Clear()

func (*StringStack) IsEmpty added in v0.35.0

func (self *StringStack) IsEmpty() bool

func (*StringStack) Pop added in v0.35.0

func (self *StringStack) Pop() string

func (*StringStack) Push added in v0.35.0

func (self *StringStack) Push(s string)

type ThreadSafeMap added in v0.36.0

type ThreadSafeMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewThreadSafeMap added in v0.36.0

func NewThreadSafeMap[K comparable, V any]() *ThreadSafeMap[K, V]

func (*ThreadSafeMap[K, V]) Clear added in v0.36.0

func (m *ThreadSafeMap[K, V]) Clear()

func (*ThreadSafeMap[K, V]) Delete added in v0.36.0

func (m *ThreadSafeMap[K, V]) Delete(key K)

func (*ThreadSafeMap[K, V]) Get added in v0.36.0

func (m *ThreadSafeMap[K, V]) Get(key K) (V, bool)

func (*ThreadSafeMap[K, V]) Has added in v0.36.0

func (m *ThreadSafeMap[K, V]) Has(key K) bool

func (*ThreadSafeMap[K, V]) IsEmpty added in v0.36.0

func (m *ThreadSafeMap[K, V]) IsEmpty() bool

func (*ThreadSafeMap[K, V]) Keys added in v0.36.0

func (m *ThreadSafeMap[K, V]) Keys() []K

func (*ThreadSafeMap[K, V]) Len added in v0.36.0

func (m *ThreadSafeMap[K, V]) Len() int

func (*ThreadSafeMap[K, V]) Set added in v0.36.0

func (m *ThreadSafeMap[K, V]) Set(key K, value V)

func (*ThreadSafeMap[K, V]) Values added in v0.36.0

func (m *ThreadSafeMap[K, V]) Values() []V

Jump to

Keyboard shortcuts

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