utils

package
v0.0.0-...-7ff6b7e Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: CC0-1.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WHITESPACE_CHAR = " "
	BULLET          = "•"
	ELLIPSIS        = "…"
)

Variables

View Source
var (
	TOP_LEFT     = Position{X: 0, Y: 0}
	TOP_RIGHT    = Position{X: 1, Y: 0}
	BOTTOM_LEFT  = Position{X: 0, Y: 1}
	BOTTOM_RIGHT = Position{X: 1, Y: 1}
	CENTER       = Position{X: 0.5, Y: 0.5}
)

Functions

func Abs

func Abs(input int) int

Returns the integer absolute value of the given integer. (Integer alternative to math.Abs)

func ClampInt

func ClampInt(input int, minimum int, maximum int) int

Returns the input int if it's between min and max, otherwise returns min or max

func GetTerminalSize

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

func PlaceHorizontallyScrolled

func PlaceHorizontallyScrolled(viewWidth int, hPos int, input string) string

Takes an input string and places it horizontally in a view of a given width. If the visible width of the input is larger than the view width or the provided horizontal position of the input string places it partially out of the view, it will be cropped. If the input gets cropped, only the visible characters in the string will be removed, so any ansi sequences in the string will still apply to the remaining visible characters (this avoids visual artifacts from mangled ansi sequences).

viewWidth: int - The width (in cells) of the view hPos: int - The horizontal offset of the input string input: int - The string to be placed

func PlaceStacked

func PlaceStacked(bottom string, top string, origin Position, vPos int, hPos int) string

Takes a top string and places it on top of (in front of, i.e. visually obstructing) a given bottom string. This function also takes a position argument, specifying which corner the two strings should be joined on (if position is 2, the top-left corner of the top string should be over the top-left corner of the bottom string)

bottom: string - The input string to be placed on the bottom of the stack top: string - The input string to be placed on the top of the stack vPos: int - The vertical offset of the top string hPos: int - The horizontal offset of the top string

func PlaceVerticallyAndHorizontallyScrolled

func PlaceVerticallyAndHorizontallyScrolled(viewHeight int, viewWidth int, vPos int, hPos int, input string) string

Takes an input string and places it in a view of a given width and height. If any of the visible dimensions of the input are larger than their corresponding view dimensions, or the provided position of the input string places it partially out of the view, it will be cropped. If the input gets cropped, only the visible characters in the string will be removed, so any ansi sequences in the string will still apply to the remaining visible characters (this avoids visual artifacts from mangled ansi sequences).

viewHeight: int - The height (in rows) of the view viewWidth: int - The width (in cells) of the view vPos: int - The vertical offset of the input string hPos: int - The horizontal offset of the input string input: int - The string to be placed

func Round

func Round(input float64) int

Returns the integer value of the given float64, rounded to the nearest whole number. (alternative to math.Abs)

func WrapInt

func WrapInt(value int, min int, max int) int

Returns the input int between the two boundaries and wraps it if it's out of the given bounds

Types

type Position

type Position struct {
	X float64
	Y float64
}

Jump to

Keyboard shortcuts

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