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:
parent
5fa2d548be
commit
52bd762edb
3 changed files with 19 additions and 1 deletions
2
input.go
2
input.go
|
|
@ -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
15
raw.go
Normal 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
3
tea.go
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue