scaffold

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scaffold writes config for the user: the starter `tui-builder init` prints.

Index

Constants

View Source
const DefaultExecTimeout = 10 * time.Second

DefaultExecTimeout is the exec source's own default, used for the sample run when no --timeout is given.

Variables

View Source
var (
	ComponentKinds = config.ComponentKinds
	SourceKinds    = []string{"http", "exec", "file", "websocket", "static", "merge"}
)

ComponentKinds and SourceKinds are what `init <kind>` takes.

View Source
var (
	StreamWindow = 3 * time.Second
	StreamLines  = 20
)

Stream sampling: a command still running this long after it started, having printed something, is a stream; a stream is sampled for this long or this many lines, whichever comes first. Variables so tests can shorten them.

View Source
var Components = []string{"table", "list", "inspector", "eventlog", "logview"}

Components add exec can write.

View Source
var Places = []string{"stack", "tab", "screen"}

Places a component can go, for --place.

Functions

func Kinds

func Kinds() []string

Kinds are the kinds `init <kind>` takes: components, then sources.

func SampleArgv

func SampleArgv(argv []string) []string

SampleArgv is the command to sample: argv as given, except window tokens written straight into it, which take sampleDefaults. An argument whose tokens are all empty is dropped, as at runtime.

func ShellJoin

func ShellJoin(argv []string) string

ShellJoin writes argv the way you'd type it, quoting what a shell would split or expand.

func Starter

func Starter(title string) []byte

Starter is the config `tui-builder init` writes, titled title.

func WriteAtomic

func WriteAtomic(path string, b []byte) error

WriteAtomic replaces path with b: a temporary file beside it, given path's mode, renamed over it.

Types

type ColumnSpec

type ColumnSpec struct {
	Path  string
	Title string
}

ColumnSpec is one --columns entry: a dot-path and an optional title.

func ParseColumns

func ParseColumns(s string) ([]ColumnSpec, error)

ParseColumns reads path[=Title],… .

type Example

type Example struct {
	Config []byte
	Files  map[string][]byte
}

Example is what `tui-builder init <kind>` writes: the config, and any files it reads, by name, to write beside it.

func Kind

func Kind(kind, title, dir string) (Example, error)

Kind is what `tui-builder init <kind>` writes, titled title: a small config built around kind that runs, with every field kind takes below it, commented out. dir is the directory the config goes in, as the command line gave it, so a path in it finds the files beside it.

type ExecOptions

type ExecOptions struct {
	// Argv is the command, exactly as given after --.
	Argv []string
	// Timeout is --timeout; zero leaves the source on the exec default
	// and writes no timeout:.
	Timeout time.Duration
	// Root is --root: where the rows are, overriding inference.
	Root string
	// MaxColumns is --max-columns: how many columns are kept, the rest
	// written commented out. Zero is columns.DefaultMax.
	MaxColumns int
	// NoStyle is --no-style: no bold, colour rules or widths.
	NoStyle bool
	// Params are --param: argv values made into source parameters.
	Params []Param
	// NoInputs is --no-inputs: parameters without input fields.
	NoInputs bool
	// Columns is --columns: the set and order, skipping ranking.
	Columns []ColumnSpec
	// Component is --component; "" infers it.
	Component string
	// Name is --name for the source and component; "" names them from
	// the command.
	Name string
	// Title is --title for the component; "" title-cases the name.
	Title string
	// Refresh is --refresh; zero leaves the source one-shot.
	Refresh time.Duration
	// Follow is --follow / --no-follow; with --no-run only FollowYes
	// matters, and writes a stream source.
	Follow Follow
	// Window is --window and the flags that shape a window.
	Window WindowOptions
}

ExecOptions is what `tui-builder add exec` was asked for.

type Field

type Field struct {
	Name, Type, Default, ValidOn, Desc string
}

Field is one row of a docs/reference field table, its cells as the docs write them (markdown and all).

type Follow

