Documentation ¶
Index ¶
- Variables
- func GetSize(text string) geom.Vec2
- func KeysToBytes(keys ...KeyMsg) (data []byte, err error)
- func Sequence(cmds ...tea.Cmd) tea.Cmd
- func Test(m Model) func(msgs ...interface{})
- func TranslateMouseEvents(data []byte, dx, dy int)
- type Cmd
- type Key
- type KeyMsg
- type KeyType
- type Model
- type MouseButton
- type MouseEvent
- type MouseEventType
- type MouseMsg
- type Msg
- type Program
- type PublishMsg
- type Renderer
- type ScreenUpdate
- type ScreenWatcher
Constants ¶
This section is empty.
Variables ¶
var ErrProgramKilled = errors.New("program was killed")
ErrProgramKilled is returned by Program.Run when the program got killed.
Functions ¶
func KeysToBytes ¶ added in v0.1.5
func Sequence ¶
Sequence runs the given commands one at a time, in order. Contrast this with Batch, which runs commands concurrently.
func Test ¶ added in v0.1.13
func Test(m Model) func(msgs ...interface{})
Test returns a function that passes the given messages to the taro Model `m` one at a time. All `Cmd`s that would normally be executed in separate goroutines are instead executed in the calling goroutine. This is useful exclusively in testing.
func TranslateMouseEvents ¶
TranslateMouseEvents translates all mouse events in-place by [dx, dy].
Types ¶
type KeyMsg ¶
type KeyMsg Key
KeyMsg contains information about a keypress. KeyMsgs are always sent to the program's update function. There are a couple general patterns you could use to check for keypresses:
// Switch on the string representation of the key (shorter) switch msg := msg.(type) { case KeyMsg: 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: switch msg.Type { case KeyEnter: fmt.Println("you pressed enter!") case KeyRunes: switch string(msg.Runes) { case "a": fmt.Println("you pressed a!") } } }
Note that Key.Runes will always contain at least one character, so you can always safely call Key.Runes[0]. In most cases Key.Runes will only contain one character, though certain input method editors (most notably Chinese IMEs) can input multiple runes at once.
func KeysToMsg ¶ added in v0.1.5
KeysToMsg translates human-readable key specifiers (such as "ctrl+a", "up", etc) into KeyMsg events. Unrecognized strings are represented as KeyRunes.
type KeyType ¶
type KeyType int
KeyType indicates the key pressed, such as KeyEnter or KeyBreak or KeyCtrlC. All other keys will be type KeyRunes. To get the rune value, check the Rune method on a Key struct, or use the Key.String() method:
k := Key{Type: KeyRunes, Runes: []rune{'a'}, Alt: true} if k.Type == KeyRunes { fmt.Println(k.Runes) // Output: a fmt.Println(k.String()) // Output: alt+a }
const ( KeyNull KeyType = keyNUL KeyBreak KeyType = keyETX KeyEnter KeyType = keyCR KeyBackspace KeyType = keyDEL KeyTab KeyType = keyHT KeyEsc KeyType = keyESC KeyEscape KeyType = keyESC KeyCtrlAt KeyType = keyNUL // ctrl+@ KeyCtrlA KeyType = keySOH KeyCtrlB KeyType = keySTX KeyCtrlC KeyType = keyETX KeyCtrlD KeyType = keyEOT KeyCtrlE KeyType = keyENQ KeyCtrlF KeyType = keyACK KeyCtrlG KeyType = keyBEL KeyCtrlH KeyType = keyBS KeyCtrlI KeyType = keyHT KeyCtrlJ KeyType = keyLF KeyCtrlK KeyType = keyVT KeyCtrlL KeyType = keyFF KeyCtrlM KeyType = keyCR KeyCtrlN KeyType = keySO KeyCtrlO KeyType = keySI KeyCtrlP KeyType = keyDLE KeyCtrlQ KeyType = keyDC1 KeyCtrlR KeyType = keyDC2 KeyCtrlS KeyType = keyDC3 KeyCtrlT KeyType = keyDC4 KeyCtrlU KeyType = keyNAK KeyCtrlV KeyType = keySYN KeyCtrlW KeyType = keyETB KeyCtrlX KeyType = keyCAN KeyCtrlY KeyType = keyEM KeyCtrlZ KeyType = keySUB KeyCtrlOpenBracket KeyType = keyESC // ctrl+[ KeyCtrlBackslash KeyType = keyFS // ctrl+\ KeyCtrlCloseBracket KeyType = keyGS // ctrl+] KeyCtrlCaret KeyType = keyRS // ctrl+^ KeyCtrlUnderscore KeyType = keyUS // ctrl+_ KeyCtrlQuestionMark KeyType = keyDEL // ctrl+? )
Control key aliases.
const ( KeyRunes KeyType = -(iota + 1) KeyUp KeyDown KeyRight KeyLeft KeyShiftTab KeyHome KeyEnd KeyPgUp KeyPgDown KeyCtrlPgUp KeyCtrlPgDown KeyDelete KeyInsert KeySpace KeyCtrlUp KeyCtrlDown KeyCtrlRight KeyCtrlLeft KeyCtrlHome KeyCtrlEnd KeyShiftUp KeyShiftDown KeyShiftRight KeyShiftLeft KeyShiftHome KeyShiftEnd KeyCtrlShiftUp KeyCtrlShiftDown KeyCtrlShiftLeft KeyCtrlShiftRight KeyCtrlShiftHome KeyCtrlShiftEnd KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyF13 KeyF14 KeyF15 KeyF16 KeyF17 KeyF18 KeyF19 KeyF20 )
Other keys.
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) // View renders the program's UI, which consists of a full *tty.State. The // view is rendered after every Update. View(*tty.State) }
Model contains the program's state as well as its core functions.
type MouseButton ¶ added in v0.1.6
type MouseButton int
const ( MouseLeft MouseButton = iota MouseRight MouseMiddle MouseWheelUp MouseWheelDown MouseWheelRight MouseWheelLeft )
type MouseEvent ¶
type MouseEvent struct { geom.Vec2 Type MouseEventType Button MouseButton Down bool Alt bool Ctrl bool }
MouseEvent represents a mouse event, which could be a click, a scroll wheel movement, a cursor movement, or a combination.
func (MouseEvent) Bytes ¶
func (m MouseEvent) Bytes() []byte
func (MouseEvent) String ¶
func (m MouseEvent) String() (s string)
String returns a string representation of a mouse event.
func (MouseEvent) X10Bytes ¶
func (m MouseEvent) X10Bytes() []byte
type MouseEventType ¶
type MouseEventType int
MouseEventType indicates the type of mouse event occurring.
const ( MouseUnknown MouseEventType = iota MousePress MouseMotion )
Mouse event types.
type MouseMsg ¶
type MouseMsg MouseEvent
MouseMsg contains information about a mouse event and are sent to a programs update function when mouse activity occurs. Note that the mouse must first be enabled in order for the mouse events to be received.
type Program ¶
Program is a terminal user interface.
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) 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) 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 PublishMsg ¶ added in v0.1.6
type PublishMsg struct {
Msg Msg
}
Indicates that this message should be emitted upwards.
type Renderer ¶
Renderer makes it easy to render lipgloss strings.
func NewRenderer ¶
func NewRenderer() *Renderer
func (*Renderer) ConvertLipgloss ¶ added in v0.1.5
type ScreenUpdate ¶ added in v0.1.5
func (ScreenUpdate) Wait ¶ added in v0.1.16
func (s ScreenUpdate) Wait() Cmd
type ScreenWatcher ¶ added in v0.1.6
func NewWatcher ¶ added in v0.1.6
func NewWatcher(ctx context.Context, screen mux.Screen) *ScreenWatcher
func (*ScreenWatcher) Wait ¶ added in v0.1.6
func (s *ScreenWatcher) Wait() Cmd