scuf

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 5 Imported by: 11

README

Simple Color bUFfers

PkgGoDev

Inspired by muesli/termenv. This lib for the sake of simplicity dropped terminal support (different color profiles and etc.). Though these might be added without problem. For now works for linux and some terminals. Primarily made for personal usage with more convenient and simple API than termenv.

See usage examples in cmd.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Foreground colors
	FgBlack   = FgANSI(0)
	FgRed     = FgANSI(1)
	FgGreen   = FgANSI(2)
	FgYellow  = FgANSI(3)
	FgBlue    = FgANSI(4)
	FgMagenta = FgANSI(5)
	FgCyan    = FgANSI(6)
	FgWhite   = FgANSI(7)
	// Foreground bright colors
	FgHiBlack   = FgANSI(8)
	FgHiRed     = FgANSI(9)
	FgHiGreen   = FgANSI(10)
	FgHiYellow  = FgANSI(11)
	FgHiBlue    = FgANSI(12)
	FgHiMagenta = FgANSI(13)
	FgHiCyan    = FgANSI(14)
	FgHiWhite   = FgANSI(15)

	// Background colors
	BgBlack   = BgANSI(0)
	BgRed     = BgANSI(1)
	BgGreen   = BgANSI(2)
	BgYellow  = BgANSI(3)
	BgBlue    = BgANSI(4)
	BgMagenta = BgANSI(5)
	BgCyan    = BgANSI(6)
	BgWhite   = BgANSI(7)
	// Background bright colors
	BgHiBlack   = BgANSI(8)
	BgHiRed     = BgANSI(9)
	BgHiGreen   = BgANSI(10)
	BgHiYellow  = BgANSI(11)
	BgHiBlue    = BgANSI(12)
	BgHiMagenta = BgANSI(13)
	BgHiCyan    = BgANSI(14)
	BgHiWhite   = BgANSI(15)

	ModReset     = Modifier("0")
	ModBold      = Modifier("1")
	ModFaint     = Modifier("2")
	ModItalic    = Modifier("3")
	ModUnderline = Modifier("4")
	ModBlink     = Modifier("5")
	ModReverse   = Modifier("7")
	ModCrossout  = Modifier("9")
	ModOverline  = Modifier("53")
)

Functions

func MustParseHexRGB

func MustParseHexRGB(hex string) (r, g, b uint8)

MustParseHexRGB parses hex color string, in form "#f0c" or "#ff1034". If color is invalid, returns black (or junk)

func NewString

func NewString(f func(Buffer)) string

NewString creates a string from a function modifying buffer

func String

func String(s string, mods ...Modifier) string

String creates a string with given modifiers

func ToHex

func ToHex(color Modifier) string

Types

type Buffer

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

func New

func New(out io.Writer) Buffer

func (Buffer) Bytes

func (b Buffer) Bytes(bs ...byte) Buffer

Bytes writes bytes to buffer

func (Buffer) ChangeScrollingRegion

func (b Buffer) ChangeScrollingRegion(top, bottom int) Buffer

ChangeScrollingRegion sets the scrolling region of the terminal

func (Buffer) ClearLine

func (b Buffer) ClearLine() Buffer

ClearLine clears the current line.

func (Buffer) ClearLineLeft

func (b Buffer) ClearLineLeft() Buffer

ClearLineLeft clears the line to the left of the cursor.

func (Buffer) ClearLineRight

func (b Buffer) ClearLineRight() Buffer

ClearLineRight clears the line to the right of the cursor.

func (Buffer) ClearLines

func (b Buffer) ClearLines(n int) Buffer

ClearLines clears a given number of lines.

func (Buffer) ClearScreen

func (b Buffer) ClearScreen() Buffer

ClearScreen clears the visible portion of the terminal.

func (Buffer) Copy

func (b Buffer) Copy(str string) Buffer

Copy text to clipboard using OSC 52 escape sequence

func (Buffer) CopyPrimary

func (b Buffer) CopyPrimary(str string) Buffer

CopyPrimary text to primary clipboard (X11) using OSC 52 escape sequence

func (Buffer) CursorBack

func (b Buffer) CursorBack(n int) Buffer

CursorBack moves the cursor backwards a given number of cells.

func (Buffer) CursorDown

func (b Buffer) CursorDown(n int) Buffer

CursorDown moves the cursor down a given number of lines.

func (Buffer) CursorForward

func (b Buffer) CursorForward(n int) Buffer

CursorForward moves the cursor up a given number of lines.

func (Buffer) CursorNextLine

func (b Buffer) CursorNextLine(n int) Buffer

CursorNextLine moves the cursor down a given number of lines and places it at the beginning of the line.

func (Buffer) CursorPrevLine

func (b Buffer) CursorPrevLine(n int) Buffer

CursorPrevLine moves the cursor up a given number of lines and places it at the beginning of the line.

func (Buffer) CursorUp

func (b Buffer) CursorUp(n int) Buffer

CursorUp moves the cursor up a given number of lines.

func (Buffer) DeleteLines

