Documentation
¶
Index ¶
- Variables
- type AnsiBuffer
- func (ap *AnsiBuffer) A(text string) *AnsiBuffer
- func (ap *AnsiBuffer) Attr(attr Attribute) *AnsiBuffer
- func (ap *AnsiBuffer) Bg(colour Colour) *AnsiBuffer
- func (ap *AnsiBuffer) BgGray(intensity uint) *AnsiBuffer
- func (ap *AnsiBuffer) BgGrayF(intensity float64) *AnsiBuffer
- func (ap *AnsiBuffer) BgHi(colour Colour) *AnsiBuffer
- func (ap *AnsiBuffer) BgRgb(r, g, b uint) *AnsiBuffer
- func (ap *AnsiBuffer) BgRgb6(r, g, b uint) *AnsiBuffer
- func (ap *AnsiBuffer) BgRgbI(i uint) *AnsiBuffer
- func (ap *AnsiBuffer) CR() *AnsiBuffer
- func (ap *AnsiBuffer) Clear() *AnsiBuffer
- func (ap *AnsiBuffer) CursorDown(count int) *AnsiBuffer
- func (ap *AnsiBuffer) CursorLeft(count int) *AnsiBuffer
- func (ap *AnsiBuffer) CursorRight(count int) *AnsiBuffer
- func (ap *AnsiBuffer) CursorUp(count int) *AnsiBuffer
- func (ap *AnsiBuffer) Esc(command rune, sep rune, codes ...int) *AnsiBuffer
- func (ap *AnsiBuffer) EscM(codes ...int) *AnsiBuffer
- func (ap *AnsiBuffer) Fg(colour Colour) *AnsiBuffer
- func (ap *AnsiBuffer) FgGray(intensity uint) *AnsiBuffer
- func (ap *AnsiBuffer) FgGrayF(intensity float64) *AnsiBuffer
- func (ap *AnsiBuffer) FgHi(colour Colour) *AnsiBuffer
- func (ap *AnsiBuffer) FgRgb(r, g, b uint) *AnsiBuffer
- func (ap *AnsiBuffer) FgRgb6(r, g, b uint) *AnsiBuffer
- func (ap *AnsiBuffer) FgRgbI(i uint) *AnsiBuffer
- func (ap *AnsiBuffer) GetBuffer() string
- func (ap *AnsiBuffer) IsEnabled() bool
- func (ap *AnsiBuffer) Reset() *AnsiBuffer
- func (ap *AnsiBuffer) S(format string, params ...interface{}) *AnsiBuffer
- func (ap *AnsiBuffer) SetEnabled(value bool)
- func (ap *AnsiBuffer) String() string
- type Attribute
- type Colour
- type FileTerminal
- func (t *FileTerminal) Fd() int
- func (t *FileTerminal) GetSize() (*unix.Winsize, error)
- func (t *FileTerminal) GetState() (*unix.Termios, error)
- func (t *FileTerminal) IsTerminal() bool
- func (t *FileTerminal) SetState(termState *unix.Termios) error
- func (t *FileTerminal) Write(s string) (n int, err error)
- type MockTerminal
- func (m *MockTerminal) Fd() int
- func (m *MockTerminal) GetSize() (*unix.Winsize, error)
- func (m *MockTerminal) GetState() (*unix.Termios, error)
- func (m *MockTerminal) IsTerminal() bool
- func (m *MockTerminal) ResetBuffer()
- func (m *MockTerminal) SetSize(w, h int, c chan os.Signal)
- func (m *MockTerminal) SetState(termState *unix.Termios) error
- func (m *MockTerminal) Write(s string) (n int, err error)
- type Screen
- type ScreenError
- type Terminal
Constants ¶
This section is empty.
Variables ¶
var Ansi = NewAnsiFor(os.Stdout)
Ansi is a default instance of AnsiBuffer
Functions ¶
This section is empty.
Types ¶
type AnsiBuffer ¶
type AnsiBuffer struct {
// ColorCompatibility allows usage of 24-bit colours on terminals that support only 256-colour mode when enabled.
ColorCompatibility bool
// contains filtered or unexported fields
}
func NewAnsi ¶
func NewAnsi() *AnsiBuffer
NewAnsi creates a new AnsiBuffer. It doesn't assume anything about the device that the output will be directed to.
func NewAnsiFor ¶
func NewAnsiFor(f *os.File) *AnsiBuffer
NewAnsiFor creates a new AnsiBuffer for a given device. It will not automatically print to this device, but it will disable ANSI colours if the device doesn't seem to support them, like when redirecting standard output into a file or piping it to another program
func (*AnsiBuffer) A ¶
func (ap *AnsiBuffer) A(text string) *AnsiBuffer
A adds text to the AnsiBuffer's buffer. The text will be output with the current colours and attributes
func (*AnsiBuffer) Attr ¶
func (ap *AnsiBuffer) Attr(attr Attribute) *AnsiBuffer
Attr sets font attribute
func (*AnsiBuffer) Bg ¶
func (ap *AnsiBuffer) Bg(colour Colour) *AnsiBuffer
Bg sets background colour. If colour is one of the standard 8 colours, it will use a basic ANSI sequence. If colour is larger than 8, it will be treated as a 256-colour code and the corresponding ANSI sequence will be used. To use 24-bit colour on supported terminals, use BgRgb or BgRgbI methods instead. To use 24-bit colour with 256-colour terminals, use BgRgb6 method or Rgb6x6x6 function to convert RGB values to 256-colour code.
func (*AnsiBuffer) BgGray ¶
func (ap *AnsiBuffer) BgGray(intensity uint) *AnsiBuffer
BgGray sets background colour that is the shade of grey. intensity is a value in a range [0..24]. It is converted to one of standard 24 grey shades in the 256-colour palette
func (*AnsiBuffer) BgGrayF ¶
func (ap *AnsiBuffer) BgGrayF(intensity float64) *AnsiBuffer
BgGrayF sets background colour that is the shade of grey. intensity is a floating point value in a range [0..1]. It is converted to one of standard 24 grey shades in the 256-colour palette
func (*AnsiBuffer) BgHi ¶
func (ap *AnsiBuffer) BgHi(colour Colour) *AnsiBuffer
BgHi sets background colour to the high intensity version of one of standard 8 colours
If used with one of 256 colour codes, it will just set the colour, without modifying the intensity
func (*AnsiBuffer) BgRgb ¶
func (ap *AnsiBuffer) BgRgb(r, g, b uint) *AnsiBuffer
BgRgb sets foreground colour using "true colour" RGB colour
func (*AnsiBuffer) BgRgb6 ¶
func (ap *AnsiBuffer) BgRgb6(r, g, b uint) *AnsiBuffer
BgRgb6 sets background RGB colour converted to 9-bit colour (3;3;3) as supported by 256-colour ANSI sequence
func (*AnsiBuffer) BgRgbI ¶
func (ap *AnsiBuffer) BgRgbI(i uint) *AnsiBuffer
BgRgbI sets background colour using "true colour" RGB colour represented as a single integer
func (*AnsiBuffer) CR ¶
func (ap *AnsiBuffer) CR() *AnsiBuffer
CR adds carriage return character (ASCII 13) to the AnsiBuffer's buffer
func (*AnsiBuffer) Clear ¶
func (ap *AnsiBuffer) Clear() *AnsiBuffer
Clear resets the internal buffer, after calling it the AnsiBuffer is in a clean state, as if just created
func (*AnsiBuffer) CursorDown ¶ added in v0.3.3
func (ap *AnsiBuffer) CursorDown(count int) *AnsiBuffer
func (*AnsiBuffer) CursorLeft ¶ added in v0.3.3
func (ap *AnsiBuffer) CursorLeft(count int) *AnsiBuffer
func (*AnsiBuffer) CursorRight ¶ added in v0.3.3
func (ap *AnsiBuffer) CursorRight(count int) *AnsiBuffer
func (*AnsiBuffer) CursorUp ¶ added in v0.3.3
func (ap *AnsiBuffer) CursorUp(count int) *AnsiBuffer
func (*AnsiBuffer) Esc ¶
func (ap *AnsiBuffer) Esc(command rune, sep rune, codes ...int) *AnsiBuffer
Esc allows adding a custom Esc sequence to the buffer The sequence that will be added is:
ESC[codes sep codes sep codes sep command
i.e. Esc('m', ':', 4, 3) will create sequence 'ESC[4:3m' which will create curly underline in iTerm2
func (*AnsiBuffer) EscM ¶
func (ap *AnsiBuffer) EscM(codes ...int) *AnsiBuffer
EscM allows adding custom SGR sequences to the output EscM(38, 2, 0, 0, 255) will add sequence 'ESC[38;2;0;0;255m' to enable bright blue RGB colour
func (*AnsiBuffer) Fg ¶
func (ap *AnsiBuffer) Fg(colour Colour) *AnsiBuffer
Fg sets foreground colour. If colour is one of the standard 8 colours, it will use a basic ANSI sequence. If colour is larger than 8, it will be treated as a 256-colour code and the corresponding ANSI sequence will be used. To use 24-bit colour on supported terminals, use FgRgb or FgRgbI methods instead. To use 24-bit colour with 256-colour terminals, use FgRgb6 method or Rgb6x6x6 function to convert RGB values to 256-colour code.
func (*AnsiBuffer) FgGray ¶
func (ap *AnsiBuffer) FgGray(intensity uint) *AnsiBuffer
FgGray sets foreground colour that is the shade of grey. intensity is a value in a range [0..23]. It is converted to one of standard 24 grey shades in the 256-colour palette
func (*AnsiBuffer) FgGrayF ¶
func (ap *AnsiBuffer) FgGrayF(intensity float64) *AnsiBuffer
FgGrayF sets foreground colour that is the shade of grey. intensity is a floating point value in a range [0..1]. It is converted to one of standard 24 grey shades in the 256-colour palette
func (*AnsiBuffer) FgHi ¶
func (ap *AnsiBuffer) FgHi(colour Colour) *AnsiBuffer
FgHi sets foreground colour to the high intensity version of one of standard 8 colours
If used with one of 256 colour codes, it will just set the colour, without modifying the intensity
func (*AnsiBuffer) FgRgb ¶
func (ap *AnsiBuffer) FgRgb(r, g, b uint) *AnsiBuffer
FgRgb sets foreground colour using "true colour" RGB colour
func (*AnsiBuffer) FgRgb6 ¶
func (ap *AnsiBuffer) FgRgb6(r, g, b uint) *AnsiBuffer
FgRgb6 sets foreground RGB colour as supported by 256-colour ANSI sequence In this mode each colour component is represented by a value from 0 to 5. Values beyond range of [0..5] are clipped R, G and B values are combined to get one of 216 colours supported by terminal
func (*AnsiBuffer) FgRgbI ¶
func (ap *AnsiBuffer) FgRgbI(i uint) *AnsiBuffer
FgRgbI sets foreground colour using "true colour" RGB colour represented as a single integer
func (*AnsiBuffer) GetBuffer ¶
func (ap *AnsiBuffer) GetBuffer() string
GetBuffer retrieves internal buffer as a string without clearing it
func (*AnsiBuffer) IsEnabled ¶
func (ap *AnsiBuffer) IsEnabled() bool
IsEnabled returns true if colour output is enabled
func (*AnsiBuffer) Reset ¶
func (ap *AnsiBuffer) Reset() *AnsiBuffer
Reset resets all the colours and attributes to defaults
func (*AnsiBuffer) S ¶
func (ap *AnsiBuffer) S(format string, params ...interface{}) *AnsiBuffer
S adds formatted (similar to fmt.Sprintf) text to the AnsiBuffer's buffer. The text will be output with the current colours and attributes
func (*AnsiBuffer) SetEnabled ¶
func (ap *AnsiBuffer) SetEnabled(value bool)
SetEnabled enables or disables the colour output. This does not affect the string already in AnsiBuffer's buffer
func (*AnsiBuffer) String ¶
func (ap *AnsiBuffer) String() string
String converts the internal buffer to a string. The buffer is cleared after the call
type Colour ¶
type Colour = int
const ( Black Colour = 0 Red Colour = 1 Green Colour = 2 Yellow Colour = 3 Blue Colour = 4 Magenta Colour = 5 Cyan Colour = 6 White Colour = 7 Maroon Colour = 1 Olive Colour = 3 Purple Colour = 5 Teal Colour = 6 Silver Colour = 7 Grey Colour = 8 BrightRed Colour = 9 BrightGreen Colour = 10 Lime Colour = 10 BrightYellow Colour = 11 BrightBlue Colour = 12 Fuchsia Colour = 13 BrightMagenta Colour = 13 Aqua Colour = 14 BrightCyan Colour = 14 BrightWhite Colour = 15 Grey0 Colour = 16 DarkBlue Colour = 18 Blue3 Colour = 20 Blue1 Colour = 21 DarkGreen Colour = 22 DeepSkyBlue4 Colour = 25 DodgerBlue3 Colour = 26 DodgerBlue2 Colour = 27 Green4 Colour = 28 SpringGreen4 Colour = 29 Turquoise4 Colour = 30 DeepSkyBlue3 Colour = 32 DodgerBlue1 Colour = 33 Green3 Colour = 34 SpringGreen3 Colour = 35 DarkCyan Colour = 36 LightSeaGreen Colour = 37 DeepSkyBlue2 Colour = 38 DeepSkyBlue1 Colour = 39 SpringGreen2 Colour = 42 Cyan3 Colour = 43 DarkTurquoise Colour = 44 Turquoise2 Colour = 45 Green1 Colour = 46 SpringGreen1 Colour = 48 MediumSpringGreen Colour = 49 Cyan2 Colour = 50 Cyan1 Colour = 51 Purple4 Colour = 55 Purple3 Colour = 56 BlueViolet Colour = 57 Grey37 Colour = 59 MediumPurple4 Colour = 60 SlateBlue3 Colour = 62 RoyalBlue1 Colour = 63 Chartreuse4 Colour = 64 PaleTurquoise4 Colour = 66 SteelBlue Colour = 67 SteelBlue3 Colour = 68 CornflowerBlue Colour = 69 DarkSeaGreen4 Colour = 71 CadetBlue Colour = 72 SkyBlue3 Colour = 74 Chartreuse3 Colour = 76 PaleGreen3 Colour = 77 SeaGreen3 Colour = 78 Aquamarine3 Colour = 79 MediumTurquoise Colour = 80 SteelBlue1 Colour = 81 SeaGreen2 Colour = 83 SeaGreen1 Colour = 85 DarkSlateGray2 Colour = 87 DarkRed Colour = 88 DarkMagenta Colour = 91 Orange4 Colour = 94 LightPink4 Colour = 95 Plum4 Colour = 96 MediumPurple3 Colour = 98 SlateBlue1 Colour = 99 Wheat4 Colour = 101 Grey53 Colour = 102 LightSlateGrey Colour = 103 MediumPurple Colour = 104 LightSlateBlue Colour = 105 Yellow4 Colour = 106 DarkSeaGreen Colour = 108 LightSkyBlue3 Colour = 110 SkyBlue2 Colour = 111 Chartreuse2 Colour = 112 DarkSlateGray3 Colour = 116 SkyBlue1 Colour = 117 Chartreuse1 Colour = 118 LightGreen Colour = 120 Aquamarine1 Colour = 122 DarkSlateGray1 Colour = 123 DeepPink4 Colour = 125 MediumVioletRed Colour = 126 DarkViolet Colour = 128 MediumOrchid3 Colour = 133 MediumOrchid Colour = 134 DarkGoldenrod Colour = 136 RosyBrown Colour = 138 Grey63 Colour = 139 MediumPurple2 Colour = 140 MediumPurple1 Colour = 141 DarkKhaki Colour = 143 Grey69 Colour = 145 LightSteelBlue3 Colour = 146 LightSteelBlue Colour = 147 DarkOliveGreen3 Colour = 149 DarkSeaGreen3 Colour = 150 LightCyan3 Colour = 152 LightSkyBlue1 Colour = 153 GreenYellow Colour = 154 DarkOliveGreen2 Colour = 155 PaleGreen1 Colour = 156 DarkSeaGreen1 Colour = 158 PaleTurquoise1 Colour = 159 Red3 Colour = 160 DeepPink3 Colour = 162 Magenta3 Colour = 164 DarkOrange3 Colour = 166 IndianRed Colour = 167 HotPink3 Colour = 168 HotPink2 Colour = 169 Orchid Colour = 170 Orange3 Colour = 172 LightSalmon3 Colour = 173 LightPink3 Colour = 174 Pink3 Colour = 175 Plum3 Colour = 176 Violet Colour = 177 Gold3 Colour = 178 LightGoldenrod3 Colour = 179 Tan Colour = 180 MistyRose3 Colour = 181 Thistle3 Colour = 182 Plum2 Colour = 183 Yellow3 Colour = 184 Khaki3 Colour = 185 LightYellow3 Colour = 187 Grey84 Colour = 188 LightSteelBlue1 Colour = 189 Yellow2 Colour = 190 DarkOliveGreen1 Colour = 192 Honeydew2 Colour = 194 LightCyan1 Colour = 195 Red1 Colour = 196 DeepPink2 Colour = 197 DeepPink1 Colour = 199 Magenta2 Colour = 200 Magenta1 Colour = 201 OrangeRed1 Colour = 202 IndianRed1 Colour = 204 HotPink Colour = 206 MediumOrchid1 Colour = 207 DarkOrange Colour = 208 Salmon1 Colour = 209 LightCoral Colour = 210 PaleVioletRed1 Colour = 211 Orchid2 Colour = 212 Orchid1 Colour = 213 Orange1 Colour = 214 SandyBrown Colour = 215 LightSalmon1 Colour = 216 LightPink1 Colour = 217 Pink1 Colour = 218 Plum1 Colour = 219 Gold1 Colour = 220 LightGoldenrod2 Colour = 222 MistyRose1 Colour = 224 Thistle1 Colour = 225 Yellow1 Colour = 226 LightGoldenrod1 Colour = 227 Khaki1 Colour = 228 Wheat1 Colour = 229 Cornsilk1 Colour = 230 Grey100 Colour = 231 Grey3 Colour = 232 Grey7 Colour = 233 Grey11 Colour = 234 Grey15 Colour = 235 Grey19 Colour = 236 Grey23 Colour = 237 Grey27 Colour = 238 Grey30 Colour = 239 Grey35 Colour = 240 Grey39 Colour = 241 Grey42 Colour = 242 Grey46 Colour = 243 Grey50 Colour = 244 Grey54 Colour = 245 Grey58 Colour = 246 Grey62 Colour = 247 Grey66 Colour = 248 Grey70 Colour = 249 Grey74 Colour = 250 Grey78 Colour = 251 Grey82 Colour = 252 Grey85 Colour = 253 Grey89 Colour = 254 Grey93 Colour = 255 )
type FileTerminal ¶ added in v0.4.0
type FileTerminal struct {
// contains filtered or unexported fields
}
FileTerminal implements the Terminal interface backed by an os.File.
func NewTerminalFromFile ¶ added in v0.4.0
func NewTerminalFromFile(file *os.File) (*FileTerminal, error)
func (*FileTerminal) Fd ¶ added in v0.4.0
func (t *FileTerminal) Fd() int
func (*FileTerminal) GetSize ¶ added in v0.4.0
func (t *FileTerminal) GetSize() (*unix.Winsize, error)
GetSize implements Terminal.
func (*FileTerminal) GetState ¶ added in v0.4.0
func (t *FileTerminal) GetState() (*unix.Termios, error)
func (*FileTerminal) IsTerminal ¶ added in v0.4.0
func (t *FileTerminal) IsTerminal() bool
type MockTerminal ¶ added in v0.4.0
type MockTerminal struct {
FileDesc int
Width int
Height int
CursorX int
CursorY int
CursorVisible bool
State unix.Termios
Buffer strings.Builder
}
func NewMockTerminal ¶ added in v0.4.0
func NewMockTerminal(width, height int) *MockTerminal
func (*MockTerminal) GetSize ¶ added in v0.4.0
func (m *MockTerminal) GetSize() (*unix.Winsize, error)
GetSize implements Terminal.
func (*MockTerminal) GetState ¶ added in v0.4.0
func (m *MockTerminal) GetState() (*unix.Termios, error)
GetState implements Terminal.
func (*MockTerminal) IsTerminal ¶ added in v0.4.0
func (m *MockTerminal) IsTerminal() bool
IsTerminal implements Terminal.
func (*MockTerminal) ResetBuffer ¶ added in v0.4.0
func (m *MockTerminal) ResetBuffer()
func (*MockTerminal) SetSize ¶ added in v0.4.0
func (m *MockTerminal) SetSize(w, h int, c chan os.Signal)
type Screen ¶ added in v0.4.0
type Screen struct {
// Width represents the width of the terminal in characters. It is updated on resize.
Width int
// Height represents the height of the terminal in characters. It is updated on resize.
Height int
// CursorVisible indicates whether the cursor is currently visible.
CursorVisible bool
// contains filtered or unexported fields
}
Screen represents a terminal screen with methods to manipulate the terminal display.
func NewScreen ¶ added in v0.4.0
NewScreen initializes a new Screen using the standard output file descriptor,
func NewScreenFromFile ¶ added in v0.4.0
NewScreenFromFile initializes a new Screen using file descriptor of f parameter, switches the terminal into alternate buffer mode, and retrieves the terminal size.
func NewScreenFromTerminal ¶ added in v0.4.0
NewScreenFromTerminal initializes a new Screen using the provided Terminal interface,
func (*Screen) Clear ¶ added in v0.4.0
func (s *Screen) Clear()
Clear clears the terminal screen and moves the cursor to the home position.
func (*Screen) Close ¶ added in v0.4.0
func (s *Screen) Close()
Close closes the screen, restores the terminal state, and exits alternate buffer mode.
func (*Screen) MoveCursorTo ¶ added in v0.4.0
MoveCursorTo moves the cursor to the specified (x, y) position in the terminal. Coordinates are 1-based, where (1, 1) is the top-left corner
func (*Screen) SetCursorVisible ¶ added in v0.4.0
SetCursorVisible shows or hides the cursor in the terminal.
func (*Screen) SetRawMode ¶ added in v0.4.0
SetRawMode sets the terminal to raw mode or restores it to normal mode. In raw mode, input is not processed (no echo, no line buffering). This is useful for applications that need to handle input directly, like text editors or games.
type ScreenError ¶ added in v0.4.0
func NewScreenError ¶ added in v0.4.0
func NewScreenError(message string, cause error) ScreenError
func (ScreenError) Error ¶ added in v0.4.0
func (err ScreenError) Error() string
type Terminal ¶ added in v0.4.0
type Terminal interface {
// Fd returns the file descriptor of the terminal.
Fd() int
// Write writes data to the terminal.
Write(s string) (n int, err error)
// IsTerminal checks if the file descriptor is a terminal.
IsTerminal() bool
// GetState retrieves the current terminal state.
GetState() (*unix.Termios, error)
// SetState sets the terminal state to the provided termios structure.
SetState(termState *unix.Termios) error
// GetSize retrieves the size of the terminal.
GetSize() (*unix.Winsize, error) // Returns width and height of the terminal
}
Terminal interface defines abstract terminal operations.


