shell

package
v0.0.0-...-f9f3222 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package shell implements a terminal console handler for user defined commands.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPrompt = "> "

DefaultPrompt represents the command prompt when none is set for the Interface instance.

Functions

func Add

func Add(cmd Cmd)

Add registers a terminal interface command.

Types

type Cmd

type Cmd struct {
	// Name is the command name.
	Name string

	// Args defines the number of command arguments, meant to be in the
	// Pattern capturing brackets.
	Args int

	// Pattern defines the command syntax and arguments.
	Pattern *regexp.Regexp

	// Syntax defines the Help() command syntax field.
	Syntax string

	// Help defines the Help() command description field.
	Help string

	// Fn defines the command handler.
	Fn CmdFn
}

Cmd represents a shell command.

type CmdFn

type CmdFn func(c *Interface, arg []string) (res string, err error)

CmdFn represents a command handler.

type Interface

type Interface struct {
	// Prompt represents the command prompt
	Prompt string
	// Banner represents the welcome message
	Banner string

	// Log represents the interface log file
	Log *os.File

	// ReadWriter represents the terminal connection
	ReadWriter io.ReadWriter

	// Output represents the interface output
	Output io.Writer
	// Terminal represents the VT100 terminal output
	Terminal *term.Terminal
	// contains filtered or unexported fields
}

Interface represents a terminal interface.

func (*Interface) Exec

func (c *Interface) Exec(cmd []byte)

Exec executes an individual command.

func (*Interface) Help

func (c *Interface) Help(_ *Interface, _ []string) (res string, _ error)

Help returns a formatted string with instructions for all registered commands.

func (*Interface) Start

func (c *Interface) Start(vt100 bool)

Start handles registered commands over the interface Terminal or ReadWriter, the argument specifies whether ReadWriter is VT100 compatible.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