Source File
prompt.go
Belonging Package
github.com/reeflective/console/internal/ui
package uiimport ()// Prompt - A prompt is a set of functions that return the strings to print// for each prompt type. The console will call these functions to retrieve// the prompt strings to print. Each menu has its own prompt.type Prompt struct {Primary func() string // Primary is the main prompt.Secondary func() string // Secondary is the prompt used when the user is typing a multi-line command.Transient func() string // Transient is used if the console shell is configured to be transient.Right func() string // Right is the prompt printed on the right side of the screen.Tooltip func(word string) string // Tooltip is used to hint on the root command, replacing right prompts if not empty.}// NewPrompt requires the name of the application and the current menu,// as well as the current menu output buffer to produce a new, default prompt.func (, string, *bytes.Buffer) *Prompt {:= &Prompt{}.Primary = func() string {:=// menu := app.activeMenu()if == "" {return + " > "}+= fmt.Sprintf(" [%s]", )// If the buffered command output is not empty,// add a special status indicator to the prompt.if strings.TrimSpace(.String()) != "" {+= " $(...)"}return + " > "}return}// BindPrompt reassigns the prompt printing functions to the shell helpers.func ( *Prompt, *readline.Shell) {:= .Prompt// If the user has bound its own primary prompt and the shell// must leave a newline after command/log output, wrap its function// to add a newline before the prompt.:= func() string {if .Primary == nil {return ""}:= .Primary()return}.Primary().Right(.Right).Secondary(.Secondary).Transient(.Transient).Tooltip(.Tooltip)}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |