terminal

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package terminal provides a pipe-based terminal backend for grut. It starts a shell process with piped stdin/stdout/stderr and captures output into a scrollback buffer. This is a v1 implementation using plain pipes; full PTY emulation can be added later.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultShell

func DefaultShell() string

DefaultShell returns the platform-appropriate default shell. On Windows it returns "cmd.exe"; on Unix it checks $SHELL and falls back to "/bin/sh".

Types

type Runner

type Runner interface {
	// Write sends data to the shell's stdin.
	Write(data []byte) error
	// Lines returns a snapshot of the current output lines (thread-safe).
	Lines() []string
	// Close kills the shell process and waits for it to exit.
	Close() error
	// Done returns a channel that is closed when the shell process exits.
	Done() <-chan struct{}
	// ExitCode returns the process exit code, or -1 if still running.
	ExitCode() int
}

Runner abstracts the terminal backend so that panels can use a mock implementation in tests.

type Terminal

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

Terminal manages a shell process with piped stdin/stdout/stderr. It reads output in background goroutines and stores lines in a thread-safe scrollback buffer with a configurable maximum.

func New

func New(shell string, maxLines int) (*Terminal, error)

New starts a shell process and begins reading its output. If shell is empty, DefaultShell() is used. If maxLines is <= 0, it defaults to 10000.

func (*Terminal) Close

func (t *Terminal) Close() error

Close closes stdin, kills the process if still running, and waits for the done channel to be closed.

func (*Terminal) Done

func (t *Terminal) Done() <-chan struct{}

Done returns a channel that is closed when the shell process exits.

func (*Terminal) ExitCode

func (t *Terminal) ExitCode() int

ExitCode returns the process exit code. Returns -1 if the process is still running or was killed.

func (*Terminal) Lines

func (t *Terminal) Lines() []string

Lines returns a copy of the current output lines. Safe for concurrent use.

func (*Terminal) Write

func (t *Terminal) Write(data []byte) error

Write sends data to the shell's stdin. Returns an error if the write fails (e.g. process has exited and pipe is closed).

Jump to

Keyboard shortcuts

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