Documentation
¶
Overview ¶
Package tout provides utilities for terminal output.
The tout package includes various functionalities to enhance terminal output, such as text coloring using ANSI color codes. It defines the Term type, which can be used to manage terminal-related operations and settings.
The package includes a default Cursor that is used by helper functions to set the text colors and other display attributes.
example:
package main
import (
"github.com/pachecot/tout"
)
func main() {
tout.Println("Hello, World!")
}
The example above prints "Hello, World!" to the terminal using the default Cursor settings.
The tout package also provides functions to set the text color, background color, and font style of the text. These functions can be used to customize the appearance of the text output.
example:
package main
import (
"github.com/pachecot/tout"
"github.com/pachecot/tout/color24"
)
func main() {
tout.Foreground(color24.Blue)
tout.Println("This is blue text")
}
The example above sets the text color to blue and prints "This is blue text" to the terminal using the default Cursor settings.
The tout package also provides functions to set the font style of the text. These functions can be used to apply bold, italic, underline, and other font styles to the text output.
example:
package main
import (
"github.com/pachecot/tout"
)
func main() {
tout.SetFont(tout.BoldFont | tout.UnderlineFont)
tout.Println("This is bold underlined text")
}
The example above sets the font style to bold and underline and prints "This is bold underlined text" to the terminal using the default Cursor settings.
Index ¶
- Constants
- func AddStyle(f FontType)
- func Background(c Color)
- func DefaultBackground()
- func DefaultForeground()
- func Error(a ...any)
- func ErrorWriter() io.Writer
- func Errorf(format string, a ...any)
- func Errorln(a ...any)
- func Foreground(c Color)
- func Print(a ...any)
- func Printf(format string, a ...any)
- func Println(a ...any)
- func RemoveStyle(f FontType)
- func ResetBackground()
- func ResetFont()
- func ResetForeground()
- func SetDefaultCursor(c *Cursor)
- func SetErrorCursor(c *Cursor)
- func SetFont(f FontType)
- func Write[T string | []byte](t T)
- func Writer() io.Writer
- type Color
- type Cursor
- func (c *Cursor) Background(k Color)
- func (c *Cursor) DefaultBackground()
- func (c *Cursor) DefaultForeground()
- func (c *Cursor) Foreground(k Color)
- func (c *Cursor) Print(a ...any)
- func (c *Cursor) Printf(format string, a ...any)
- func (c *Cursor) Println(a ...any)
- func (c *Cursor) ResetBackground()
- func (c *Cursor) ResetForeground()
- func (c *Cursor) SetWriter(w io.Writer)
- func (c *Cursor) Writer() io.Writer
- type FontType
Constants ¶
const ( ESC = "\x1b" // Escape character CSI = ESC + "[" // Control Sequence Introducer )
ANSI escape codes and sequences.
Variables ¶
This section is empty.
Functions ¶
func AddStyle ¶
func AddStyle(f FontType)
AddStyle adds a style to the current font type of the default cursor.
func Background ¶
func Background(c Color)
Background sets the background color of the default cursor.
func DefaultBackground ¶
func DefaultBackground()
DefaultBackground sets the background color of the default cursor to the default value.
func DefaultForeground ¶
func DefaultForeground()
DefaultForeground sets the foreground color of the default cursor to the default value.
func ErrorWriter ¶
ErrorWriter returns the writer associated with the error cursor.
func Errorf ¶
Errorf formats according to a format specifier and writes to the error cursor's writer.
func Errorln ¶
func Errorln(a ...any)
Errorln prints the given arguments to the error cursor's writer with a newline.
func Foreground ¶
func Foreground(c Color)
Foreground sets the foreground color of the default cursor.
func Printf ¶
Printf formats according to a format specifier and writes to the default cursor's writer.
func Println ¶
func Println(a ...any)
Println prints the given arguments to the default cursor's writer with a newline.
func RemoveStyle ¶
func RemoveStyle(f FontType)
RemoveStyle removes a style from the current font type of the default cursor.
func ResetBackground ¶
func ResetBackground()
ResetBackground resets the background color of the default cursor to the default value.
func ResetFont ¶
func ResetFont()
ResetFont resets the font type of the default cursor to the default value.
func ResetForeground ¶
func ResetForeground()
ResetForeground resets the foreground color of the default cursor to the default value.
func SetDefaultCursor ¶
func SetDefaultCursor(c *Cursor)
SetDefaultCursor sets the default cursor for terminal output.
func SetErrorCursor ¶
func SetErrorCursor(c *Cursor)
SetErrorCursor sets the cursor for error output.
Types ¶
type Color ¶
Color interface represents a color that can provide ANSI escape codes for foreground and background colors.
type Cursor ¶
type Cursor struct {
Font FontType
Level supportscolor.ColorLevel
// contains filtered or unexported fields
}
Cursor represents a terminal cursor with associated writer, colors, and font styles.
func DefaultCursor ¶
func DefaultCursor() *Cursor
DefaultCursor returns sets the default cursor for terminal output.
func NewCursor ¶
NewCursor creates a new Cursor with the specified writer. It detects the color support level of the writer if it is a file.
If the writer is nil, it uses os.Stdout as the default writer.
func (*Cursor) Background ¶
Background sets the background color of the Cursor. If the color level is not supported, it resets the background color.
func (*Cursor) DefaultBackground ¶
func (c *Cursor) DefaultBackground()
DefaultBackground sets the background color of the Cursor to the default value.
func (*Cursor) DefaultForeground ¶
func (c *Cursor) DefaultForeground()
DefaultForeground sets the foreground color of the Cursor to the default value.
func (*Cursor) Foreground ¶
Foreground sets the foreground color of the Cursor. If the color level is not supported, it resets the foreground color.
func (*Cursor) Printf ¶
Printf formats according to a format specifier and writes to the Cursor's writer.
func (*Cursor) Println ¶
Println prints the given arguments to the Cursor's writer with a newline. The newline is not styled.
func (*Cursor) ResetBackground ¶
func (c *Cursor) ResetBackground()
ResetBackground resets the background color of the Cursor.
func (*Cursor) ResetForeground ¶
func (c *Cursor) ResetForeground()
ResetForeground resets the foreground color of the Cursor.
type FontType ¶
type FontType int
FontType represents different font styles that can be applied to terminal text.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package color16 provides a set of basic 16-color ANSI color definitions.
|
Package color16 provides a set of basic 16-color ANSI color definitions. |
|
Package color24 provides a comprehensive set of 24-bit color definitions.
|
Package color24 provides a comprehensive set of 24-bit color definitions. |
|
Package color256 provides a set of 256-color ANSI color definitions.
|
Package color256 provides a set of 256-color ANSI color definitions. |