textcmd

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 6 Imported by: 1

README

Push

TextCmd

Go package implementing a simple text command shell and executor.

Usage

See USAGE.

License

Copyright (c) 2020 Eric Barkie. All rights reserved.
Use of this source code is governed by the MIT license that can be found in the LICENSE file.

Documentation

Overview

Package textcmd implements a simple text command shell and executor.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCmdNotFound = errors.New("command not found")
	ErrCmdQuit     = errors.New("quit command")
)

Errors.

Functions

This section is empty.

Types

type CmdFunc added in v1.1.2

type CmdFunc func(context.Context, io.ReadWriter, ...string) error

CmdFunc is the function signature for command handlers.

type History added in v1.1.0

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

History tracks command history with readline-style cursor navigation. It is per-session state and is not tied to a Shell.

func NewHistory added in v1.1.0

func NewHistory(max int) *History

NewHistory creates a new History. max limits the number of entries kept; max <= 0 means unbounded.

func (*History) Add added in v1.1.0

func (h *History) Add(s string)

Add appends a command to the history and resets the cursor to the end. Empty/whitespace-only strings and consecutive duplicates are skipped.

func (*History) Next added in v1.1.0

func (h *History) Next() string

Next moves the cursor forward and returns the entry. Returns "" when moving past the last entry.

func (*History) Prev added in v1.1.0

func (h *History) Prev() string

Prev moves the cursor back and returns the entry. Returns "" if history is empty. Stays at the first entry if already at the beginning.

func (*History) Reset added in v1.1.0

func (h *History) Reset()

Reset moves the cursor to the end (past the last entry).

type Shell

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

Shell is a text command shell for which commands can be registered and executed.

func (Shell) Complete added in v1.1.0

func (sh Shell) Complete(s string) (completion string, matches iter.Seq[string])

Complete returns the input expanded as far as possible and all possible full command strings.

func (Shell) Exec

func (sh Shell) Exec(ctx context.Context, rw io.ReadWriter, s string) error

Exec attempts to execute the passed string as a command.

func (*Shell) Register

func (sh *Shell) Register(f CmdFunc, cmd ...string)

Register adds a command to the text command shell. It takes a command function and command execution strings.

Directories

Path Synopsis
internal
trie
Package trie implements a simple prefix tree.
Package trie implements a simple prefix tree.

Jump to

Keyboard shortcuts

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