Documentation
¶
Overview ¶
Readline is a pure go implementation for GNU-Readline kind library.
WHY: Readline will support most of features which GNU Readline is supported, and provide a pure go environment and a MIT license.
example:
rl, err := readline.New("> ") if err != nil { panic(err) } defer rl.Close() for { line, err := rl.Readline() if err != nil { // io.EOF break } println(line) }
Index ¶
- Constants
- Variables
- func Debug(o ...interface{})
- func Do(p PrefixCompleterInterface, line []rune, pos int) (newLine [][]rune, offset int)
- func GetInt(s []string, def int) int
- func IsPrintable(key rune) bool
- func IsTerminal(fd int) bool
- func IsWordBreak(i rune) bool
- func LineCount(w int) int
- func MakeRaw(fd int) (*terminal.State, error)
- func Print(p PrefixCompleterInterface, prefix string, level int, buf *bytes.Buffer)
- func Restore(fd int, state *terminal.State) error
- type AutoCompleter
- type Config
- type Conn
- type DumpListener
- type FdReader
- type Instance
- func (i *Instance) Close() error
- func (i *Instance) GenPasswordConfig() *Config
- func (i *Instance) IsVimMode() bool
- func (i *Instance) ReadPassword(prompt string) ([]byte, error)
- func (i *Instance) ReadPasswordEx(prompt string, l Listener) ([]byte, error)
- func (i *Instance) ReadPasswordWithConfig(cfg *Config) ([]byte, error)
- func (i *Instance) ReadSlice() ([]byte, error)
- func (i *Instance) Readline() (string, error)
- func (i *Instance) Refresh()
- func (i *Instance) SetConfig(cfg *Config) *Config
- func (i *Instance) SetHistoryPath(p string)
- func (i *Instance) SetMaskRune(r rune)
- func (i *Instance) SetPrompt(s string)
- func (i *Instance) SetVimMode(on bool)
- func (i *Instance) Stderr() io.Writer
- func (i *Instance) Stdout() io.Writer
- type Listener
- type Operation
- func (o *Operation) Close()
- func (o Operation) CloseHistory()
- func (o Operation) CompactHistory()
- func (o Operation) CompleteRefresh()
- func (o Operation) EnterCompleteMode(offset int, candidate [][]rune)
- func (o Operation) EnterCompleteSelectMode()
- func (o Operation) EnterPasswordMode(cfg *Config) (err error)
- func (o Operation) EnterVimInsertMode()
- func (o Operation) ExitCompleteMode(revent bool)
- func (o Operation) ExitCompleteSelectMode()
- func (o Operation) ExitPasswordMode()
- func (o Operation) ExitSearchMode(revert bool)
- func (o Operation) ExitVimInsertMode()
- func (o Operation) ExitVimMode()
- func (o Operation) FindHistoryBck(isNewSearch bool, rs []rune, start int) (int, *list.Element)
- func (o Operation) FindHistoryFwd(isNewSearch bool, rs []rune, start int) (int, *list.Element)
- func (o *Operation) GenPasswordConfig() *Config
- func (o Operation) HandleCompleteSelect(r rune) bool
- func (o Operation) HandleVim(r rune, readNext func() rune) rune
- func (o Operation) HandleVimNormal(r rune, readNext func() rune) (t rune)
- func (o Operation) HistoryRewrite()
- func (o Operation) InitHistory()
- func (o Operation) IsEnableVimMode() bool
- func (o Operation) IsHistoryClosed() bool
- func (o Operation) IsInCompleteMode() bool
- func (o Operation) IsInCompleteSelectMode() bool
- func (o *Operation) IsNormalMode() bool
- func (o Operation) IsSearchMode() bool
- func (o Operation) NewHistory(current []rune)
- func (o Operation) NextHistory() ([]rune, bool)
- func (o Operation) OnComplete()
- func (o *Operation) Password(prompt string) ([]byte, error)
- func (o Operation) PasswordConfig() *Config
- func (o *Operation) PasswordEx(prompt string, l Listener) ([]byte, error)
- func (o *Operation) PasswordWithConfig(cfg *Config) ([]byte, error)
- func (o Operation) PrevHistory() []rune
- func (o Operation) PushHistory(s []rune)
- func (o *Operation) Refresh()
- func (o Operation) RevertHistory()
- func (o *Operation) Runes() ([]rune, error)
- func (o Operation) SearchBackspace()
- func (o Operation) SearchChar(r rune)
- func (o Operation) SearchMode(dir int)
- func (o Operation) SearchRefresh(x int)
- func (op *Operation) SetConfig(cfg *Config) (*Config, error)
- func (o *Operation) SetHistoryPath(path string)
- func (o *Operation) SetMaskRune(r rune)
- func (o *Operation) SetPrompt(s string)
- func (o *Operation) SetTitle(t string)
- func (o Operation) SetVimMode(on bool)
- func (o *Operation) Slice() ([]byte, error)
- func (o *Operation) Stderr() io.Writer
- func (o *Operation) Stdout() io.Writer
- func (o *Operation) String() (string, error)
- func (o Operation) UpdateHistory(s []rune, commit bool)
- type PrefixCompleter
- func (p *PrefixCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int)
- func (p *PrefixCompleter) GetChildren() []PrefixCompleterInterface
- func (p *PrefixCompleter) GetName() []rune
- func (p *PrefixCompleter) Print(prefix string, level int, buf *bytes.Buffer)
- func (p *PrefixCompleter) Tree(prefix string) string
- type PrefixCompleterInterface
- type RuneBuffer
- func (r *RuneBuffer) BackEscapeWord()
- func (r *RuneBuffer) Backspace()
- func (r *RuneBuffer) Backup()
- func (r *RuneBuffer) Clean()
- func (r *RuneBuffer) CurrentWidth(x int) int
- func (r *RuneBuffer) CursorLineCount() int
- func (r *RuneBuffer) Delete() (success bool)
- func (r *RuneBuffer) DeleteWord()
- func (r *RuneBuffer) Erase()
- func (r *RuneBuffer) IdxLine() int
- func (r *RuneBuffer) Kill()
- func (r *RuneBuffer) KillFront()
- func (r *RuneBuffer) Len() int
- func (r *RuneBuffer) LineCount() int
- func (r *RuneBuffer) MoveBackward()
- func (r *RuneBuffer) MoveForward()
- func (r *RuneBuffer) MoveTo(ch rune, prevChar, reverse bool) (success bool)
- func (r *RuneBuffer) MoveToLineEnd()
- func (r *RuneBuffer) MoveToLineStart()
- func (r *RuneBuffer) MoveToNextWord()
- func (r *RuneBuffer) MoveToPrevWord() (success bool)
- func (r *RuneBuffer) Pos() int
- func (r *RuneBuffer) PromptLen() int
- func (r *RuneBuffer) Refresh(f func())
- func (r *RuneBuffer) Reset() []rune
- func (r *RuneBuffer) Restore()
- func (r *RuneBuffer) RuneSlice(i int) []rune
- func (r *RuneBuffer) Runes() []rune
- func (r *RuneBuffer) Set(buf []rune)
- func (r *RuneBuffer) SetMask(m rune)
- func (r *RuneBuffer) SetPrompt(prompt string)
- func (r *RuneBuffer) SetStyle(start, end int, style string)
- func (r *RuneBuffer) SetWithIdx(idx int, buf []rune)
- func (r *RuneBuffer) Transpose()
- func (r *RuneBuffer) WriteRune(s rune)
- func (r *RuneBuffer) WriteRunes(s []rune)
- func (r *RuneBuffer) WriteString(s string)
- type Terminal
- func (t *Terminal) Bell()
- func (t *Terminal) Close() error
- func (t *Terminal) EnterRawMode() (err error)
- func (t *Terminal) ExitRawMode() (err error)
- func (t *Terminal) IsReading() bool
- func (t *Terminal) KickRead()
- func (t *Terminal) Print(s string)
- func (t *Terminal) PrintRune(r rune)
- func (t *Terminal) ReadRune() rune
- func (t *Terminal) Readline() *Operation
- func (t *Terminal) SetConfig(c *Config) error
- func (t *Terminal) Write(b []byte) (int, error)
Constants ¶
View Source
const ( CharLineStart = 1 CharBackward = 2 CharInterrupt = 3 CharDelete = 4 CharLineEnd = 5 CharForward = 6 CharBell = 7 CharCtrlH = 8 CharTab = 9 CharCtrlJ = 10 CharKill = 11 CharEnter = 13 CharNext = 14 CharPrev = 16 CharBckSearch = 18 CharFwdSearch = 19 CharTranspose = 20 CharCtrlU = 21 CharCtrlW = 23 CharEsc = 27 CharEscapeEx = 91 CharBackspace = 127 )
View Source
const ( MetaBackward rune = -iota - 1 MetaForward MetaDelete MetaBackspace MetaTranspose )
View Source
const ( S_STATE_FOUND = iota S_STATE_FAILING )
View Source
const ( S_DIR_BCK = iota S_DIR_FWD )
View Source
const ( VIM_NORMAL = iota VIM_INSERT VIM_VISUAL )
Variables ¶
View Source
var ( Stdin io.ReadCloser = os.Stdin Stdout io.WriteCloser = os.Stdout Stderr io.WriteCloser = os.Stderr )
View Source
var (
ErrInterrupt = errors.New("Interrupt")
)
View Source
var (
StdinFd = int(uintptr(syscall.Stdin))
)
Functions ¶
func IsPrintable ¶
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
func IsWordBreak ¶
Types ¶
type AutoCompleter ¶
type AutoCompleter interface { // Readline will pass the whole line and current offset to it // Completer need to pass all the candidates, and how long they shared the same characters in line // Example: // Do("g", 1) => ["o", "it", "it-shell", "rep"], 1 // Do("gi", 2) => ["t", "t-shell"], 1 // Do("git", 3) => ["", "-shell"], 0 Do(line []rune, pos int) (newLine [][]rune, length int) }
type Config ¶
type Config struct { // prompt supports ANSI escape sequence, so we can color some characters even in windows Prompt string // readline will persist historys to file where HistoryFile specified HistoryFile string // specify the max length of historys, it's 500 by default, set it to -1 to disable history HistoryLimit int // AutoCompleter will called once user press TAB AutoComplete AutoCompleter // Any key press will pass to Listener // NOTE: Listener will be triggered by (nil, 0, 0) immediately Listener Listener // If VimMode is true, readline will in vim.insert mode by default VimMode bool InterruptPrompt string EOFPrompt string Stdin FdReader Stdout io.Writer Stderr io.Writer MaskRune rune UniqueEditLine bool // contains filtered or unexported fields }
type DumpListener ¶
type DumpListener struct {
// contains filtered or unexported fields
}
type Instance ¶
func (*Instance) GenPasswordConfig ¶
func (*Instance) ReadPasswordEx ¶
func (*Instance) ReadPasswordWithConfig ¶
we can generate a config by `i.GenPasswordConfig()`
func (*Instance) SetHistoryPath ¶
change hisotry persistence in runtime
func (*Instance) SetMaskRune ¶
type Listener ¶
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
func NewOperation ¶
func (Operation) CloseHistory ¶
func (o Operation) CloseHistory()
func (Operation) CompactHistory ¶
func (o Operation) CompactHistory()
func (Operation) CompleteRefresh ¶
func (o Operation) CompleteRefresh()
func (Operation) EnterCompleteMode ¶
func (Operation) EnterCompleteSelectMode ¶
func (o Operation) EnterCompleteSelectMode()
func (Operation) EnterPasswordMode ¶
func (Operation) EnterVimInsertMode ¶
func (o Operation) EnterVimInsertMode()
func (Operation) ExitCompleteMode ¶
func (o Operation) ExitCompleteMode(revent bool)
func (Operation) ExitCompleteSelectMode ¶
func (o Operation) ExitCompleteSelectMode()
func (Operation) ExitPasswordMode ¶
func (o Operation) ExitPasswordMode()
func (Operation) ExitSearchMode ¶
func (o Operation) ExitSearchMode(revert bool)
func (Operation) ExitVimInsertMode ¶
func (o Operation) ExitVimInsertMode()
func (Operation) ExitVimMode ¶
func (o Operation) ExitVimMode()
func (Operation) FindHistoryBck ¶
func (Operation) FindHistoryFwd ¶
func (*Operation) GenPasswordConfig ¶
func (Operation) HandleCompleteSelect ¶
func (Operation) HandleVimNormal ¶
func (Operation) HistoryRewrite ¶
func (o Operation) HistoryRewrite()
func (Operation) InitHistory ¶
func (o Operation) InitHistory()
func (Operation) IsEnableVimMode ¶
func (o Operation) IsEnableVimMode() bool
func (Operation) IsHistoryClosed ¶
func (o Operation) IsHistoryClosed() bool
func (Operation) IsInCompleteMode ¶
func (o Operation) IsInCompleteMode() bool
func (Operation) IsInCompleteSelectMode ¶
func (o Operation) IsInCompleteSelectMode() bool
func (*Operation) IsNormalMode ¶
func (Operation) IsSearchMode ¶
func (o Operation) IsSearchMode() bool
func (Operation) NewHistory ¶
func (o Operation) NewHistory(current []rune)
func (Operation) NextHistory ¶
func (Operation) OnComplete ¶
func (o Operation) OnComplete()
func (Operation) PasswordConfig ¶
func (o Operation) PasswordConfig() *Config
func (*Operation) PasswordEx ¶
func (*Operation) PasswordWithConfig ¶
func (Operation) PrevHistory ¶
func (o Operation) PrevHistory() []rune
func (Operation) PushHistory ¶
func (o Operation) PushHistory(s []rune)
func (Operation) RevertHistory ¶
func (o Operation) RevertHistory()
func (Operation) SearchBackspace ¶
func (o Operation) SearchBackspace()
func (Operation) SearchChar ¶
func (o Operation) SearchChar(r rune)
func (Operation) SearchMode ¶
func (o Operation) SearchMode(dir int)
func (Operation) SearchRefresh ¶
func (o Operation) SearchRefresh(x int)
func (*Operation) SetHistoryPath ¶
func (*Operation) SetMaskRune ¶
func (Operation) SetVimMode ¶
func (o Operation) SetVimMode(on bool)
func (Operation) UpdateHistory ¶
type PrefixCompleter ¶
type PrefixCompleter struct { Name []rune Children []PrefixCompleterInterface }
func NewPrefixCompleter ¶
func NewPrefixCompleter(pc ...PrefixCompleterInterface) *PrefixCompleter
func PcItem ¶
func PcItem(name string, pc ...PrefixCompleterInterface) *PrefixCompleter
func (*PrefixCompleter) Do ¶
func (p *PrefixCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int)
func (*PrefixCompleter) GetChildren ¶
func (p *PrefixCompleter) GetChildren() []PrefixCompleterInterface
func (*PrefixCompleter) GetName ¶
func (p *PrefixCompleter) GetName() []rune
func (*PrefixCompleter) Print ¶
func (p *PrefixCompleter) Print(prefix string, level int, buf *bytes.Buffer)
func (*PrefixCompleter) Tree ¶
func (p *PrefixCompleter) Tree(prefix string) string
type RuneBuffer ¶
type RuneBuffer struct {
// contains filtered or unexported fields
}
func NewRuneBuffer ¶
func NewRuneBuffer(w io.Writer, prompt string, mask rune) *RuneBuffer
func (*RuneBuffer) BackEscapeWord ¶
func (r *RuneBuffer) BackEscapeWord()
func (*RuneBuffer) Backspace ¶
func (r *RuneBuffer) Backspace()
func (*RuneBuffer) Backup ¶
func (r *RuneBuffer) Backup()
func (*RuneBuffer) Clean ¶
func (r *RuneBuffer) Clean()
func (*RuneBuffer) CurrentWidth ¶
func (r *RuneBuffer) CurrentWidth(x int) int
func (*RuneBuffer) CursorLineCount ¶
func (r *RuneBuffer) CursorLineCount() int
func (*RuneBuffer) Delete ¶
func (r *RuneBuffer) Delete() (success bool)
func (*RuneBuffer) DeleteWord ¶
func (r *RuneBuffer) DeleteWord()
func (*RuneBuffer) Erase ¶
func (r *RuneBuffer) Erase()
func (*RuneBuffer) IdxLine ¶
func (r *RuneBuffer) IdxLine() int
func (*RuneBuffer) Kill ¶
func (r *RuneBuffer) Kill()
func (*RuneBuffer) KillFront ¶
func (r *RuneBuffer) KillFront()
func (*RuneBuffer) Len ¶
func (r *RuneBuffer) Len() int
func (*RuneBuffer) LineCount ¶
func (r *RuneBuffer) LineCount() int
func (*RuneBuffer) MoveBackward ¶
func (r *RuneBuffer) MoveBackward()
func (*RuneBuffer) MoveForward ¶
func (r *RuneBuffer) MoveForward()
func (*RuneBuffer) MoveTo ¶
func (r *RuneBuffer) MoveTo(ch rune, prevChar, reverse bool) (success bool)
func (*RuneBuffer) MoveToLineEnd ¶
func (r *RuneBuffer) MoveToLineEnd()
func (*RuneBuffer) MoveToLineStart ¶
func (r *RuneBuffer) MoveToLineStart()
func (*RuneBuffer) MoveToNextWord ¶
func (r *RuneBuffer) MoveToNextWord()
func (*RuneBuffer) MoveToPrevWord ¶
func (r *RuneBuffer) MoveToPrevWord() (success bool)
func (*RuneBuffer) Pos ¶
func (r *RuneBuffer) Pos() int
func (*RuneBuffer) PromptLen ¶
func (r *RuneBuffer) PromptLen() int
func (*RuneBuffer) Refresh ¶
func (r *RuneBuffer) Refresh(f func())
func (*RuneBuffer) Reset ¶
func (r *RuneBuffer) Reset() []rune
func (*RuneBuffer) Restore ¶
func (r *RuneBuffer) Restore()
func (*RuneBuffer) RuneSlice ¶
func (r *RuneBuffer) RuneSlice(i int) []rune
func (*RuneBuffer) Runes ¶
func (r *RuneBuffer) Runes() []rune
func (*RuneBuffer) Set ¶
func (r *RuneBuffer) Set(buf []rune)
func (*RuneBuffer) SetMask ¶
func (r *RuneBuffer) SetMask(m rune)
func (*RuneBuffer) SetPrompt ¶
func (r *RuneBuffer) SetPrompt(prompt string)
func (*RuneBuffer) SetStyle ¶
func (r *RuneBuffer) SetStyle(start, end int, style string)
func (*RuneBuffer) SetWithIdx ¶
func (r *RuneBuffer) SetWithIdx(idx int, buf []rune)
func (*RuneBuffer) Transpose ¶
func (r *RuneBuffer) Transpose()
func (*RuneBuffer) WriteRune ¶
func (r *RuneBuffer) WriteRune(s rune)
func (*RuneBuffer) WriteRunes ¶
func (r *RuneBuffer) WriteRunes(s []rune)
func (*RuneBuffer) WriteString ¶
func (r *RuneBuffer) WriteString(s string)
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
func NewTerminal ¶
func (*Terminal) EnterRawMode ¶
func (*Terminal) ExitRawMode ¶
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
example
|
|
readline-pass-strength
This is a small example using readline to read a password and check it's strength while typing using the zxcvbn library.
|
This is a small example using readline to read a password and check it's strength while typing using the zxcvbn library. |
Click to show internal directories.
Click to hide internal directories.