feat: add RawMsg and Raw command to print raw strings to the terminal (#1288)

This adds a new message type, `RawMsg`, and a new command, `Raw`, that
allows printing raw strings to the terminal without any intermediate
processing.
This commit is contained in:
Ayman Bagabas 2025-01-16 08:43:34 -05:00 committed by GitHub
parent 5fa2d548be
commit 52bd762edb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View file

@ -61,5 +61,5 @@ func (p *Program) translateInputEvent(e input.Event) Msg {
kittyFlags: p.activeEnhancements.kittyFlags,
}
}
return nil
return e
}

15
raw.go Normal file
View file

@ -0,0 +1,15 @@
package tea
// RawMsg is a message that contains a string to be printed to the terminal
// without any intermediate processing.
type RawMsg struct {
Msg any
}
// Raw is a command that prints the given string to the terminal without any
// formatting.
func Raw(r any) Cmd {
return func() Msg {
return RawMsg{r}
}
}

3
tea.go
View file

@ -671,6 +671,9 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
case requestCursorPosMsg:
p.execute(ansi.RequestCursorPosition)
case RawMsg:
p.execute(fmt.Sprint(msg.Msg))
case setCursorPosMsg:
p.renderer.moveTo(msg.X, msg.Y)