util

package
v0.0.0-...-4a68eac Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT, MIT Imports: 15 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsUint16

func AsUint16(val int) uint16

func AtExit

func AtExit(fn func())

AtExit registers the function fn to be called on program termination. The functions will be called in reverse order they were registered.

func Constrain

func Constrain(val int, min int, max int) int

Constrain limits the given integer with the upper and lower bounds

func Constrain32

func Constrain32(val int32, min int32, max int32) int32

Constrain32 limits the given 32-bit integer with the upper and lower bounds

func DurWithin

func DurWithin(
	val time.Duration, min time.Duration, max time.Duration) time.Duration

DurWithin limits the given time.Duration with the upper and lower bounds

func Exit

func Exit(code int)

Exit executes any functions registered with AtExit() then exits the program with os.Exit(code).

NOTE: It must be used instead of os.Exit() since calling os.Exit() terminates the program before any of the AtExit functions can run.

func IsTty

func IsTty() bool

IsTty returns true if stdin is a terminal

func IsWindows

func IsWindows() bool

IsWindows returns true on Windows

func KillCommand

func KillCommand(cmd *exec.Cmd) error

KillCommand kills the process for the given command

func Max

func Max(first int, second int) int

Max returns the largest integer

func Max16

func Max16(first int16, second int16) int16

Max16 returns the largest integer

func Max32

func Max32(first int32, second int32) int32

Max32 returns the largest 32-bit integer

func Min

func Min(first int, second int) int

Min returns the smallest integer

func Min32

func Min32(first int32, second int32) int32

Min32 returns the smallest 32-bit integer

func Once

func Once(nextResponse bool) func() bool

Once returns a function that returns the specified boolean value only once

func Read

func Read(fd int, b []byte) (int, error)

Read executes syscall.Read on file descriptor

func RepeatToFill

func RepeatToFill(str string, length int, limit int) string

RepeatToFill repeats the given string to fill the given width

func RunAtExitFuncs

func RunAtExitFuncs()

RunAtExitFuncs runs any functions registered with AtExit().

func RunesWidth

func RunesWidth(runes []rune, prefixWidth int, tabstop int, limit int) (int, int)

RunesWidth returns runes width

func SetNonblock

func SetNonblock(file *os.File, nonblock bool)

SetNonblock executes syscall.SetNonblock on file descriptor

func SetStdin

func SetStdin(file *os.File)

func StringWidth

func StringWidth(s string) int

StringWidth returns string width where each CR/LF character takes 1 column

func ToKebabCase

func ToKebabCase(s string) string

ToKebabCase converts the given CamelCase string to kebab-case

func ToTty

func ToTty() bool

ToTty returns true if stdout is a terminal

func Truncate

func Truncate(input string, limit int) ([]rune, int)

Truncate returns the truncated runes and its width

Types

type AtomicBool

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

AtomicBool is a boxed-class that provides synchronized access to the underlying boolean value

func NewAtomicBool

func NewAtomicBool(initialState bool) *AtomicBool

NewAtomicBool returns a new AtomicBool

func (*AtomicBool) Get

func (a *AtomicBool) Get() bool

Get returns the current boolean value synchronously

func (*AtomicBool) Set

func (a *AtomicBool) Set(newState bool) bool

Set updates the boolean value synchronously

type Chars

type Chars struct {

	// XXX Piggybacking item index here is a horrible idea. But I'm trying to
	// minimize the memory footprint by not wasting padded spaces.
	Index int32
	// contains filtered or unexported fields
}

func RunesToChars

func RunesToChars(runes []rune) Chars

func ToChars

func ToChars(bytes []byte) Chars

ToChars converts byte array into rune array

func (*Chars) Bytes

func (chars *Chars) Bytes() []byte

func (*Chars) CopyRunes

func (chars *Chars) CopyRunes(dest []rune, from int)

func (*Chars) Get

func (chars *Chars) Get(i int) rune

func (*Chars) IsBytes

func (chars *Chars) IsBytes() bool

func (*Chars) LeadingWhitespaces

func (chars *Chars) LeadingWhitespaces() int

func (*Chars) Length

func (chars *Chars) Length() int

func (*Chars) Prepend

func (chars *Chars) Prepend(prefix string)

func (*Chars) String

func (chars *Chars) String() string

String returns the string representation of a Chars object.

func (*Chars) ToRunes

func (chars *Chars) ToRunes() []rune

func (*Chars) ToString

func (chars *Chars) ToString() string

func (*Chars) TrailingWhitespaces

func (chars *Chars) TrailingWhitespaces() int

func (*Chars) TrimLength

func (chars *Chars) TrimLength() uint16

TrimLength returns the length after trimming leading and trailing whitespaces

func (*Chars) TrimTrailingWhitespaces

func (chars *Chars) TrimTrailingWhitespaces()

type EventBox

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

EventBox is used for coordinating events

func NewEventBox

func NewEventBox() *EventBox

NewEventBox returns a new EventBox

func (*EventBox) Peek

func (b *EventBox) Peek(event EventType) bool

Peek peeks at the event box if the given event is set

func (*EventBox) Set

func (b *EventBox) Set(event EventType, value interface{})

Set turns on the event type on the box

func (*EventBox) Unwatch

func (b *EventBox) Unwatch(events ...EventType)

Unwatch adds the events to the ignore list

func (*EventBox) Wait

func (b *EventBox) Wait(callback func(*Events))

Wait blocks the goroutine until signaled

func (*EventBox) WaitFor

func (b *EventBox) WaitFor(event EventType)

WaitFor blocks the execution until the event is received

func (*EventBox) Watch

func (b *EventBox) Watch(events ...EventType)

Watch deletes the events from the ignore list

type EventType

type EventType int

EventType is the type for fzf events

type Events

type Events map[EventType]interface{}

Events is a type that associates EventType to any data

func (*Events) Clear

func (events *Events) Clear()

Clear clears the events Unsynchronized; should be called within Wait routine

type Executor

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

func NewExecutor

func NewExecutor(withShell string) *Executor

func (*Executor) Become

func (x *Executor) Become(stdin *os.File, environ []string, command string)

func (*Executor) ExecCommand

func (x *Executor) ExecCommand(command string, setpgid bool) *exec.Cmd

ExecCommand executes the given command with $SHELL

func (*Executor) QuoteEntry

func (x *Executor) QuoteEntry(entry string) string

type Slab

type Slab struct {
	I16 []int16
	I32 []int32
}

func MakeSlab

func MakeSlab(size16 int, size32 int) *Slab

Jump to

Keyboard shortcuts

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