Documentation
¶
Overview ¶
Package readline provides an easier-to-use wrapper around creadline.
Example:
readline.Init(readline.Opts{Name: "myapp"})
for {
line = readline.Readline("> ")
processInput(line)
readline.AddHistory(line)
}
Signal handling ¶
Readline intercepts SIGINT (Ctrl-C). On SIGINT, the ongoing Readline call aborts and returns an Interrupt error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Interrupt is returned by Readline on SIGINT (i.e., Control-C keypress). Interrupt = creadline.Interrupt )
Functions ¶
func AddHistory ¶
AddHistory adds a history entry. It appends the entry both inmemory list and Opts.HistoryPath. It may truncate the history list if it grows larger than Opts.MaxHistoryLen. Thread-hostile.
REQUIRES: Init has been called.
func GetScreenSize ¶
GetScreenSize returns the current screen size, (#rows, #cols). It returns nonpositive values when the stdout is not a terminal, or on any error.
Types ¶
type Opts ¶
type Opts struct {
// Name is the name of the application. It is used to generate the default
// history pathname (~/.NAME_history). It may be empty.
Name string
// InitPath is the name of the readline init file. It may be empty.
//
// https://tiswww.case.edu/php/chet/readline/readline.html#SEC9
InitPath string
// HistoryPath is the name of the readline history file. If "" and Name is
// nonempty, then its value will be ~/.NAME_history. If both HistoryPath and
// Name are empty, then its value will be ~/.history.
HistoryPath string
// MaxHistoryLen is the maximum number of history entries to retain. If <= 0,
// the last 10000 entries will be retained.
MaxHistoryLen int
// ExpandHistory enables history expansion, such as "!tok".
ExpandHistory bool
// Completer is invoked to complete a line. It may be nil. The arg line is
// the current input line. Args start and end are the start and limit offset
// of the word being completed, respectively.
Completer func(line string, start, end int) []string
}
Opts define options for the readline package.
Click to show internal directories.
Click to hide internal directories.