ansipixels

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

ansipixel provides terminal drawing and key reading abilities. fps/fps.go and life/life.go are examples/demos of how to use it.

Index

Constants

View Source
const (
	RoundTopLeft     = "╭"
	RoundTopRight    = "╮"
	RoundBottomLeft  = "╰"
	RoundBottomRight = "╯"

	SquareTopLeft     = "┌"
	SquareTopRight    = "┐"
	SquareBottomLeft  = "└"
	SquareBottomRight = "┘"

	Horizontal = "─"
	Vertical   = "│"

	TopT        = "┬"
	BottomT     = "┴"
	LeftT       = "├"
	RightT      = "┤"
	MiddleCross = "┼"

	FullPixel       = '█'
	TopHalfPixel    = '▀'
	BottomHalfPixel = '▄'

	QLowLeft  = '▖'
	QLowRight = '▗'
	QUpLeft   = '▘'
	QUpRight  = '▝'
)
View Source
const BUFSIZE = 1024

Variables

This section is empty.

Functions

func AnsiClean added in v0.21.0

func AnsiClean(str []byte) ([]byte, int)

AnsiClean removes all Ansi code from a given byte slice. Useful among other things to get the correct string to pass to uniseq.StringWidth (ap.StringWidth does it for you). Returns the length of the processed input - unterminated sequences can be reprocessed using data from str[returnedVal:] plus additional data (see tests and nocolor for usage).

func DrawAALine added in v0.21.0

func DrawAALine(img *image.NRGBA, x0, y0, x1, y1 float64, c color.NRGBA)

Draw an anti-aliased line using Xiaolin Wu's algorithm. https://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm This may or not be correct as it was mostly generated by our AI overlords.

func DrawLine added in v0.21.0

func DrawLine(img *image.NRGBA, x0, y0, x1, y1 float64, c color.NRGBA)

Non aliased version. Brute force implementation of Bresenham's line algorithm.

func FormatDate added in v0.20.0

func FormatDate(d *time.Time) string

func HSLToRGB added in v0.21.0

func HSLToRGB(h, s, l float64) color.NRGBA

HSLToRGB converts HSL values to RGB. h, s and l in [0,1]. Initially from grol.io/grol/extensions images.go.

func MergePlot added in v0.21.0

func MergePlot(img *image.NRGBA, x, y int, c color.NRGBA, newalpha float64)

Merge (additively) the pixel with alpha on top of the existing image.

Types

type AnsiPixels

type AnsiPixels struct {
	FdIn int

	Out           *bufio.Writer
	In            *os.File
	InWithTimeout *terminal.TimeoutReader

	Data []byte
	W, H int // Width and Height

	Mouse    bool // Mouse event received
	Mx, My   int  // Mouse last known position
	Mbuttons int  // Mouse buttons and modifier state
	C        chan os.Signal
	// Should image be monochrome, 256 or true color
	TrueColor bool
	Color     bool         // 256 (216) color mode
	Gray      bool         // grayscale mode
	Margin    int          // Margin around the image (image is smaller by 2*margin)
	FPS       float64      // (Target) Frames per second used for Reading with timeout
	OnResize  func() error // Callback when terminal is resized
	// contains filtered or unexported fields
}

func NewAnsiPixels

func NewAnsiPixels(fps float64) *AnsiPixels

func (*AnsiPixels) ChangeFPS added in v0.17.0

func (ap *AnsiPixels) ChangeFPS(fps float64)

func (*AnsiPixels) ClearEndOfLine

func (ap *AnsiPixels) ClearEndOfLine()

func (*AnsiPixels) ClearScreen

func (ap *AnsiPixels) ClearScreen()

func (*AnsiPixels) DecodeImage added in v0.11.0

func (ap *AnsiPixels) DecodeImage(inp io.Reader) (*Image, error)

func (*AnsiPixels) Draw216ColorImage added in v0.12.0

func (ap *AnsiPixels) Draw216ColorImage(sx, sy int, img *image.RGBA) error

func (*AnsiPixels) DrawBox

func (ap *AnsiPixels) DrawBox(x, y, w, h int, topLeft, topRight, bottomLeft, bottomRight string)

func (*AnsiPixels) DrawMonoImage added in v0.12.0

func (ap *AnsiPixels) DrawMonoImage(sx, sy int, img *image.Gray, color string) error

func (*AnsiPixels) DrawRoundBox

func (ap *AnsiPixels) DrawRoundBox(x, y, w, h int)

func (*AnsiPixels) DrawSquareBox

func (ap *AnsiPixels) DrawSquareBox(x, y, w, h int)

func (*AnsiPixels) DrawTrueColorImage added in v0.12.0

func (ap *AnsiPixels) DrawTrueColorImage(sx, sy int, img *image.RGBA) error

func (*AnsiPixels) EndSyncMode added in v0.17.0

func (ap *AnsiPixels) EndSyncMode()

End sync (and flush).

