tview

package
v0.0.0-...-ccefcf7 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Require

func Require(baseCtx context.Context, manager *Manager) func(runtime *goja.Runtime, module *goja.Object)

Require returns a CommonJS native module under "osm:tview". It exposes tview functionality for creating rich terminal UIs.

The key design principle is that TUI components are: - Explicitly invoked by JavaScript code - Accept simple, trivially-wirable data structures - Implemented in Go for performance and testability - Extensible through configuration objects

API (JS):

const tview = require('osm:tview');

// Interactive table - blocks until user exits (Escape/q) or selects (Enter)
tview.interactiveTable({
    title: "Context Items",
    headers: ["ID", "Type", "Label", "Status"],
    rows: [
        ["1", "file", "main.go", "ok"],
        ["2", "note", "Important note", "ok"],
    ],
    footer: "Press Escape or 'q' to close | Enter to edit | Arrow keys to navigate",
    onSelect: function(rowIndex) {
        // Called when user presses Enter on a row
        // rowIndex is 0-based (excluding header)
        output.print("Selected row: " + rowIndex);
    }
});

Types

type Manager

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

Manager holds the tview application and related state per engine instance.

func NewManager

func NewManager(
	ctx context.Context,
	screen tcell.Screen,
	terminal TerminalOps,
	signalNotify func(c chan<- os.Signal, sig ...os.Signal),
	signalStop func(c chan<- os.Signal),
) *Manager

NewManager creates a new tview manager for an engine instance. The provided screen is optional and mainly for testing purposes. Similarly, custom signal handling functions can be provided for testing. The terminal parameter is optional - if provided and screen is nil, it will be used to create a screen via TcellAdapter.

func NewManagerWithTerminal

func NewManagerWithTerminal(
	ctx context.Context,
	screen tcell.Screen,
	terminal TerminalOps,
	signalNotify func(c chan<- os.Signal, sig ...os.Signal),
	signalStop func(c chan<- os.Signal),
) *Manager

NewManagerWithTerminal creates a new tview manager with terminal ops support. If screen is nil and terminal is provided, a screen will be created using the TcellAdapter when needed.

func (*Manager) ShowInteractiveTable

func (m *Manager) ShowInteractiveTable(config TableConfig) error

ShowInteractiveTable displays an interactive table in the terminal.

type TableConfig

type TableConfig struct {
	Title    string
	Headers  []string
	Rows     []TableRow
	Footer   string
	OnSelect func(rowIndex int) // Optional callback when a row is selected with Enter
}

TableConfig holds configuration for an interactive table.

type TableRow

type TableRow struct {
	Cells []string
}

TableRow represents a row of data for the interactive table.

type TcellAdapter

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

TcellAdapter implements tcell.Tty by wrapping a TerminalOps. This allows tcell/tview to use the shared terminal I/O from the engine.

func NewTcellAdapter

func NewTcellAdapter(terminal TerminalOps) *TcellAdapter

NewTcellAdapter creates a new tcell.Tty adapter wrapping the given terminal.

func (*TcellAdapter) Close

func (a *TcellAdapter) Close() error

Close implements io.Closer.

func (*TcellAdapter) Drain

func (a *TcellAdapter) Drain() error

Drain satisfies the tcell.Tty interface. We implement it as a no-op because the adapter bypass mechanism handles state transitions, and attempting to drain via FCNTL/IOCTL manually here is dangerous and platform-dependent.

func (*TcellAdapter) NotifyResize

func (a *TcellAdapter) NotifyResize(cb func())

NotifyResize registers a callback for terminal resize events.

func (*TcellAdapter) Read

func (a *TcellAdapter) Read(p []byte) (n int, err error)

Read implements io.Reader.

func (*TcellAdapter) Start

func (a *TcellAdapter) Start() error

Start puts the terminal into raw mode.

func (*TcellAdapter) Stop

func (a *TcellAdapter) Stop() error

Stop restores the terminal to its previous state.

func (*TcellAdapter) WindowSize

func (a *TcellAdapter) WindowSize() (tcell.WindowSize, error)

WindowSize returns the current terminal size.

func (*TcellAdapter) Write

func (a *TcellAdapter) Write(p []byte) (n int, err error)

Write implements io.Writer.

type TerminalOps

type TerminalOps interface {
	io.Reader
	io.Writer
	io.Closer

	// Fd returns the file descriptor of the underlying terminal.
	Fd() uintptr

	// MakeRaw puts the terminal into raw mode and returns the previous state.
	MakeRaw() (*term.State, error)

	// Restore restores the terminal to a previous state.
	Restore(state *term.State) error

	// GetSize returns the current terminal size (width, height).
	GetSize() (width, height int, err error)

	// IsTerminal returns true if the underlying resource is a terminal.
	IsTerminal() bool
}

TerminalOps defines the interface for terminal operations. This matches the interface in internal/scripting/tui_io.go.

Jump to

Keyboard shortcuts

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