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
- func AnsiClean(str []byte) ([]byte, int)
- func DrawAALine(img *image.NRGBA, x0, y0, x1, y1 float64, c color.NRGBA)
- func DrawLine(img *image.NRGBA, x0, y0, x1, y1 float64, c color.NRGBA)
- func FormatDate(d *time.Time) string
- func HSLToRGB(h, s, l float64) color.NRGBA
- func MergePlot(img *image.NRGBA, x, y int, c color.NRGBA, newalpha float64)
- type AnsiPixels
- func (ap *AnsiPixels) AltMod() bool
- func (ap *AnsiPixels) AnyModifier() bool
- func (ap *AnsiPixels) ChangeFPS(fps float64)
- func (ap *AnsiPixels) ClearEndOfLine()
- func (ap *AnsiPixels) ClearScreen()
- func (ap *AnsiPixels) CtrlMod() bool
- func (ap *AnsiPixels) DecodeImage(inp io.Reader) (*Image, error)
- func (ap *AnsiPixels) Draw216ColorImage(sx, sy int, img *image.RGBA) error
- func (ap *AnsiPixels) DrawBox(x, y, w, h int, topLeft, topRight, bottomLeft, bottomRight string)
- func (ap *AnsiPixels) DrawMonoImage(sx, sy int, img *image.Gray, color string) error
- func (ap *AnsiPixels) DrawRoundBox(x, y, w, h int)
- func (ap *AnsiPixels) DrawSquareBox(x, y, w, h int)
- func (ap *AnsiPixels) DrawTrueColorImage(sx, sy int, img *image.RGBA) error
- func (ap *AnsiPixels) EndSyncMode()
- func (ap *AnsiPixels) GetSize() (err error)
- func (ap *AnsiPixels) HandleSignal(s os.Signal) error
- func (ap *AnsiPixels) HideCursor()
- func (ap *AnsiPixels) IsResizeSignal(s os.Signal) bool
- func (ap *AnsiPixels) LeftClick() bool
- func (ap *AnsiPixels) LeftDrag() bool
- func (ap *AnsiPixels) Middle() bool
- func (ap *AnsiPixels) MiddleDrag() bool
- func (ap *AnsiPixels) MouseClickOff()
- func (ap *AnsiPixels) MouseClickOn()
- func (ap *AnsiPixels) MouseDecode()
- func (ap *AnsiPixels) MousePixelsOff()
- func (ap *AnsiPixels) MousePixelsOn()
- func (ap *AnsiPixels) MouseTrackingOff()
- func (ap *AnsiPixels) MouseTrackingOn()
- func (ap *AnsiPixels) MouseWheelDown() bool
- func (ap *AnsiPixels) MouseWheelUp() bool
- func (ap *AnsiPixels) MouseX10Off()
- func (ap *AnsiPixels) MouseX10On()
- func (ap *AnsiPixels) MoveCursor(x, y int)
- func (ap *AnsiPixels) MoveHorizontally(x int)
- func (ap *AnsiPixels) Open() (err error)
- func (ap *AnsiPixels) ReadCursorPos() (int, int, error)
- func (ap *AnsiPixels) ReadImage(path string) (*Image, error)
- func (ap *AnsiPixels) ReadOrResizeOrSignal() error
- func (ap *AnsiPixels) ReadOrResizeOrSignalOnce() (int, error)
- func (ap *AnsiPixels) Restore()
- func (ap *AnsiPixels) RightClick() bool
- func (ap *AnsiPixels) RightDrag() bool
- func (ap *AnsiPixels) ScreenWidth(str string) int
- func (ap *AnsiPixels) ShiftMod() bool
- func (ap *AnsiPixels) ShowCursor()
- func (ap *AnsiPixels) ShowImage(imagesRGBA *Image, zoom float64, offsetX, offsetY int, colorString string) error
- func (ap *AnsiPixels) StartSyncMode()
- func (ap *AnsiPixels) TruncateLeftToFit(msg string, maxWidth int) (string, int)
- func (ap *AnsiPixels) WriteAt(x, y int, msg string, args ...interface{})
- func (ap *AnsiPixels) WriteAtStr(x, y int, msg string)
- func (ap *AnsiPixels) WriteBoxed(y int, msg string, args ...interface{})
- func (ap *AnsiPixels) WriteCentered(y int, msg string, args ...interface{})
- func (ap *AnsiPixels) WriteRight(y int, msg string, args ...interface{})
- func (ap *AnsiPixels) WriteRightBoxed(y int, msg string, args ...interface{})
- func (ap *AnsiPixels) WriteRune(r rune)
- func (ap *AnsiPixels) WriteString(msg string)
- type Image
Constants ¶
const ( RoundTopLeft = "╭" RoundTopRight = "╮" RoundBottomLeft = "╰" RoundBottomRight = "╯" SquareTopLeft = "┌" SquareTopRight = "┐" SquareBottomLeft = "└" SquareBottomRight = "┘" Horizontal = "─" Vertical = "│" TopT = "┬" BottomT = "┴" LeftT = "├" RightT = "┤" MiddleCross = "┼" FullPixel = '█' TopHalfPixel = '▀' BottomHalfPixel = '▄' QLowLeft = '▖' QLowRight = '▗' QUpLeft = '▘' QUpRight = '▝' )
const ( Bold = "\x1b[1m" Dim = "\x1b[2m" Underlined = "\x1b[4m" Blink = "\x1b[5m" Reverse = "\x1b[7m" MoveLeft = "\033[1D" Reset = "\033[0m" // Foreground Colors. Black = "\033[30m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Purple = "\033[35m" Cyan = "\033[36m" Gray = "\033[37m" DarkGray = "\033[90m" BrightRed = "\033[91m" BrightGreen = "\033[92m" BrightYellow = "\033[93m" BrightBlue = "\033[94m" BrightPurple = "\033[95m" BrightCyan = "\033[96m" White = "\033[97m" // Select colors from the 256 colors set that are missing from. Orange = "\033[38;5;214m" // Combo for RGB full pixel (used by fps). RedPixel = Red + "█" GreenPixel = Green + "█" BluePixel = Blue + "█" ResetClear = Reset + " " )
Ansi codes.
const ( MouseLeft = 0b00 MouseMiddle = 0b01 MouseRight = 0b10 MouseMove = 0b100000 MouseWheelUp = 0b1000000 MouseWheelDown = 0b1000001 Shift = 0b000100 Alt = 0b001000 Ctrl = 0b010000 AllModifiers = Shift | Alt | Ctrl AnyModifierMask = ^AllModifiers // On a mac with a physical mouse, shift mousewheel is translated to button 6,7 which // here looks like we set the MouseRight bit (when shift-mousewheeling). MouseWheelMask = ^(AllModifiers | MouseRight) )
Variables ¶
This section is empty.
Functions ¶
func AnsiClean ¶ added in v0.21.0
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
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
Non aliased version. Brute force implementation of Bresenham's line algorithm.
func FormatDate ¶ added in v0.20.0
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 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) AltMod ¶ added in v0.25.0
func (ap *AnsiPixels) AltMod() bool
func (*AnsiPixels) AnyModifier ¶ added in v0.25.0
func (ap *AnsiPixels) AnyModifier() bool
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) CtrlMod ¶ added in v0.25.0
func (ap *AnsiPixels) CtrlMod() bool
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 (*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) LeftClick ¶ added in v0.24.0
func (ap *AnsiPixels) LeftClick() bool
func (*AnsiPixels) LeftDrag ¶ added in v0.24.0
func (ap *AnsiPixels) LeftDrag() bool
func (*AnsiPixels) Middle ¶ added in v0.26.1
func (ap *AnsiPixels) Middle() bool
func (*AnsiPixels) MiddleDrag ¶ added in v0.26.1
func (ap *AnsiPixels) MiddleDrag() 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) MouseWheelDown ¶ added in v0.26.0
func (ap *AnsiPixels) MouseWheelDown() bool
func (*AnsiPixels) MouseWheelUp ¶ added in v0.26.0
func (ap *AnsiPixels) MouseWheelUp() bool
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 and ends the syncmode.
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) RightClick ¶ added in v0.24.0
func (ap *AnsiPixels) RightClick() bool
func (*AnsiPixels) RightDrag ¶ added in v0.24.0
func (ap *AnsiPixels) RightDrag() bool
func (*AnsiPixels) ScreenWidth ¶ added in v0.20.0
func (ap *AnsiPixels) ScreenWidth(str string) int
func (*AnsiPixels) ShiftMod ¶ added in v0.25.0
func (ap *AnsiPixels) ShiftMod() bool
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)