termview

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Termview - TUI terminal component for Go

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.

License

1. Functional demo

This demo represents routing PTY I/O into x/vt emulators, rendering with bubbletea library.

Two-pane terminal multiplexer demo with focus switching and horizontal/vertical layout toggle

2. Installation and usage

go get github.com/grafviktor/termview@v0.4.0
import "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.

3. Scrolling

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.

4. Clipboard

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{} }),
    )

5. License

MIT - see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClosedMsg

type ClosedMsg struct {
	ID              int
	ProcessExitCode int
	ProcessError    error
}

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model embeds a shell in Bubble Tea using x/vt for emulation and xpty for the pseudo-terminal.

func New

func New(opts ...Option) (Model, error)

func (Model) Args added in v0.2.0

func (m Model) Args() []string

func (Model) Blur

func (m Model) Blur() Model

func (*Model) Close

func (m *Model) Close()

func (Model) Closed

func (m Model) Closed() bool

func (Model) Command added in v0.2.0

func (m Model) Command() string

func (Model) Cursor

func (m Model) Cursor() *tea.Cursor

func (Model) Focus

func (m Model) Focus() Model

func (Model) Focused

func (m Model) Focused() bool

func (Model) Height

func (m Model) Height() int

func (Model) ID

func (m Model) ID() int

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) PID added in v0.2.0

func (m Model) PID() int

func (*Model) SetHeight

func (m *Model) SetHeight(height int)

func (*Model) SetWidth

func (m *Model) SetWidth(width int)

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

func (Model) View

func (m Model) View() string

func (Model) Width

func (m Model) Width() int

type Option

type Option func(*Model)

func WithCommand

func WithCommand(cmd string, args ...string) Option

func WithInitialHeight

func WithInitialHeight(height int) Option

func WithInitialWidth

func WithInitialWidth(width int) Option

func WithScrollbackSize added in v0.4.0

func WithScrollbackSize(lines int) Option

func WithStdErr added in v0.2.0

func WithStdErr(stdErr io.Writer) Option

type OutputMsg

type OutputMsg struct{ ID int }

type TextSelectedMsg added in v0.4.0

type TextSelectedMsg struct {
	ID   int
	Text string
}

Only used when mouse motion mode is enabled. See tea.MouseMode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址