Documentation
¶
Overview ¶
Package tea provides a framework for building rich terminal user interfaces based on the paradigms of The Elm Architecture. It's well-suited for simple and complex terminal applications, either inline, full-window, or a mix of both. It's been battle-tested in several large projects and is production-ready.
A tutorial is available at https://github.com/charmbracelet/bubbletea/tree/master/tutorials
Example programs can be found at https://github.com/charmbracelet/bubbletea/tree/master/examples
Index ¶
- Constants
- Variables
- func LogToFile(path string, prefix string) (*os.File, error)
- func LogToFileWith(path string, prefix string, log LogOptionsSetter) (*os.File, error)
- func WithKeyReleases(k *KeyboardEnhancements)
- func WithUniformKeyLayout(k *KeyboardEnhancements)
- type BackgroundColorMsg
- type BatchMsg
- type BlurMsg
- type CapabilityMsg
- type ClipboardMsg
- type Cmd
- func Batch(cmds ...Cmd) Cmd
- func Every(duration time.Duration, fn func(time.Time) Msg) Cmd
- func Exec(c ExecCommand, fn ExecCallback) Cmd
- func ExecProcess(c *exec.Cmd, fn ExecCallback) Cmd
- func Printf(template string, args ...interface{}) Cmd
- func Println(args ...interface{}) Cmd
- func Raw(r any) Cmd
- func RequestCapability(s string) Cmd
- func RequestKeyboardEnhancements(enhancements ...KeyboardEnhancementOption) Cmd
- func Sequence(cmds ...Cmd) Cmd
- func SetBackgroundColor(c color.Color) Cmd
- func SetClipboard(s string) Cmd
- func SetCursorColor(c color.Color) Cmd
- func SetForegroundColor(c color.Color) Cmd
- func SetPrimaryClipboard(s string) Cmd
- func SetWindowTitle(title string) Cmd
- func Tick(d time.Duration, fn func(time.Time) Msg) Cmd
- type ColorProfileMsg
- type Cursor
- type CursorColorMsg
- type CursorModel
- type CursorPositionMsg
- type CursorShape
- type EnvMsg
- type ExecCallback
- type ExecCommand
- type FocusMsg
- type ForegroundColorMsg
- type InterruptMsg
- type Key
- type KeyMod
- type KeyMsg
- type KeyPressMsg
- type KeyReleaseMsg
- type KeyboardEnhancementOption
- type KeyboardEnhancements
- type KeyboardEnhancementsMsg
- type LogOptionsSetter
- type Model
- type Mouse
- type MouseButton
- type MouseClickMsg
- type MouseMotionMsg
- type MouseMsg
- type MouseReleaseMsg
- type MouseWheelMsg
- type Msg
- func ClearScreen() Msg
- func DisableBracketedPaste() Msg
- func DisableGraphemeClustering() Msg
- func DisableKeyboardEnhancements() Msg
- func DisableMouse() Msg
- func DisableReportFocus() Msg
- func EnableBracketedPaste() Msg
- func EnableGraphemeClustering() Msg
- func EnableMouseAllMotion() Msg
- func EnableMouseCellMotion() Msg
- func EnableReportFocus() Msg
- func EnterAltScreen() Msg
- func ExitAltScreen() Msg
- func HideCursor() Msg
- func Interrupt() Msg
- func Quit() Msg
- func ReadClipboard() Msg
- func ReadPrimaryClipboard() Msg
- func RequestBackgroundColor() Msg
- func RequestCursorColor() Msg
- func RequestCursorPosition() Msg
- func RequestForegroundColor() Msg
- func RequestWindowSize() Msg
- func ShowCursor() Msg
- func Suspend() Msg
- func TerminalVersion() Msg
- type PasteEndMsg
- type PasteMsg
- type PasteStartMsg
- type Position
- type PrimaryClipboardMsg
- type Program
- func (p *Program) Kill()
- func (p *Program) Printf(template string, args ...interface{})
- func (p *Program) Println(args ...interface{})
- func (p *Program) Quit()
- func (p *Program) ReleaseTerminal() error
- func (p *Program) RestoreTerminal() error
- func (p *Program) Run() (Model, error)
- func (p *Program) Send(msg Msg)
- func (p *Program) Wait()
- type ProgramOption
- func WithAltScreen() ProgramOption
- func WithColorProfile(profile colorprofile.Profile) ProgramOption
- func WithContext(ctx context.Context) ProgramOption
- func WithEnvironment(env []string) ProgramOption
- func WithFPS(fps int) ProgramOption
- func WithFilter(filter func(Model, Msg) Msg) ProgramOption
- func WithGraphemeClustering() ProgramOption
- func WithInput(input io.Reader) ProgramOption
- func WithInputTTY() ProgramOption
- func WithKeyboardEnhancements(enhancements ...KeyboardEnhancementOption) ProgramOption
- func WithMouseAllMotion() ProgramOption
- func WithMouseCellMotion() ProgramOption
- func WithOutput(output io.Writer) ProgramOption
- func WithReportFocus() ProgramOption
- func WithWindowSize(width, height int) ProgramOption
- func WithoutBracketedPaste() ProgramOption
- func WithoutCatchPanics() ProgramOption
- func WithoutSignalHandler() ProgramOption
- func WithoutSignals() ProgramOption
- type QuitMsg
- type RawMsg
- type ResumeMsg
- type SuspendMsg
- type TerminalVersionMsg
- type ViewModel
- type WindowSizeMsg
Constants ¶
const ( KeyUp = input.KeyUp KeyDown = input.KeyDown KeyRight = input.KeyRight KeyLeft = input.KeyLeft KeyBegin = input.KeyBegin KeyFind = input.KeyFind KeyInsert = input.KeyInsert KeyDelete = input.KeyDelete KeySelect = input.KeySelect KeyPgUp = input.KeyPgUp KeyPgDown = input.KeyPgDown KeyHome = input.KeyHome KeyEnd = input.KeyEnd KeyKpEnter = input.KeyKpEnter KeyKpEqual = input.KeyKpEqual KeyKpMultiply = input.KeyKpMultiply KeyKpPlus = input.KeyKpPlus KeyKpComma = input.KeyKpComma KeyKpMinus = input.KeyKpMinus KeyKpDecimal = input.KeyKpDecimal KeyKpDivide = input.KeyKpDivide KeyKp0 = input.KeyKp0 KeyKp1 = input.KeyKp1 KeyKp2 = input.KeyKp2 KeyKp3 = input.KeyKp3 KeyKp4 = input.KeyKp4 KeyKp5 = input.KeyKp5 KeyKp6 = input.KeyKp6 KeyKp7 = input.KeyKp7 KeyKp8 = input.KeyKp8 KeyKp9 = input.KeyKp9 // The following are keys defined in the Kitty keyboard protocol. // XXX: Investigate the names of these keys. KeyKpSep = input.KeyKpSep KeyKpUp = input.KeyKpUp KeyKpDown = input.KeyKpDown KeyKpLeft = input.KeyKpLeft KeyKpRight = input.KeyKpRight KeyKpPgUp = input.KeyKpPgUp KeyKpPgDown = input.KeyKpPgDown KeyKpHome = input.KeyKpHome KeyKpEnd = input.KeyKpEnd KeyKpInsert = input.KeyKpInsert KeyKpDelete = input.KeyKpDelete KeyKpBegin = input.KeyKpBegin KeyF1 = input.KeyF1 KeyF2 = input.KeyF2 KeyF3 = input.KeyF3 KeyF4 = input.KeyF4 KeyF5 = input.KeyF5 KeyF6 = input.KeyF6 KeyF7 = input.KeyF7 KeyF8 = input.KeyF8 KeyF9 = input.KeyF9 KeyF10 = input.KeyF10 KeyF11 = input.KeyF11 KeyF12 = input.KeyF12 KeyF13 = input.KeyF13 KeyF14 = input.KeyF14 KeyF15 = input.KeyF15 KeyF16 = input.KeyF16 KeyF17 = input.KeyF17 KeyF18 = input.KeyF18 KeyF19 = input.KeyF19 KeyF20 = input.KeyF20 KeyF21 = input.KeyF21 KeyF22 = input.KeyF22 KeyF23 = input.KeyF23 KeyF24 = input.KeyF24 KeyF25 = input.KeyF25 KeyF26 = input.KeyF26 KeyF27 = input.KeyF27 KeyF28 = input.KeyF28 KeyF29 = input.KeyF29 KeyF30 = input.KeyF30 KeyF31 = input.KeyF31 KeyF32 = input.KeyF32 KeyF33 = input.KeyF33 KeyF34 = input.KeyF34 KeyF35 = input.KeyF35 KeyF36 = input.KeyF36 KeyF37 = input.KeyF37 KeyF38 = input.KeyF38 KeyF39 = input.KeyF39 KeyF40 = input.KeyF40 KeyF41 = input.KeyF41 KeyF42 = input.KeyF42 KeyF43 = input.KeyF43 KeyF44 = input.KeyF44 KeyF45 = input.KeyF45 KeyF46 = input.KeyF46 KeyF47 = input.KeyF47 KeyF48 = input.KeyF48 KeyF49 = input.KeyF49 KeyF50 = input.KeyF50 KeyF51 = input.KeyF51 KeyF52 = input.KeyF52 KeyF53 = input.KeyF53 KeyF54 = input.KeyF54 KeyF55 = input.KeyF55 KeyF56 = input.KeyF56 KeyF57 = input.KeyF57 KeyF58 = input.KeyF58 KeyF59 = input.KeyF59 KeyF60 = input.KeyF60 KeyF61 = input.KeyF61 KeyF62 = input.KeyF62 KeyF63 = input.KeyF63 KeyCapsLock = input.KeyCapsLock KeyScrollLock = input.KeyScrollLock KeyNumLock = input.KeyNumLock KeyPrintScreen = input.KeyPrintScreen KeyPause = input.KeyPause KeyMenu = input.KeyMenu KeyMediaPlay = input.KeyMediaPlay KeyMediaPause = input.KeyMediaPause KeyMediaPlayPause = input.KeyMediaPlayPause KeyMediaReverse = input.KeyMediaReverse KeyMediaStop = input.KeyMediaStop KeyMediaFastForward = input.KeyMediaFastForward KeyMediaRewind = input.KeyMediaRewind KeyMediaNext = input.KeyMediaNext KeyMediaPrev = input.KeyMediaPrev KeyMediaRecord KeyLowerVol = input.KeyLowerVol KeyRaiseVol = input.KeyRaiseVol KeyMute = input.KeyMute KeyLeftShift = input.KeyLeftShift KeyLeftAlt = input.KeyLeftAlt KeyLeftCtrl = input.KeyLeftCtrl KeyLeftSuper = input.KeyLeftSuper KeyLeftHyper = input.KeyLeftHyper KeyLeftMeta = input.KeyLeftMeta KeyRightShift = input.KeyRightShift KeyRightAlt = input.KeyRightAlt KeyRightCtrl = input.KeyRightCtrl KeyRightSuper = input.KeyRightSuper KeyRightHyper = input.KeyRightHyper KeyRightMeta = input.KeyRightMeta KeyIsoLevel3Shift = input.KeyIsoLevel3Shift KeyIsoLevel5Shift = input.KeyIsoLevel5Shift KeyBackspace = input.KeyBackspace KeyTab = input.KeyTab KeyEnter = input.KeyEnter KeyReturn = input.KeyReturn KeyEscape = input.KeyEscape KeyEsc = input.KeyEsc KeySpace = input.KeySpace )
Special key symbols.
const ( ModShift = input.ModShift ModAlt = input.ModAlt ModCtrl = input.ModCtrl ModMeta = input.ModMeta ModHyper = input.ModHyper ModSuper = input.ModSuper // Windows/Command keys ModCapsLock = input.ModCapsLock ModNumLock = input.ModNumLock ModScrollLock = input.ModScrollLock // Defined in Windows API only )
Modifier keys.
const ( MouseNone = input.MouseNone MouseLeft = input.MouseLeft MouseMiddle = input.MouseMiddle MouseRight = input.MouseRight MouseWheelUp = input.MouseWheelUp MouseWheelDown = input.MouseWheelDown MouseWheelLeft = input.MouseWheelLeft MouseWheelRight = input.MouseWheelRight MouseBackward = input.MouseBackward MouseForward = input.MouseForward MouseButton10 = input.MouseButton10 MouseButton11 )
Mouse event buttons
This is based on X11 mouse button codes.
1 = left button 2 = middle button (pressing the scroll wheel) 3 = right button 4 = turn scroll wheel up 5 = turn scroll wheel down 6 = push scroll wheel left 7 = push scroll wheel right 8 = 4th button (aka browser backward button) 9 = 5th button (aka browser forward button) 10 11
Other buttons are not supported.
const ( // KeyExtended is a special key code used to signify that a key event // contains multiple runes. KeyExtended = input.KeyExtended )
Variables ¶
var ErrInterrupted = errors.New("program was interrupted")
ErrInterrupted is returned by Program.Run when the program get a SIGINT signal, or when it receives a InterruptMsg.
var ErrProgramKilled = errors.New("program was killed")
ErrProgramKilled is returned by Program.Run when the program gets killed.
Functions ¶
func LogToFile ¶
LogToFile sets up default logging to log to a file. This is helpful as we can't print to the terminal since our TUI is occupying it. If the file doesn't exist it will be created.
Don't forget to close the file when you're done with it.
f, err := LogToFile("debug.log", "debug") if err != nil { fmt.Println("fatal:", err) os.Exit(1) } defer f.Close()
func LogToFileWith ¶
LogToFileWith does allows to call LogToFile with a custom LogOptionsSetter.
func WithKeyReleases ¶
func WithKeyReleases(k *KeyboardEnhancements)
WithKeyReleases enables support for reporting release key events. This is useful for terminals that support the Kitty keyboard protocol "Report event types" progressive enhancement feature.
Note that not all terminals support this feature.
func WithUniformKeyLayout ¶
func WithUniformKeyLayout(k *KeyboardEnhancements)
WithUniformKeyLayout enables support for reporting key events as though they were on a PC-101 layout. This is useful for uniform key event reporting across different keyboard layouts. This is equivalent to the Kitty keyboard protocol "Report alternate keys" and "Report all keys as escape codes" progressive enhancement features.
Note that not all terminals support this feature.
Types ¶
type BackgroundColorMsg ¶
BackgroundColorMsg represents a background color message. This message is emitted when the program requests the terminal background color with the RequestBackgroundColor Cmd.
This is commonly used in [Update.Init] to get the terminal background color for style definitions. For that you'll want to call BackgroundColorMsg.IsDark to determine if the color is dark or light. For example:
func (m Model) Init() (Model, Cmd) { return m, RequestBackgroundColor() } func (m Model) Update(msg Msg) (Model, Cmd) { switch msg := msg.(type) { case BackgroundColorMsg: m.styles = newStyles(msg.IsDark()) } }
func (BackgroundColorMsg) IsDark ¶
func (e BackgroundColorMsg) IsDark() bool
IsDark returns whether the color is dark.
func (BackgroundColorMsg) String ¶
func (e BackgroundColorMsg) String() string
String returns the hex representation of the color.
type BatchMsg ¶
type BatchMsg []Cmd
BatchMsg is a message used to perform a bunch of commands concurrently with no ordering guarantees. You can send a BatchMsg with Batch.
type BlurMsg ¶
type BlurMsg struct{}
BlurMsg represents a terminal blur message. This occurs when the terminal loses focus.
type CapabilityMsg ¶
type CapabilityMsg string
CapabilityMsg represents a Termcap/Terminfo response event. Termcap responses are generated by the terminal in response to RequestTermcap (XTGETTCAP) requests.
See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
type ClipboardMsg ¶
type ClipboardMsg string
ClipboardMsg is a clipboard read message event. This message is emitted when a terminal receives an OSC52 clipboard read message event.
func (ClipboardMsg) String ¶
func (e ClipboardMsg) String() string
String returns the string representation of the clipboard message.
type Cmd ¶
type Cmd func() Msg
Cmd is an IO operation that returns a message when it's complete. If it's nil it's considered a no-op. Use it for things like HTTP requests, timers, saving and loading from disk, and so on.
Note that there's almost never a reason to use a command to send a message to another part of your program. That can almost always be done in the update function.
func Batch ¶
Batch performs a bunch of commands concurrently with no ordering guarantees about the results. Use a Batch to return several commands.
Example:
func (m model) Init() (Model, Cmd) { return m, tea.Batch(someCommand, someOtherCommand) }
func Every ¶
Every is a command that ticks in sync with the system clock. So, if you wanted to tick with the system clock every second, minute or hour you could use this. It's also handy for having different things tick in sync.
Because we're ticking with the system clock the tick will likely not run for the entire specified duration. For example, if we're ticking for one minute and the clock is at 12:34:20 then the next tick will happen at 12:35:00, 40 seconds later.
To produce the command, pass a duration and a function which returns a message containing the time at which the tick occurred.
type TickMsg time.Time cmd := Every(time.Second, func(t time.Time) Msg { return TickMsg(t) })
Beginners' note: Every sends a single message and won't automatically dispatch messages at an interval. To do that, you'll want to return another Every command after receiving your tick message. For example:
type TickMsg time.Time // Send a message every second. func tickEvery() Cmd { return Every(time.Second, func(t time.Time) Msg { return TickMsg(t) }) } func (m model) Init() (Model, Cmd) { // Start ticking. return m, tickEvery() } func (m model) Update(msg Msg) (Model, Cmd) { switch msg.(type) { case TickMsg: // Return your Every command again to loop. return m, tickEvery() } return m, nil }
Every is analogous to Tick in the Elm Architecture.
func Exec ¶
func Exec(c ExecCommand, fn ExecCallback) Cmd
Exec is used to perform arbitrary I/O in a blocking fashion, effectively pausing the Program while execution is running and resuming it when execution has completed.
Most of the time you'll want to use ExecProcess, which runs an exec.Cmd.
For non-interactive i/o you should use a Cmd (that is, a tea.Cmd).
func ExecProcess ¶
func ExecProcess(c *exec.Cmd, fn ExecCallback) Cmd
ExecProcess runs the given *exec.Cmd in a blocking fashion, effectively pausing the Program while the command is running. After the *exec.Cmd exists the Program resumes. It's useful for spawning other interactive applications such as editors and shells from within a Program.
To produce the command, pass an *exec.Cmd and a function which returns a message containing the error which may have occurred when running the ExecCommand.
type VimFinishedMsg struct { err error } c := exec.Command("vim", "file.txt") cmd := ExecProcess(c, func(err error) Msg { return VimFinishedMsg{err: err} })
Or, if you don't care about errors, you could simply:
cmd := ExecProcess(exec.Command("vim", "file.txt"), nil)
For non-interactive i/o you should use a Cmd (that is, a tea.Cmd).
func Printf ¶
Printf prints above the Program. It takes a format template followed by values similar to fmt.Printf. This output is unmanaged by the program and will persist across renders by the Program.
Unlike fmt.Printf (but similar to log.Printf) the message will be print on its own line.
If the altscreen is active no output will be printed.
func Println ¶
func Println(args ...interface{}) Cmd
Println prints above the Program. This output is unmanaged by the program and will persist across renders by the Program.
Unlike fmt.Println (but similar to log.Println) the message will be print on its own line.
If the altscreen is active no output will be printed.
func Raw ¶
Raw is a command that prints the given string to the terminal without any formatting.
This is intended for advanced use cases where you need to query the terminal or send escape sequences directly. Don't use this unless you know what you're doing :)
Example:
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case input.PrimaryDeviceAttributesEvent: for _, attr := range msg { if attr == 4 { // We have Sixel graphics support! break } } } // Request the terminal primary device attributes to detect Sixel graphics // support. return m, tea.Raw(ansi.RequestPrimaryDeviceAttributes) }
func RequestCapability ¶
RequestCapability is a command that requests the terminal to send its Termcap/Terminfo response for the given capability.
Bubble Tea recognizes the following capabilities and will use them to upgrade the program's color profile:
- "RGB" Xterm direct color
- "Tc" True color support
Note: that some terminal's like Apple's Terminal.app do not support this and will send the wrong response to the terminal breaking the program's output.
When the Bubble Tea advertises a non-TrueColor profile, you can use this command to query the terminal for its color capabilities. Example:
switch msg := msg.(type) { case tea.ColorProfileMsg: if msg.Profile != colorprofile.TrueColor { return m, tea.Batch( tea.RequestCapability("RGB"), tea.RequestCapability("Tc"), ) } }
func RequestKeyboardEnhancements ¶
func RequestKeyboardEnhancements(enhancements ...KeyboardEnhancementOption) Cmd
RequestKeyboardEnhancements is a command that enables keyboard enhancements in the terminal.
This command can be used to request specific keyboard enhancements. Use this command to request enabling support for key disambiguation. You can also request other enhancements by passing additional options. For example:
- WithKeyReleases enables support for reporting release key events.
- WithUniformKeyLayout enables support for reporting key events as though they were on a PC-101 layout.
If the terminal supports the requested enhancements, it will send a KeyboardEnhancementsMsg message with the supported enhancements.
Note that not all terminals support all enhancements.
func Sequence ¶
Sequence runs the given commands one at a time, in order. Contrast this with Batch, which runs commands concurrently.
func SetBackgroundColor ¶
SetBackgroundColor is a command that sets the terminal background color.
func SetClipboard ¶
SetClipboard produces a command that sets the system clipboard using OSC52. Note that OSC52 is not supported in all terminals.
func SetCursorColor ¶
SetCursorColor is a command that sets the terminal cursor color.
func SetForegroundColor ¶
SetForegroundColor is a command that sets the terminal foreground color.
func SetPrimaryClipboard ¶
SetPrimaryClipboard produces a command that sets the primary clipboard using OSC52. Primary clipboard selection is a feature present in X11 and Wayland only. Note that OSC52 is not supported in all terminals.
func SetWindowTitle ¶
SetWindowTitle produces a command that sets the terminal title.
For example:
func (m model) Init() (Model, Cmd) { // Set title. return m, tea.SetWindowTitle("My App") }
func Tick ¶
Tick produces a command at an interval independent of the system clock at the given duration. That is, the timer begins precisely when invoked, and runs for its entire duration.
To produce the command, pass a duration and a function which returns a message containing the time at which the tick occurred.
type TickMsg time.Time cmd := Tick(time.Second, func(t time.Time) Msg { return TickMsg(t) })
Beginners' note: Tick sends a single message and won't automatically dispatch messages at an interval. To do that, you'll want to return another Tick command after receiving your tick message. For example:
type TickMsg time.Time func doTick() Cmd { return Tick(time.Second, func(t time.Time) Msg { return TickMsg(t) }) } func (m model) Init() (Model, Cmd) { // Start ticking. return m, doTick() } func (m model) Update(msg Msg) (Model, Cmd) { switch msg.(type) { case TickMsg: // Return your Tick command again to loop. return m, doTick() } return m, nil }
type ColorProfileMsg ¶
type ColorProfileMsg struct {
colorprofile.Profile
}
ColorProfileMsg is a message that describes the terminal's color profile. This message is send to the program's update function when the program is started.
To upgrade the terminal color profile, use the `tea.RequestCapability` command to request the `RGB` and `Tc` terminfo capabilities. Bubble Tea will then cache the terminal's color profile and send a `ColorProfileMsg` to the program's update function.
type Cursor ¶
type Cursor struct { // Position is a [Position] that determines the cursor's position on the // screen relative to the top left corner of the frame. Position // Color is a [color.Color] that determines the cursor's color. Color color.Color // Shape is a [CursorShape] that determines the cursor's shape. Shape CursorShape // Blink is a boolean that determines whether the cursor should blink. Blink bool }
Cursor represents a cursor on the terminal screen.
type CursorColorMsg ¶
CursorColorMsg represents a cursor color change message. This message is emitted when the program requests the terminal cursor color.
func (CursorColorMsg) IsDark ¶
func (e CursorColorMsg) IsDark() bool
IsDark returns whether the color is dark.
func (CursorColorMsg) String ¶
func (e CursorColorMsg) String() string
String returns the hex representation of the color.
type CursorModel ¶
type CursorModel interface { // View renders the program's UI, which is just a string. The view is // rendered after every Update. The cursor is optional, if it's nil the // cursor will be hidden. // Use [NewCursor] to quickly create a cursor for a given position with // default styles. View() (string, *Cursor) }
CursorModel is an optional interface that can be implemented by the main model to provide a view that manages the cursor. If the main model does not implement a view interface, the program won't render anything.
type CursorPositionMsg ¶
type CursorPositionMsg Position
CursorPositionMsg is a message that represents the terminal cursor position.
type CursorShape ¶
type CursorShape int
CursorShape represents a terminal cursor shape.
const ( CursorBlock CursorShape = iota CursorUnderline CursorBar )
Cursor shapes.
type EnvMsg ¶
type EnvMsg environ
EnvMsg is a message that represents the environment variables of the program. This is useful for getting the environment variables of programs running in a remote session like SSH. In that case, using os.Getenv would return the server's environment variables, not the client's.
This message is sent to the program when it starts.
Example:
switch msg := msg.(type) { case EnvMsg: // What terminal type is being used? term := msg.Getenv("TERM") }
func (EnvMsg) Getenv ¶
Getenv returns the value of the environment variable named by the key. If the variable is not present in the environment, the value returned will be the empty string.
type ExecCallback ¶
ExecCallback is used when executing an *exec.Command to return a message with an error, which may or may not be nil.
type ExecCommand ¶
type ExecCommand interface { Run() error SetStdin(io.Reader) SetStdout(io.Writer) SetStderr(io.Writer) }
ExecCommand can be implemented to execute things in a blocking fashion in the current terminal.
type FocusMsg ¶
type FocusMsg struct{}
FocusMsg represents a terminal focus message. This occurs when the terminal gains focus.
type ForegroundColorMsg ¶
ForegroundColorMsg represents a foreground color message. This message is emitted when the program requests the terminal foreground color with the RequestForegroundColor Cmd.
func (ForegroundColorMsg) IsDark ¶
func (e ForegroundColorMsg) IsDark() bool
IsDark returns whether the color is dark.
func (ForegroundColorMsg) String ¶
func (e ForegroundColorMsg) String() string
String returns the hex representation of the color.
type InterruptMsg ¶
type InterruptMsg struct{}
InterruptMsg signals the program should suspend. This usually happens when ctrl+c is pressed on common programs, but since bubbletea puts the terminal in raw mode, we need to handle it in a per-program basis.
You can send this message with [Interrupt()].
type Key ¶
type Key struct { // Text contains the actual characters received. This usually the same as // [Key.Code]. When [Key.Text] is non-empty, it indicates that the key // pressed represents printable character(s). Text string // Mod represents modifier keys, like [ModCtrl], [ModAlt], and so on. Mod KeyMod // Code represents the key pressed. This is usually a special key like // [KeyTab], [KeyEnter], [KeyF1], or a printable character like 'a'. Code rune // ShiftedCode is the actual, shifted key pressed by the user. For example, // if the user presses shift+a, or caps lock is on, [Key.ShiftedCode] will // be 'A' and [Key.Code] will be 'a'. // // In the case of non-latin keyboards, like Arabic, [Key.ShiftedCode] is the // unshifted key on the keyboard. // // This is only available with the Kitty Keyboard Protocol or the Windows // Console API. ShiftedCode rune // BaseCode is the key pressed according to the standard PC-101 key layout. // On international keyboards, this is the key that would be pressed if the // keyboard was set to US PC-101 layout. // // For example, if the user presses 'q' on a French AZERTY keyboard, // [Key.BaseCode] will be 'q'. // // This is only available with the Kitty Keyboard Protocol or the Windows // Console API. BaseCode rune // IsRepeat indicates whether the key is being held down and sending events // repeatedly. // // This is only available with the Kitty Keyboard Protocol or the Windows // Console API. IsRepeat bool }
Key represents a Key press or release event. It contains information about the Key pressed, like the runes, the type of Key, and the modifiers pressed. There are a couple general patterns you could use to check for key presses or releases:
// Switch on the string representation of the key (shorter) switch msg := msg.(type) { case KeyPressMsg: switch msg.String() { case "enter": fmt.Println("you pressed enter!") case "a": fmt.Println("you pressed a!") } } // Switch on the key type (more foolproof) switch msg := msg.(type) { case KeyMsg: // catch both KeyPressMsg and KeyReleaseMsg switch key := msg.Key(); key.Code { case KeyEnter: fmt.Println("you pressed enter!") default: switch key.Text { case "a": fmt.Println("you pressed a!") } } }
Note that [Key.Text] will be empty for special keys like KeyEnter, KeyTab, and for keys that don't represent printable characters like key combos with modifier keys. In other words, [Key.Text] is populated only for keys that represent printable characters shifted or unshifted (like 'a', 'A', '1', '!', etc.).
func (Key) String ¶
String implements fmt.Stringer and is used to convert a key to a string. While less type safe than looking at the individual fields, it will usually be more convenient and readable to use this method when matching against keys.
Note that modifier keys are always printed in the following order:
- ctrl
- alt
- shift
- meta
- hyper
- super
For example, you'll always see "ctrl+shift+alt+a" and never "shift+ctrl+alt+a".
type KeyPressMsg ¶
type KeyPressMsg Key
KeyPressMsg represents a key press message.
func (KeyPressMsg) Key ¶
func (k KeyPressMsg) Key() Key
Key returns the underlying key event. This is a syntactic sugar for casting the key event to a Key.
func (KeyPressMsg) String ¶
func (k KeyPressMsg) String() string
String implements fmt.Stringer and is quite useful for matching key events. For details, on what this returns see Key.String.
type KeyReleaseMsg ¶
type KeyReleaseMsg Key
KeyReleaseMsg represents a key release message.
func (KeyReleaseMsg) Key ¶
func (k KeyReleaseMsg) Key() Key
Key returns the underlying key event. This is a convenience method and syntactic sugar to satisfy the KeyMsg interface, and cast the key event to Key.
func (KeyReleaseMsg) String ¶
func (k KeyReleaseMsg) String() string
String implements fmt.Stringer and is quite useful for matching key events. For details, on what this returns see Key.String.
type KeyboardEnhancementOption ¶
type KeyboardEnhancementOption func(k *KeyboardEnhancements)
KeyboardEnhancementOption is a type that represents a keyboard enhancement.
type KeyboardEnhancements ¶
type KeyboardEnhancements struct {
// contains filtered or unexported fields
}
KeyboardEnhancements is a type that represents a set of keyboard enhancements.
type KeyboardEnhancementsMsg ¶
type KeyboardEnhancementsMsg KeyboardEnhancements
KeyboardEnhancementsMsg is a message that gets sent when the terminal supports keyboard enhancements.
func (KeyboardEnhancementsMsg) SupportsKeyDisambiguation ¶
func (k KeyboardEnhancementsMsg) SupportsKeyDisambiguation() bool
SupportsKeyDisambiguation returns whether the terminal supports reporting disambiguous keys as escape codes.
func (KeyboardEnhancementsMsg) SupportsKeyReleases ¶
func (k KeyboardEnhancementsMsg) SupportsKeyReleases() bool
SupportsKeyReleases returns whether the terminal supports key release events.
func (KeyboardEnhancementsMsg) SupportsUniformKeyLayout ¶
func (k KeyboardEnhancementsMsg) SupportsUniformKeyLayout() bool
SupportsUniformKeyLayout returns whether the terminal supports reporting key events as though they were on a PC-101 layout.
type LogOptionsSetter ¶
LogOptionsSetter is an interface implemented by stdlib's log and charm's log libraries.
type Model ¶
type Model interface { // Init is the first function that will be called. It returns an optional // initial command. To not perform an initial command return nil. Init() Cmd // Update is called when a message is received. Use it to inspect messages // and, in response, update the model and/or send a command. Update(Msg) (Model, Cmd) }
Model contains the program's state as well as its core functions.
type Mouse ¶
type Mouse struct {
X, Y int
Button MouseButton
Mod KeyMod
}
Mouse represents a Mouse message. Use MouseMsg to represent all mouse messages.
The X and Y coordinates are zero-based, with (0,0) being the upper left corner of the terminal.
// Catch all mouse events switch msg := msg.(type) { case MouseMsg: m := msg.Mouse() fmt.Println("Mouse event:", m.X, m.Y, m) } // Only catch mouse click events switch msg := msg.(type) { case MouseClickMsg: fmt.Println("Mouse click event:", msg.X, msg.Y, msg) }
type MouseButton ¶
type MouseButton = input.MouseButton
MouseButton represents the button that was pressed during a mouse message.
type MouseClickMsg ¶
type MouseClickMsg Mouse
MouseClickMsg represents a mouse button click message.
func (MouseClickMsg) Mouse ¶
func (e MouseClickMsg) Mouse() Mouse
Mouse returns the underlying mouse event. This is a convenience method and syntactic sugar to satisfy the MouseMsg interface, and cast the mouse event to Mouse.
func (MouseClickMsg) String ¶
func (e MouseClickMsg) String() string
String returns a string representation of the mouse click message.
type MouseMotionMsg ¶
type MouseMotionMsg Mouse
MouseMotionMsg represents a mouse motion message.
func (MouseMotionMsg) Mouse ¶
func (e MouseMotionMsg) Mouse() Mouse
Mouse returns the underlying mouse event. This is a convenience method and syntactic sugar to satisfy the MouseMsg interface, and cast the mouse event to Mouse.
func (MouseMotionMsg) String ¶
func (e MouseMotionMsg) String() string
String returns a string representation of the mouse motion message.
type MouseMsg ¶
MouseMsg represents a mouse message. This is a generic mouse message that can represent any kind of mouse event.
type MouseReleaseMsg ¶
type MouseReleaseMsg Mouse
MouseReleaseMsg represents a mouse button release message.
func (MouseReleaseMsg) Mouse ¶
func (e MouseReleaseMsg) Mouse() Mouse
Mouse returns the underlying mouse event. This is a convenience method and syntactic sugar to satisfy the MouseMsg interface, and cast the mouse event to Mouse.
func (MouseReleaseMsg) String ¶
func (e MouseReleaseMsg) String() string
String returns a string representation of the mouse release message.
type MouseWheelMsg ¶
type MouseWheelMsg Mouse
MouseWheelMsg represents a mouse wheel message event.
func (MouseWheelMsg) Mouse ¶
func (e MouseWheelMsg) Mouse() Mouse
Mouse returns the underlying mouse event. This is a convenience method and syntactic sugar to satisfy the MouseMsg interface, and cast the mouse event to Mouse.
func (MouseWheelMsg) String ¶
func (e MouseWheelMsg) String() string
String returns a string representation of the mouse wheel message.
type Msg ¶
type Msg interface{}
Msg contain data from the result of a IO operation. Msgs trigger the update function and, henceforth, the UI.
func ClearScreen ¶
func ClearScreen() Msg
ClearScreen is a special command that tells the program to clear the screen before the next update. This can be used to move the cursor to the top left of the screen and clear visual clutter when the alt screen is not in use.
Note that it should never be necessary to call ClearScreen() for regular redraws.
func DisableBracketedPaste ¶
func DisableBracketedPaste() Msg
DisableBracketedPaste is a special command that tells the Bubble Tea program to accept bracketed paste input.
Note that bracketed paste will be automatically disabled when the program quits.
func DisableGraphemeClustering ¶
func DisableGraphemeClustering() Msg
DisableGraphemeClustering is a special command that tells the Bubble Tea program to disable grapheme clustering. This mode will be disabled automatically when the program quits.
func DisableKeyboardEnhancements ¶
func DisableKeyboardEnhancements() Msg
DisableKeyboardEnhancements is a command that disables keyboard enhancements in the terminal.
func DisableMouse ¶
func DisableMouse() Msg
DisableMouse is a special command that stops listening for mouse events.
func DisableReportFocus ¶
func DisableReportFocus() Msg
DisableReportFocus is a special command that tells the Bubble Tea program to disable focus reporting.
func EnableBracketedPaste ¶
func EnableBracketedPaste() Msg
EnableBracketedPaste is a special command that tells the Bubble Tea program to accept bracketed paste input.
Note that bracketed paste will be automatically disabled when the program quits.
func EnableGraphemeClustering ¶
func EnableGraphemeClustering() Msg
EnableGraphemeClustering is a special command that tells the Bubble Tea program to enable grapheme clustering. This is enabled by default.
func EnableMouseAllMotion ¶
func EnableMouseAllMotion() Msg
EnableMouseAllMotion is a special command that enables mouse click, release, wheel, and motion events, which are delivered regardless of whether a mouse button is pressed, effectively enabling support for hover interactions.
Many modern terminals support this, but not all. If in doubt, use EnableMouseCellMotion instead.
Because commands run asynchronously, this command should not be used in your model's Init function. Use the WithMouseAllMotion ProgramOption instead.
func EnableMouseCellMotion ¶
func EnableMouseCellMotion() Msg
EnableMouseCellMotion is a special command that enables mouse click, release, and wheel events. Mouse movement events are also captured if a mouse button is pressed (i.e., drag events).
Because commands run asynchronously, this command should not be used in your model's Init function. Use the WithMouseCellMotion ProgramOption instead.
func EnableReportFocus ¶
func EnableReportFocus() Msg
EnableReportFocus is a special command that tells the Bubble Tea program to enable focus reporting.
func EnterAltScreen ¶
func EnterAltScreen() Msg
EnterAltScreen is a special command that tells the Bubble Tea program to enter the alternate screen buffer.
Because commands run asynchronously, this command should not be used in your model's Init function. To initialize your program with the altscreen enabled use the WithAltScreen ProgramOption instead.
func ExitAltScreen ¶
func ExitAltScreen() Msg
ExitAltScreen is a special command that tells the Bubble Tea program to exit the alternate screen buffer. This command should be used to exit the alternate screen buffer while the program is running.
Note that the alternate screen buffer will be automatically exited when the program quits.
func HideCursor ¶
func HideCursor() Msg
HideCursor is a special command for manually instructing Bubble Tea to hide the cursor. In some rare cases, certain operations will cause the terminal to show the cursor, which is normally hidden for the duration of a Bubble Tea program's lifetime. You will most likely not need to use this command.
func Interrupt ¶
func Interrupt() Msg
Interrupt is a special command that tells the Bubble Tea program to interrupt.
func ReadClipboard ¶
func ReadClipboard() Msg
ReadClipboard produces a command that reads the system clipboard using OSC52. Note that OSC52 is not supported in all terminals.
func ReadPrimaryClipboard ¶
func ReadPrimaryClipboard() Msg
ReadPrimaryClipboard produces a command that reads the primary clipboard using OSC52. Primary clipboard selection is a feature present in X11 and Wayland only. Note that OSC52 is not supported in all terminals.
func RequestBackgroundColor ¶
func RequestBackgroundColor() Msg
RequestBackgroundColor is a command that requests the terminal background color.
func RequestCursorColor ¶
func RequestCursorColor() Msg
RequestCursorColor is a command that requests the terminal cursor color.
func RequestCursorPosition ¶
func RequestCursorPosition() Msg
RequestCursorPosition is a command that requests the cursor position. The cursor position will be sent as a CursorPositionMsg message.
func RequestForegroundColor ¶
func RequestForegroundColor() Msg
RequestForegroundColor is a command that requests the terminal foreground color.
func RequestWindowSize ¶
func RequestWindowSize() Msg
RequestWindowSize is a command that queries the terminal for its current size. It delivers the results to Update via a WindowSizeMsg. Keep in mind that WindowSizeMsgs will automatically be delivered to Update when the Program starts and when the window dimensions change so in many cases you will not need to explicitly invoke this command.
func ShowCursor ¶
func ShowCursor() Msg
ShowCursor is a special command for manually instructing Bubble Tea to show the cursor.
func Suspend ¶
func Suspend() Msg
Suspend is a special command that tells the Bubble Tea program to suspend.
func TerminalVersion ¶
func TerminalVersion() Msg
TerminalVersion is a command that queries the terminal for its version using XTVERSION. Note that some terminals may not support this command.
type PasteEndMsg ¶
type PasteEndMsg struct{}
PasteEndMsg is an message that is emitted when the terminal ends the bracketed-paste text.
type PasteMsg ¶
type PasteMsg string
PasteMsg is an message that is emitted when a terminal receives pasted text using bracketed-paste.
type PasteStartMsg ¶
type PasteStartMsg struct{}
PasteStartMsg is an message that is emitted when the terminal starts the bracketed-paste text.
type PrimaryClipboardMsg ¶
type PrimaryClipboardMsg string
PrimaryClipboardMsg is a primary clipboard read message event. This message is emitted when a terminal receives an OSC52 primary clipboard read message event. Primary clipboard selection is a feature present in X11 and Wayland only.
func (PrimaryClipboardMsg) String ¶
func (e PrimaryClipboardMsg) String() string
String returns the string representation of the primary clipboard message.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a terminal user interface.
func NewProgram ¶
func NewProgram(model Model, opts ...ProgramOption) *Program
NewProgram creates a new Program.
func (*Program) Kill ¶
func (p *Program) Kill()
Kill stops the program immediately and restores the former terminal state. The final render that you would normally see when quitting will be skipped. [program.Run] returns a ErrProgramKilled error.
func (*Program) Printf ¶
Printf prints above the Program. It takes a format template followed by values similar to fmt.Printf. This output is unmanaged by the program and will persist across renders by the Program.
Unlike fmt.Printf (but similar to log.Printf) the message will be print on its own line.
If the altscreen is active no output will be printed.
func (*Program) Println ¶
func (p *Program) Println(args ...interface{})
Println prints above the Program. This output is unmanaged by the program and will persist across renders by the Program.
If the altscreen is active no output will be printed.
func (*Program) Quit ¶
func (p *Program) Quit()
Quit is a convenience function for quitting Bubble Tea programs. Use it when you need to shut down a Bubble Tea program from the outside.
If you wish to quit from within a Bubble Tea program use the Quit command.
If the program is not running this will be a no-op, so it's safe to call if the program is unstarted or has already exited.
func (*Program) ReleaseTerminal ¶
ReleaseTerminal restores the original terminal state and cancels the input reader. You can return control to the Program with RestoreTerminal.
func (*Program) RestoreTerminal ¶
RestoreTerminal reinitializes the Program's input reader, restores the terminal to the former state when the program was running, and repaints. Use it to reinitialize a Program after running ReleaseTerminal.
func (*Program) Run ¶
Run initializes the program and runs its event loops, blocking until it gets terminated by either Program.Quit, Program.Kill, or its signal handler. Returns the final model.
func (*Program) Send ¶
Send sends a message to the main update function, effectively allowing messages to be injected from outside the program for interoperability purposes.
If the program hasn't started yet this will be a blocking operation. If the program has already been terminated this will be a no-op, so it's safe to send messages after the program has exited.
type ProgramOption ¶
type ProgramOption func(*Program)
ProgramOption is used to set options when initializing a Program. Program can accept a variable number of options.
Example usage:
p := NewProgram(model, WithInput(someInput), WithOutput(someOutput))
func WithAltScreen ¶
func WithAltScreen() ProgramOption
WithAltScreen starts the program with the alternate screen buffer enabled (i.e. the program starts in full window mode). Note that the altscreen will be automatically exited when the program quits.
Example:
p := tea.NewProgram(Model{}, tea.WithAltScreen()) if _, err := p.Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1) }
To enter the altscreen once the program has already started running use the EnterAltScreen command.
func WithColorProfile ¶
func WithColorProfile(profile colorprofile.Profile) ProgramOption
WithColorProfile sets the color profile that the program will use. This is useful when you want to force a specific color profile. By default, Bubble Tea will try to detect the terminal's color profile from environment variables and terminfo capabilities. Use tea.WithEnvironment to set custom environment variables.
func WithContext ¶
func WithContext(ctx context.Context) ProgramOption
WithContext lets you specify a context in which to run the Program. This is useful if you want to cancel the execution from outside. When a Program gets cancelled it will exit with an error ErrProgramKilled.
func WithEnvironment ¶
func WithEnvironment(env []string) ProgramOption
WithEnvironment sets the environment variables that the program will use. This useful when the program is running in a remote session (e.g. SSH) and you want to pass the environment variables from the remote session to the program.
Example:
var sess ssh.Session // ssh.Session is a type from the github.com/charmbracelet/ssh package pty, _, _ := sess.Pty() environ := append(sess.Environ(), "TERM="+pty.Term) p := tea.NewProgram(model, tea.WithEnvironment(environ)
func WithFPS ¶
func WithFPS(fps int) ProgramOption
WithFPS sets a custom maximum FPS at which the renderer should run. If less than 1, the default value of 60 will be used. If over 120, the FPS will be capped at 120.
func WithFilter ¶
func WithFilter(filter func(Model, Msg) Msg) ProgramOption
WithFilter supplies an event filter that will be invoked before Bubble Tea processes a tea.Msg. The event filter can return any tea.Msg which will then get handled by Bubble Tea instead of the original event. If the event filter returns nil, the event will be ignored and Bubble Tea will not process it.
As an example, this could be used to prevent a program from shutting down if there are unsaved changes.
Example:
func filter(m tea.Model, msg tea.Msg) tea.Msg { if _, ok := msg.(tea.QuitMsg); !ok { return msg } model := m.(myModel) if model.hasChanges { return nil } return msg } p := tea.NewProgram(Model{}, tea.WithFilter(filter)); if _,err := p.Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1) }
func WithGraphemeClustering ¶
func WithGraphemeClustering() ProgramOption
WithGraphemeClustering disables grapheme clustering. This is useful if you want to disable grapheme clustering for your program.
Grapheme clustering is a character width calculation method that accurately calculates the width of wide characters in a terminal. This is useful for properly rendering double width characters such as emojis and CJK characters.
See https://mitchellh.com/writing/grapheme-clusters-in-terminals
func WithInput ¶
func WithInput(input io.Reader) ProgramOption
WithInput sets the input which, by default, is stdin. In most cases you won't need to use this. To disable input entirely pass nil.
p := NewProgram(model, WithInput(nil))
func WithInputTTY ¶
func WithInputTTY() ProgramOption
WithInputTTY opens a new TTY for input (or console input device on Windows).
func WithKeyboardEnhancements ¶
func WithKeyboardEnhancements(enhancements ...KeyboardEnhancementOption) ProgramOption
WithKeyboardEnhancements enables support for enhanced keyboard features. You can enable different keyboard features by passing one or more KeyboardEnhancement functions.
This is not supported on all terminals. On Windows, these features are enabled by default.
func WithMouseAllMotion ¶
func WithMouseAllMotion() ProgramOption
WithMouseAllMotion starts the program with the mouse enabled in "all motion" mode.
EnableMouseAllMotion is a special command that enables mouse click, release, wheel, and motion events, which are delivered regardless of whether a mouse button is pressed, effectively enabling support for hover interactions.
This will try to enable the mouse in extended mode (SGR), if that is not supported by the terminal it will fall back to normal mode (X10).
Many modern terminals support this, but not all. If in doubt, use EnableMouseCellMotion instead.
To enable the mouse once the program has already started running use the EnableMouseAllMotion command. To disable the mouse when the program is running use the DisableMouse command.
The mouse will be automatically disabled when the program exits.
func WithMouseCellMotion ¶
func WithMouseCellMotion() ProgramOption
WithMouseCellMotion starts the program with the mouse enabled in "cell motion" mode.
Cell motion mode enables mouse click, release, and wheel events. Mouse movement events are also captured if a mouse button is pressed (i.e., drag events). Cell motion mode is better supported than all motion mode.
This will try to enable the mouse in extended mode (SGR), if that is not supported by the terminal it will fall back to normal mode (X10).
To enable mouse cell motion once the program has already started running use the EnableMouseCellMotion command. To disable the mouse when the program is running use the DisableMouse command.
The mouse will be automatically disabled when the program exits.
func WithOutput ¶
func WithOutput(output io.Writer) ProgramOption
WithOutput sets the output which, by default, is stdout. In most cases you won't need to use this.
func WithReportFocus ¶
func WithReportFocus() ProgramOption
WithReportFocus enables reporting when the terminal gains and loses focus. When this is enabled FocusMsg and BlurMsg messages will be sent to your Update method.
Note that while most terminals and multiplexers support focus reporting, some do not. Also note that tmux needs to be configured to report focus events.
func WithWindowSize ¶
func WithWindowSize(width, height int) ProgramOption
WithWindowSize sets the initial size of the terminal window. This is useful when you need to set the initial size of the terminal window, for example during testing or when you want to run your program in a non-interactive environment.
func WithoutBracketedPaste ¶
func WithoutBracketedPaste() ProgramOption
WithoutBracketedPaste starts the program with bracketed paste disabled.
func WithoutCatchPanics ¶
func WithoutCatchPanics() ProgramOption
WithoutCatchPanics disables the panic catching that Bubble Tea does by default. If panic catching is disabled the terminal will be in a fairly unusable state after a panic because Bubble Tea will not perform its usual cleanup on exit.
func WithoutSignalHandler ¶
func WithoutSignalHandler() ProgramOption
WithoutSignalHandler disables the signal handler that Bubble Tea sets up for Programs. This is useful if you want to handle signals yourself.
func WithoutSignals ¶
func WithoutSignals() ProgramOption
WithoutSignals will ignore OS signals. This is mainly useful for testing.
type QuitMsg ¶
type QuitMsg struct{}
QuitMsg signals that the program should quit. You can send a QuitMsg with Quit.
type RawMsg ¶
type RawMsg struct {
Msg any
}
RawMsg is a message that contains a string to be printed to the terminal without any intermediate processing.
type ResumeMsg ¶
type ResumeMsg struct{}
ResumeMsg can be listen to to do something once a program is resumed back from a suspend state.
type SuspendMsg ¶
type SuspendMsg struct{}
SuspendMsg signals the program should suspend. This usually happens when ctrl+z is pressed on common programs, but since bubbletea puts the terminal in raw mode, we need to handle it in a per-program basis.
You can send this message with [Suspend()].
type TerminalVersionMsg ¶
type TerminalVersionMsg string
TerminalVersionMsg is a message that represents the terminal version.
type ViewModel ¶
type ViewModel interface { // View renders the program's UI, which is just a string. The view is // rendered after every Update. View() string }
ViewModel is an optional interface that can be implemented by the main model to provide a view. If the main model does not implement a view interface, the program won't render anything.
type WindowSizeMsg ¶
WindowSizeMsg is used to report the terminal size. It's sent to Update once initially and then on every terminal resize. Note that Windows does not have support for reporting when resizes occur as it does not support the SIGWINCH signal.
Source Files
¶
- clipboard.go
- color.go
- commands.go
- cursed_renderer.go
- cursor.go
- environ.go
- exec.go
- focus.go
- input.go
- key.go
- keyboard.go
- logging.go
- mod.go
- mode.go
- mouse.go
- nil_renderer.go
- options.go
- paste.go
- profile.go
- raw.go
- renderer.go
- screen.go
- signals_unix.go
- standard_renderer.go
- sync.go
- tea.go
- termcap.go
- termios_unix.go
- tty.go
- tty_unix.go
- xterm.go