func (*AnsiPixels) GetSize

func (ap *AnsiPixels) GetSize() (err error)

func (*AnsiPixels) HandleSignal added in v0.17.0

func (ap *AnsiPixels) HandleSignal(s os.Signal) error

func (*AnsiPixels) HideCursor

func (ap *AnsiPixels) HideCursor()

func (*AnsiPixels) IsResizeSignal

func (ap *AnsiPixels) IsResizeSignal(s os.Signal) bool

func (*AnsiPixels) MouseClickOff added in v0.21.0

func (ap *AnsiPixels) MouseClickOff()

func (*AnsiPixels) MouseClickOn added in v0.21.0

func (ap *AnsiPixels) MouseClickOn()

func (*AnsiPixels) MouseDecode added in v0.21.0

func (ap *AnsiPixels) MouseDecode()

func (*AnsiPixels) MousePixelsOff added in v0.21.0

func (ap *AnsiPixels) MousePixelsOff()

func (*AnsiPixels) MousePixelsOn added in v0.21.0

func (ap *AnsiPixels) MousePixelsOn()

func (*AnsiPixels) MouseTrackingOff added in v0.21.0

func (ap *AnsiPixels) MouseTrackingOff()

func (*AnsiPixels) MouseTrackingOn added in v0.21.0

func (ap *AnsiPixels) MouseTrackingOn()

func (*AnsiPixels) MouseX10Off added in v0.21.0

func (ap *AnsiPixels) MouseX10Off()

func (*AnsiPixels) MouseX10On added in v0.21.0

func (ap *AnsiPixels) MouseX10On()

func (*AnsiPixels) MoveCursor

func (ap *AnsiPixels) MoveCursor(x, y int)

func (*AnsiPixels) MoveHorizontally

func (ap *AnsiPixels) MoveHorizontally(x int)

func (*AnsiPixels) Open

func (ap *AnsiPixels) Open() (err error)

func (*AnsiPixels) ReadCursorPos

func (ap *AnsiPixels) ReadCursorPos() (int, int, error)

This also synchronizes the display.

func (*AnsiPixels) ReadImage added in v0.11.0

func (ap *AnsiPixels) ReadImage(path string) (*Image, error)

func (*AnsiPixels) ReadOrResizeOrSignal added in v0.17.0

func (ap *AnsiPixels) ReadOrResizeOrSignal() error

Read something or return terminal.ErrSignal if signal is received (normal exit requested case), will automatically call OnResize if set and if a resize signal is received and continue trying to read.

func (*AnsiPixels) ReadOrResizeOrSignalOnce added in v0.19.0

func (ap *AnsiPixels) ReadOrResizeOrSignalOnce() (int, error)

This will return either because of signal, or something read or the timeout (fps) passed. ap.Data is (re)set to the read data.

func (*AnsiPixels) Restore

func (ap *AnsiPixels) Restore()

func (*AnsiPixels) ScreenWidth added in v0.20.0

func (ap *AnsiPixels) ScreenWidth(str string) int

func (*AnsiPixels) ShowCursor

func (ap *AnsiPixels) ShowCursor()

func (*AnsiPixels) ShowImage added in v0.11.0

func (ap *AnsiPixels) ShowImage(imagesRGBA *Image, zoom float64, offsetX, offsetY int, colorString string) error

Color string is the fallback mono color to use when AnsiPixels.TrueColor is false.

func (*AnsiPixels) StartSyncMode added in v0.17.0

func (ap *AnsiPixels) StartSyncMode()

func (*AnsiPixels) TruncateLeftToFit added in v0.21.0

func (ap *AnsiPixels) TruncateLeftToFit(msg string, maxWidth int) (string, int)

func (*AnsiPixels) WriteAt

func (ap *AnsiPixels) WriteAt(x, y int, msg string, args ...interface{})

func (*AnsiPixels) WriteAtStr

func (ap *AnsiPixels) WriteAtStr(x, y int, msg string)

func (*AnsiPixels) WriteBoxed

func (ap *AnsiPixels) WriteBoxed(y int, msg string, args ...interface{})

func (*AnsiPixels) WriteCentered

func (ap *AnsiPixels) WriteCentered(y int, msg string, args ...interface{})

func (*AnsiPixels) WriteRight added in v0.14.2

func (ap *AnsiPixels) WriteRight(y int, msg string, args ...interface{})

func (*AnsiPixels) WriteRightBoxed added in v0.20.0

func (ap *AnsiPixels) WriteRightBoxed(y int, msg string, args ...interface{})

func (*AnsiPixels) WriteRune added in v0.20.0

func (ap *AnsiPixels) WriteRune(r rune)

func (*AnsiPixels) WriteString added in v0.20.0

func (ap *AnsiPixels) WriteString(msg string)

type Image added in v0.11.0

type Image struct {
	Format string
	Width  int
	Height int
	Images []*image.RGBA
	Delays []int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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