Skip to content

Commit

Permalink
feat: add RawMsg and Raw command to print raw strings to the terminal
Browse files Browse the repository at this point in the history
This adds a new message type, `RawMsg`, and a new command, `Raw`, that
allows printing raw strings to the terminal without any intermediate
processing.
  • Loading branch information
aymanbagabas committed Jan 15, 2025
1 parent 43a5b4d commit 381649e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ func translateInputEvent(e input.Event) Msg {
case input.TerminalVersionEvent:
return TerminalVersionMsg(e)
}
return nil
return e
}
15 changes: 15 additions & 0 deletions raw.go
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,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)

Expand Down

0 comments on commit 381649e

Please sign in to comment.