Documentation ¶
Overview ¶
Package interactive provides an easy to implement shell for simple, interactive commandline applications. It is build on top of the excellent https://golang.org/x/crypto/ssh/terminal package and tries to simplify the creation of small and simple applications which run in shell mode. It isn't very powerful (yet) but has enough features for basic usage. For example it shuts down gracefully on Ctrl^C and Ctrl^D.
This small application echos the entered text:
s := interactive.New(">") s.Action = func(c *interactive.Context) error { text, _ := c.Scan() c.Println(text) return nil } s.Run()
Returning an error instead of nil will print the error. Calling context.Close() will close the session with the specified exit code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
*Session
}
A Context is bound to a session and provides methods to interact with it. It hasn't anything in common with the official context package/type.
func (*Context) Close ¶
Close will close the session with the specified exit code and restore the terminal into the previous state.
func (*Context) Print ¶
func (c *Context) Print(a ...interface{})
Print formats using the default formats for its operands and writes to the sessions output. Spaces are added between operands when neither is a string. See fmt.Sprint and fmt.Print for more information.
func (*Context) Printf ¶
Printf formats according to a format specifier and writes to the sessions output. See fmt.Sprintf and fmt.Printf for more information.
func (*Context) Println ¶
func (c *Context) Println(a ...interface{})
Println formats using the default formats for its operands and writes to the sessions output. Spaces are always added between operands and a newline is appended. See fmt.Sprintln and fmt.Println for more information.
func (*Context) ScanHidden ¶
ScanHidden reads without echo.
type Session ¶
type Session struct { // Action is the actual application logic which is looped until the // application gets terminated. Action Action // After is run AFTER the action function, BEFORE the session is closed. After Action // Before is run BEFORE the action function. Before Action // contains filtered or unexported fields }
A Session is an interactive shell. The New() function should be used to obtain a new Session instance.