term

package
v0.0.0-...-15f74bb Latest Latest
Warning

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

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

Documentation

Overview

Package term provides line editing, history, and tab completion for the interactive shell.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal reports whether w is a real terminal (as opposed to a pipe or file). This is a convenience wrapper for callers that need to decide whether to run an interactive loop.

Types

type Terminal

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

Terminal wraps liner.State to provide line editing, history, and completion.

func New

func New(historyFile string) (*Terminal, error)

New returns a Terminal.

If historyFile is non-empty the history is loaded from it at construction and saved back on Close. A missing history file is silently ignored.

func (*Terminal) Close

func (t *Terminal) Close() error

Close saves history and releases terminal resources.

func (*Terminal) ReadLine

func (t *Terminal) ReadLine(prompt string) (string, error)

ReadLine prints prompt and reads one line of input.

Returns ("", io.EOF) at end of input. Ctrl-C (ErrPromptAborted) returns ("", nil) so the caller can show a new prompt rather than exit.

func (*Terminal) SetCompleter

func (t *Terminal) SetCompleter(fn func(line string) []string)

SetCompleter installs a tab-completion function.

fn receives the full current line prefix and returns a slice of completion candidates (also full lines, not just the suffix).

Jump to

Keyboard shortcuts

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