Termview is a terminal component which is designed to work with Bubble Tea v2. It embeds a real shell session in your app using the same model/update/view pattern as other Charm Bracelet components.
This demo represents routing PTY I/O into x/vt emulators, rendering with bubbletea library.
go get github.com/grafviktor/termview@v0.4.0import "github.com/grafviktor/termview"
...
term, err := termview.New(
termview.WithCommand("/bin/bash"),
termview.WithInitialWidth(80),
termview.WithInitialHeight(24),
termview.WithScrollbackSize(10000),
)Also see terminal-simple and terminal-multiplexer for the examples.
Lines that leave the top of the screen are kept in a scrollback buffer, 10000 lines by default. Use termview.WithScrollbackSize to change the limit. You can use mouse for scrolling or shift+pgup, shift+pgdown, shift+up, shift+down buttons.
TermView emits when user selects a text and then releases the mouse. You can handle it in your app with such code:
case termview.TextSelectedMsg:
if msg.ID != a.term.ID() {
return a, nil
}
a.status = "Copied to clipboard"
return a, tea.Batch(
tea.SetClipboard(msg.Text),
tea.Tick(2*time.Second, func(time.Time) tea.Msg { return clearStatusMsg{} }),
)MIT - see LICENSE.
