Documentation ¶
Index ¶
- Constants
- func InputChan(file *os.File) <-chan rune
- func ProcessInput(ctx context.Context, file *os.File, commands Commands)
- func Prompt(format string, v ...interface{})
- func PromptVerbose(format string, v ...interface{})
- func SetCommands(c Commands)
- func SetupLogging(setup LogSetupFunc)
- func SigWait(ctx context.Context, cancel context.CancelFunc) (os.Signal, error)
- func WithSigWait(parent context.Context, opt ...Option) (context.Context, context.CancelFunc)
- type Clock
- type Command
- type CommandInfoFormatter
- type Commands
- type DisplayTime
- type LogSetupFunc
- type Option
- type RestoreFunc
- type Term
- func (c *Term) GetClock() *Clock
- func (c *Term) GetMessage() string
- func (c *Term) Help()
- func (c *Term) IsDebug() bool
- func (c *Term) IsRaw() bool
- func (c *Term) IsVerbose() bool
- func (c *Term) Println(s string) (int, error)
- func (c *Term) Prompt(v ...string)
- func (c *Term) SetDebug(v bool) *Term
- func (c *Term) SetMessage(msg string)
- func (c *Term) SetVerbose(v bool) *Term
- func (c *Term) StartClock(ctx context.Context)
- func (c *Term) Sync() (int, error)
- func (c *Term) WrapOutput(w io.Writer)
- func (c *Term) Write(b []byte) (int, error)
- func (c *Term) WriteString(s string) (int, error)
Constants ¶
const ( // TimeFormatHuman is the only reasonable time format for human readability. TimeFormatHuman = "2006-01-02 15:04:05" ClearAll = "\r \r" )
Supported logger types
const ( // CR is the carriage return byte CR = byte(13) // NL is the newline byte NL = byte(10) )
Variables ¶
This section is empty.
Functions ¶
func ProcessInput ¶
ProcessInput reads runes from input chan and executes the `commands` mapped to the received input keys.
func Prompt ¶
func Prompt(format string, v ...interface{})
Prompt sets the global prompt message displayed in the interactive log line.
func PromptVerbose ¶
func PromptVerbose(format string, v ...interface{})
PromptVerbose sets the global prompt message if in debug mode.
func SetupLogging ¶
func SetupLogging(setup LogSetupFunc)
SetupLogging configures interactive logging for commandline applications.
func SigWait ¶
SigWait waits for OS signals and cancels the given context on SIGINT or SIGTERM. It blocks until the context is canceled either by the awaited signal or externally. It returns the received signal and the context's error.
func WithSigWait ¶
WithSigWait returns a context.Context that is canceled on OS signal.
WithSigWait starts a goroutine that waits for OS signals SIGINT or SIGTERM and cancels the returned context after receiving the signal. Depending on the options, WithSigWait starts processing input and sets up commands.
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock stores the current clock step and text.
func (*Clock) DisplayTime ¶
func (c *Clock) DisplayTime(tickInterval time.Duration) *DisplayTime
DisplayTime returns the current clock text.
type Command ¶
Command define a command.
func (*Command) Run ¶
func (c *Command) Run()
Run runs the command and sets the Prompt to indicate that the command was run.
func (*Command) StartsWithKey ¶
StartsWithKey tells if a command name starts with the command key.
type CommandInfoFormatter ¶
CommandInfoFormatter formats a command.
type Commands ¶
type Commands []Command
Commands provides convenient functions on a list of commands.
func (Commands) Info ¶
func (c Commands) Info(fn CommandInfoFormatter) []string
Info returns the command names and keys as strings.
type DisplayTime ¶
DisplayTime defines the visible values for a time.
type LogSetupFunc ¶
LogSetupFunc configures a specific Logger.
type Option ¶
type Option func(*options)
Option defines a sigwait option.
func WithInput ¶
WithInput makes sigwait run the given commands on receiving user input. The keys q, Q, CTRL-C, and CTRL-D are reserved to quit the program.
func WithQuit ¶
func WithQuit() Option
WithQuit add the default quit commands and enables user input.
func WithoutClock ¶
func WithoutClock() Option
WithoutClock disabled the default ascii/unicode clock in the last terminal line.
type RestoreFunc ¶
type RestoreFunc func() error
RestoreFunc restores the terminal.
func ClaimTerminal ¶
func ClaimTerminal() (RestoreFunc, error)
ClaimTerminal sets the terminal to raw input mode and returns a RestoreFunc for resetting the terminal to normal mode.
type Term ¶
type Term struct {
// contains filtered or unexported fields
}
Term stores shared terminal state about loggers, the underlying terminals, and commands.
func AcquireTerm ¶
func AcquireTerm() (*Term, func())
AcquireTerm locks and returns the global terminal.
func (*Term) Help ¶ added in v0.0.14
func (c *Term) Help()
Help prints and prompts help for the configured Commands.
func (*Term) SetVerbose ¶
SetVerbose enabled or disables verbose output on stderr.
func (*Term) StartClock ¶
StartClock starts the terminal clock to ingest clock output into the status line.