terminal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package terminal provides a terminal with support for the generation of GUIs and interactive CLIs for any existing command line tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StructForFlags

func StructForFlags(flags []*Flag) any

StructForFlags returns a new struct object for the given flags.

Types

type App

type App struct {
	core.Frame

	// Cmd is the root command associated with this app.
	Cmd *Cmd

	// CurCmd is the current root command being typed in.
	CurCmd string

	// Dir is the current directory of the app.
	Dir string
}

App is a GUI view of a terminal command.

func NewApp

func NewApp(parent ...tree.Node) *App

NewApp returns a new App with the given optional parent: App is a GUI view of a terminal command.

func (*App) Init added in v0.0.3

func (a *App) Init()

func (*App) MakeToolbar added in v0.0.3

func (a *App) MakeToolbar(p *tree.Plan)

func (*App) RunCmd

func (a *App) RunCmd(cmd string, cmds *core.Frame, dir *core.Text) error

RunCmd runs the given command in the context of the given commands frame and current directory text.

func (*App) SetCmd

func (t *App) SetCmd(v *Cmd) *App

SetCmd sets the [App.Cmd]: Cmd is the root command associated with this app.

func (*App) SetCurCmd

func (t *App) SetCurCmd(v string) *App

SetCurCmd sets the [App.CurCmd]: CurCmd is the current root command being typed in.

func (*App) SetDir

func (t *App) SetDir(v string) *App

SetDir sets the [App.Dir]: Dir is the current directory of the app.

type Cmd

type Cmd struct {
	// Cmd is the actual name of the command (eg: "git", "go build")
	Cmd string
	// Name is the formatted name of the command (eg: "Git", "Go build")
	Name string
	// Doc is the documentation for the command (eg: "compile packages and dependencies")
	Doc string
	// Flags contains the flags for the command
	Flags []*Flag
	// Cmds contains the subcommands of the command
	Cmds []*Cmd
}

Cmd contains all of the data for a parsed command line command.

func NewCmd

func NewCmd(cmd string) *Cmd

NewCmd makes a new App object from the given command name. It does not parse it; see [App.Parse].

func (*Cmd) GetBlocks

func (cm *Cmd) GetBlocks() ([]ParseBlock, error)

GetBlocks gets the ParseBlock objects for this command.

func (*Cmd) GetHelp

func (cm *Cmd) GetHelp() (string, error)

GetHelp gets the help information for the command. It tries various different commands and flags to get the help information and only returns an error if all of them fail.

func (*Cmd) Parse

func (cm *Cmd) Parse() error

Parse uses the help messages of the app to fill in its data fields.

func (*Cmd) SetFromBlocks

func (cm *Cmd) SetFromBlocks(blocks []ParseBlock) error

SetFromBlocks sets the information of the command from the given ParseBlock objects.

type Flag

type Flag struct {
	// Name is the canonical (longest) name of the flag.
	// It includes the leading dashes of the flag.
	Name string
	// Names are the different names the flag can go by.
	// They include the leading dashes of the flag.
	Names []string
	// Type is the type or value hint for the flag.
	Type string
	// Doc is the documentation for the flag.
	Doc string
}

Flag contains the information for a parsed command line flag.

type ParseBlock

type ParseBlock struct {
	Name string
	Doc  string
}

ParseBlock is a block of parsed content containing the name of something and the documentation for it.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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