Documentation
¶
Overview ¶
Package scaffold writes config for the user: the starter `tui-builder init` prints.
Index ¶
- Constants
- Variables
- func Kinds() []string
- func SampleArgv(argv []string) []string
- func ShellJoin(argv []string) string
- func Starter(title string) []byte
- func WriteAtomic(path string, b []byte) error
- type ColumnSpec
- type Example
- type ExecOptions
- type Field
- type Follow
- type Output
- type Param
- type Result
- type Spliced
- type WindowMark
- type WindowOptions
Constants ¶
const DefaultExecTimeout = 10 * time.Second
DefaultExecTimeout is the exec source's own default, used for the sample run when no --timeout is given.
Variables ¶
var ( ComponentKinds = config.ComponentKinds SourceKinds = []string{"http", "exec", "file", "websocket", "static", "merge"} )
ComponentKinds and SourceKinds are what `init <kind>` takes.
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.
var Components = []string{"table", "list", "inspector", "eventlog", "logview"}
Components add exec can write.
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 ¶
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 ¶
ShellJoin writes argv the way you'd type it, quoting what a shell would split or expand.
func WriteAtomic ¶
WriteAtomic replaces path with b: a temporary file beside it, given path's mode, renamed over it.
Types ¶
type ColumnSpec ¶
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 ¶
Example is what `tui-builder init <kind>` writes: the config, and any files it reads, by name, to write 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 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 ¶
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 ¶
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 ¶
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.
Source Files
¶
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. |