func (b Buffer) DeleteLines(n int) Buffer

DeleteLines deletes the given number of lines, pulling any lines in the scrollable region below up

func (Buffer) Disable

func (b Buffer) Disable(d Device) Buffer

Disable device. See devices for details

func (Buffer) Enable

func (b Buffer) Enable(d Device) Buffer

Enable device. See devices for details

func (b Buffer) Hyperlink(link, name string) Buffer

Hyperlink writes hyperlink using OSC8

func (Buffer) InBytePair

func (b Buffer) InBytePair(start, end byte, f func(Buffer)) Buffer

InBytePair writes callback inside given byte pair, e.g. parentheses or quotes

func (Buffer) InsertLines

func (b Buffer) InsertLines(n int) Buffer

InsertLines inserts the given number of lines at the top of the scrollable region, pushing lines below down.

func (Buffer) Iter

func (b Buffer) Iter(seq func(yield func(func(Buffer)) bool) bool) Buffer

Iter iterates callback with buffer modifier collbacks

func (Buffer) MoveCursor

func (b Buffer) MoveCursor(row, column int) Buffer

MoveCursor moves the cursor to a given position.

func (Buffer) NL

func (b Buffer) NL() Buffer

NL writes newline

func (Buffer) Notify

func (b Buffer) Notify(title, body string) Buffer

Notify triggers a notification using OSC777

func (Buffer) Printf

func (b Buffer) Printf(format string, args ...any) Buffer

Printf writes formatted data to buffer

func (Buffer) RepeatByte

func (b Buffer) RepeatByte(c byte, n int) Buffer

RepeatByte repeats byte n times

func (Buffer) RestoreCursorPosition

func (b Buffer) RestoreCursorPosition() Buffer

RestoreCursorPosition restores a saved cursor position.

func (Buffer) SPC

func (b Buffer) SPC() Buffer

SPC writes space

func (Buffer) SaveCursorPosition

func (b Buffer) SaveCursorPosition() Buffer

SaveCursorPosition saves the cursor position.

func (Buffer) SetBackgroundColor

func (b Buffer) SetBackgroundColor(hex string) Buffer

SetBackgroundColor set default background color

func (Buffer) SetCursorColor

func (b Buffer) SetCursorColor(hex string) Buffer

SetCursorColor set cursor color

func (Buffer) SetForegroundColor

func (b Buffer) SetForegroundColor(hex string) Buffer

SetForegroundColor set default foreground color

func (Buffer) SetWindowTitle

func (b Buffer) SetWindowTitle(title string) Buffer

SetWindowTitle sets the terminal window title

func (Buffer) String

func (b Buffer) String(s string, mods ...Modifier) Buffer

String writes string to buffer with given modifiers

func (Buffer) Styled

func (b Buffer) Styled(f func(Buffer), mods ...Modifier) Buffer

Styled write things in callback using modifiers. Don't use Styled inside Styled.

func (Buffer) TAB

func (b Buffer) TAB() Buffer

TAB writes tab

type Device

type Device int

Device things that can be enabled and disabled e.g. for handling events, changing to alt screen, showing/hiding cursor, etc.

const (
	// MousePress enables X10 mouse mode. Button press events are sent only. press only (X10)
	MousePress Device = 9
	// Cursor shows cursor on enable, hides on disable
	Cursor Device = 25
	// SaveScreen saves the screen state on enable, on disable restors previously saved screen state
	SaveScreen Device = 47
	// Mouse enables Mouse Tracking mode. press, release, wheel
	Mouse Device = 1000
	// MouseHilite enables Hilite Mouse Tracking mode.
	MouseHilite Device = 1001
	// MouseCellMotion enables Cell Motion Mouse Tracking mode. press, release, move on pressed, wheel
	MouseCellMotion Device = 1002
	// MouseAllMotion enables All Motion Mouse mode. press, release, move, wheel
	MouseAllMotion Device = 1003
	// MouseExtendedMotion enables Extended Mouse mode (SGR). This should be enabled in conjunction with
	// MouseCellMotion, and MouseAllMotion. press, release, move, wheel, extended coordinates
	MouseExtendedMode Device = 1006
	// MousePixelsMotion enables Pixel Motion Mouse mode (SGR-Pixels). This should be enabled in conjunction with
	// MouseCellMotion, and MouseAllMotion. press, release, move, wheel, extended pixel coordinates
	MousePixelsMode Device = 1016
	// AltScreen switches to the alternate screen buffer on enable. On disable former view is restored
	AltScreen Device = 1049
	// BracketedPaste enables bracketed paste
	BracketedPaste Device = 2004
)

type Modifier

type Modifier []byte

func BgANSI

func BgANSI(c int) Modifier

func BgRGB

func BgRGB(r, g, b uint8) Modifier

r,g,b are 0-255

func Combine

func Combine(mods ...Modifier) Modifier

func FgANSI

func FgANSI(c int) Modifier

func FgRGB

func FgRGB(r, g, b uint8) Modifier

r,g,b are 0-255

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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