type Follow int

Follow says whether the command is a stream.

const (
	// FollowAuto decides from how the command behaves.
	FollowAuto Follow = iota
	// FollowYes is --follow: it streams, so sample it without waiting
	// to find out.
	FollowYes
	// FollowNo is --no-follow: it finishes, however long it takes (up to
	// the timeout).
	FollowNo
)

type Output

type Output struct {
	Stdout []byte
	// Truncated is set when stdout ran past config.DefaultMaxBody and
	// was cut there.
	Truncated bool
	// Stream is set when the command was still running when sampling
	// stopped: Stdout holds the complete lines it had printed.
	Stream bool
	// Detected is set on a stream found by watching it (not --follow).
	Detected bool
}

Output is what a sample run of a command printed.

func Run

func Run(ctx context.Context, argv []string, timeout time.Duration, follow Follow) (Output, error)

Run runs argv as the exec source will: no shell, the inherited environment and working directory. A command that finishes must exit zero and print something within the timeout. One that keeps running is a stream (see Follow): it's stopped after StreamWindow or StreamLines, and what it printed is the sample.

type Param

type Param struct {
	Name  string
	Value string
	// Type is string (the default), int, bool or duration.
	Type string
}

Param is one --param: an argv value made into a source parameter.

func ParseParam

func ParseParam(s string) (Param, error)

ParseParam reads NAME=VALUE[:TYPE]. A trailing :TYPE counts only when it's one of the parameter types, so a value like a URL keeps its colons.

type Result

type Result struct {
	Config []byte

	// Summary lists each choice and whether it was inferred or came
	// from a flag.
	Summary []string
	// Warnings are flags the sample didn't bear out, short of an error.
	Warnings []string
	// contains filtered or unexported fields
}

Result is a written config and what to tell the user about it.

func ExecConfig

func ExecConfig(opts ExecOptions, out Output) (Result, error)

ExecConfig infers a source and the component that shows it from a sample of the command's output, and returns a complete config.

func ExecConfigNoRun

func ExecConfigNoRun(opts ExecOptions) (Result, error)

ExecConfigNoRun is --no-run: the source, unsampled. Without a sample there's no shape, so it's shown by an auto inspector unless --columns gives a table or list its columns.

type Spliced

type Spliced struct {
	Old, New []byte
	// Summary says what went where: "added source pods, table pods to
	// screen main".
	Summary string
	// Notes are things worth knowing about where it went.
	Notes []string
}

Spliced is a config with add exec's result added to it.

func SpliceInto

func SpliceInto(old []byte, res Result, place, dir string) (Spliced, error)

SpliceInto adds res's source, components and layout to the config in old, by inserting lines into it: nothing else in the file is rewritten, so comments, quoting and layout survive. place is "" (by the config's shape) or one of Places. dir is the config's directory, for checking the result loads with its relative paths.

type WindowMark

type WindowMark struct {
	// Token is offset, limit, search, sort, sort_dir, cursor, dir or
	// filters.NAME.
	Token string
	Value string
}

WindowMark is one --window: an argv value that's a window token.

func ParseWindow

func ParseWindow(s string) (WindowMark, error)

ParseWindow reads TOKEN=VALUE, or filter.NAME=VALUE.

type WindowOptions

type WindowOptions struct {
	Marks []WindowMark
	// TotalPath is --total-path; CursorPath is --cursor-path.
	TotalPath, CursorPath string
	// Growing is --growing; FollowEvery is --follow-every.
	Growing     bool
	FollowEvery time.Duration
}

Window options on ExecOptions.

Directories

Path Synopsis
Command gendocs turns the field tables in docs/reference into internal/scaffold/fields_gen.go, the field list `tui-builder init <kind>` writes as comments.
Command gendocs turns the field tables in docs/reference into internal/scaffold/fields_gen.go, the field list `tui-builder init <kind>` writes as comments.

Jump to

Keyboard shortcuts

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