Documentation ¶
Index ¶
- Variables
- func Init()
- func NewHistory(filename string) (*history, error)
- func NewHistorySize(filename string, size int) (*history, error)
- type Line
- type Question
- func (q *Question) Read(prompt string) (answer string, err error)
- func (q *Question) ReadBool(prompt string, defaultAnswer bool) (answer bool, err error)
- func (q *Question) ReadChoice(prompt string, a []string) (answer string, err error)
- func (q *Question) ReadChoiceDefault(prompt string, a []string, defaultAnswer uint) (answer string, err error)
- func (q *Question) ReadFloat(prompt string) (answer float64, err error)
- func (q *Question) ReadFloatDefault(prompt string, defaultAnswer float64) (answer float64, err error)
- func (q *Question) ReadInt(prompt string) (answer int, err error)
- func (q *Question) ReadIntDefault(prompt string, defaultAnswer int) (answer int, err error)
- func (q *Question) ReadString(prompt string) (answer string, err error)
- func (q *Question) ReadStringDefault(prompt, defaultAnswer string) (answer string, err error)
- func (q *Question) RestoreTerm()
Constants ¶
This section is empty.
Variables ¶
var ( BufferCap = 4096 BufferLen = 64 // Initial length )
Buffer size
var ( ErrCtrlD = fmt.Errorf("Interrumpted (Ctrl-d)") ErrEmptyHist = fmt.Errorf("history: empty") ErrNilElement = fmt.Errorf("history: no more elements") )
var ( HistoryCap = 500 // Capacity HistoryPerm uint32 = 0600 // History file permission )
Values by default
var ( PS1 = "linoise$ " PS2 = "> " )
Values by default for prompts.
var ( QuestionPrefix = " + " // String placed before of questions QuestionErrPrefix = " " // String placed before of error messages QuestionTrueString = "y" // String to represent 'true' by default QuestionFalseString = "n" // Idem but for 'false' QuestionFloatFmt byte = 'g' // Format for float numbers QuestionFloatPrec int = -1 // Precision for float numbers )
Values by default
var ExtraBoolString = make(map[string]bool)
To pass strings in another languages.
Functions ¶
func NewHistory ¶
Creates a new history using the maximum length by default.
func NewHistorySize ¶
Creates a new history whose buffer has the specified size, which must be greater than zero.
Types ¶
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Represents a line.
func NewLine ¶
func NewLine(hist *history) *Line
Gets a line type using the primary prompt by default. Sets the TTY raw mode.
func NewLinePrompt ¶
Gets a line type using the given prompt as primary. Sets the TTY raw mode. 'ansiLen' is the length of ANSI codes that the prompt could have.
func (*Line) Read ¶
Reads charactes from input to write them to output, allowing line editing. The errors that could return are to indicate if Ctrl-D was pressed, and for both input / output errors.
func (*Line) RestoreTerm ¶
func (ln *Line) RestoreTerm()
Restores terminal settings so it is disabled the raw mode.
type Question ¶
type Question struct {
// contains filtered or unexported fields
}
func (*Question) ReadChoice ¶
Prints the prompt waiting to get an element from array `a`. If input is nil then it returns the first element of `a`.
func (*Question) ReadChoiceDefault ¶
func (q *Question) ReadChoiceDefault(prompt string, a []string, defaultAnswer uint) (answer string, err error)
Prints the prompt waiting to get an element from array `a`. If input is nil then it returns the answer by default which is the position inner array.
func (*Question) ReadFloatDefault ¶
func (q *Question) ReadFloatDefault(prompt string, defaultAnswer float64) (answer float64, err error)
Prints the prompt waiting to get a float number. If input is nil then it returns the answer by default.
func (*Question) ReadIntDefault ¶
Prints the prompt waiting to get an integer number. If input is nil then it returns the answer by default.
func (*Question) ReadString ¶
Prints the prompt waiting to get a string.
func (*Question) ReadStringDefault ¶
Prints the prompt waiting to get a string. If input is nil then it returns the answer by default.