package readline
Import Path
github.com/chzyer/readline (on go.dev )
Dependency Relation
imports 19 packages , and imported by one package
Package-Level Type Names (total 43, in which 28 are exported)
/* sort exporteds by: alphabet | popularity */
type AutoCompleter (interface)
Methods (only one, which is exported )
( T) Do (line []rune , pos int ) (newLine [][]rune , length int )
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:
[go, git, git-shell, grep]
Do("g", 1) => ["o", "it", "it-shell", "rep"], 1
Do("gi", 2) => ["t", "t-shell"], 2
Do("git", 3) => ["", "-shell"], 3
Implemented By (at least 5, all are exported )
DynamicPrefixCompleterInterface (interface)
*PrefixCompleter
PrefixCompleterInterface (interface)
*SegmentComplete
*TabCompleter
As Outputs Of (at least one exported )
func SegmentFunc (f func([][]rune , int ) [][]rune ) AutoCompleter
As Inputs Of (at least one exported )
func SetAutoComplete (completer AutoCompleter )
type Config (struct)
Fields (total 28, in which 25 are exported )
AutoComplete AutoCompleter
AutoCompleter will called once user press TAB
DisableAutoSaveHistory bool
EOFPrompt string
EnableMask bool
ForceUseInteractive bool
FuncExitRaw func() error
FuncFilterInputRune func(rune ) (rune , bool )
filter input runes (may be used to disable CtrlZ or for translating some keys to different actions)
-> output = new (translated) rune and true/false if continue with processing this one
FuncGetWidth func() int
FuncIsTerminal func() bool
force use interactive even stdout is not a tty
FuncMakeRaw func() error
FuncOnWidthChanged func(func())
HistoryFile string
readline will persist historys to file where HistoryFile specified
HistoryLimit int
specify the max length of historys, it's 500 by default, set it to -1 to disable history
HistorySearchFold bool
enable case-insensitive history searching
InterruptPrompt string
Listener Listener
Any key press will pass to Listener
NOTE: Listener will be triggered by (nil, 0, 0) immediately
MaskRune rune
Painter Painter
Prompt string
prompt supports ANSI escape sequence, so we can color some characters even in windows
Stderr io .Writer
Stdin io .ReadCloser
StdinWriter io .Writer
Stdout io .Writer
UniqueEditLine bool
erase the editing line after user submited it
it use in IM usually.
VimMode bool
If VimMode is true, readline will in vim.insert mode by default
/* 3 unexporteds ... */ /* 3 unexporteds: */
inited bool
private fields
opHistory *opHistory
opSearch *opSearch
Methods (total 5, in which 4 are exported )
( T) Clone () *Config
(*T) Init () error
(*T) SetListener (f func(line []rune , pos int , key rune ) (newLine []rune , newPos int , ok bool ))
(*T) SetPainter (p Painter )
/* one unexported ... */ /* one unexported: */
(*T) useInteractive () bool
As Outputs Of (at least 7, all are exported )
func Config.Clone () *Config
func (*Instance ).GenPasswordConfig () *Config
func (*Instance ).SetConfig (cfg *Config ) *Config
func (*Operation ).GenPasswordConfig () *Config
func (*Operation ).GetConfig () *Config
func (*Operation ).SetConfig (cfg *Config ) (*Config , error )
func (*Terminal ).GetConfig () *Config
As Inputs Of (at least 15, in which 13 are exported )
func HandleConn (cfg Config , conn net .Conn ) (*Instance , error )
func ListenRemote (n, addr string , cfg *Config , h func(*Instance ), onListen ...func(net .Listener ) error ) error
func NewEx (cfg *Config ) (*Instance , error )
func NewOperation (t *Terminal , cfg *Config ) *Operation
func NewRuneBuffer (w io .Writer , prompt string , cfg *Config , width int ) *RuneBuffer
func NewTerminal (cfg *Config ) (*Terminal , error )
func (*Instance ).ReadPasswordWithConfig (cfg *Config ) ([]byte , error )
func (*Instance ).SetConfig (cfg *Config ) *Config
func (*Operation ).PasswordWithConfig (cfg *Config ) ([]byte , error )
func (*Operation ).SetConfig (cfg *Config ) (*Config , error )
func (*RemoteSvr ).HandleConfig (cfg *Config )
func (*RuneBuffer ).SetConfig (cfg *Config )
func (*Terminal ).SetConfig (c *Config ) error
/* 2+ unexporteds ... */ /* 2+ unexporteds: */
func newOpHistory (cfg *Config ) (o *opHistory )
func newOpSearch (w io .Writer , buf *RuneBuffer , history *opHistory , cfg *Config , width int ) *opSearch
type DumpListener (struct)
Fields (only one, which is unexported )
/* one unexported ... */ /* one unexported: */
f func(line []rune , pos int , key rune ) (newLine []rune , newPos int , ok bool )
Methods (only one, which is exported )
(*T) OnChange (line []rune , pos int , key rune ) (newLine []rune , newPos int , ok bool )
Implements (at least one exported )
*T : Listener
type Instance (struct)
Fields (total 3, all are exported )
Config *Config
Operation *Operation
Terminal *Terminal
Methods (total 25, all are exported )
(*T) Clean ()
(*T) Close () error
we must make sure that call Close() before process exit.
(*T) GenPasswordConfig () *Config
(*T) HistoryDisable ()
HistoryDisable the save of the commands into the history
(*T) HistoryEnable ()
HistoryEnable the save of the commands into the history (default on)
(*T) IsVimMode () bool
(*T) Line () *Result
(*T) ReadPassword (prompt string ) ([]byte , error )
(*T) ReadPasswordEx (prompt string , l Listener ) ([]byte , error )
(*T) ReadPasswordWithConfig (cfg *Config ) ([]byte , error )
we can generate a config by `i.GenPasswordConfig()`
(*T) ReadSlice () ([]byte , error )
same as readline
(*T) Readline () (string , error )
err is one of (nil, io.EOF, readline.ErrInterrupt)
(*T) ReadlineWithDefault (what string ) (string , error )
(*T) Refresh ()
(*T) ResetHistory ()
(*T) SaveHistory (content string ) error
(*T) SetConfig (cfg *Config ) *Config
(*T) SetHistoryPath (p string )
change history persistence in runtime
(*T) SetMaskRune (r rune )
(*T) SetPrompt (s string )
(*T) SetVimMode (on bool )
switch VimMode in runtime
(*T) Stderr () io .Writer
readline will refresh automatic when write through Stdout()
(*T) Stdout () io .Writer
readline will refresh automatic when write through Stdout()
(*T) Write (b []byte ) (int , error )
(*T) WriteStdin (val []byte ) (int , error )
WriteStdin prefill the next Stdin fetch
Next time you call ReadLine() this value will be writen before the user input
ie :
i := readline.New()
i.WriteStdin([]byte("test"))
_, _= i.Readline()
gives
> test[cursor]
Implements (at least 3, all are exported )
*T : io.Closer
*T : io.WriteCloser
*T : io.Writer
As Outputs Of (at least 4, in which 3 are exported )
func HandleConn (cfg Config , conn net .Conn ) (*Instance , error )
func New (prompt string ) (*Instance , error )
func NewEx (cfg *Config ) (*Instance , error )
/* at least one unexported ... */ /* at least one unexported: */
func getInstance () *Instance
As Types Of (only one, which is unexported )
/* one unexported ... */ /* one unexported: */
var std *Instance
type Listener (interface)
Methods (only one, which is exported )
( T) OnChange (line []rune , pos int , key rune ) (newLine []rune , newPos int , ok bool )
Implemented By (at least one exported )
*DumpListener
As Outputs Of (at least one exported )
func FuncListener (f func(line []rune , pos int , key rune ) (newLine []rune , newPos int , ok bool )) Listener
As Inputs Of (at least 2, both are exported )
func (*Instance ).ReadPasswordEx (prompt string , l Listener ) ([]byte , error )
func (*Operation ).PasswordEx (prompt string , l Listener ) ([]byte , error )
type Operation (struct)
Fields (total 29, none are exported )
/* 29 unexporteds ... */ /* 29 unexporteds: */
buf *RuneBuffer
cfg *Config
errchan chan error
history *opHistory
m sync .Mutex
opCompleter *opCompleter
opCompleter .candidate [][]rune
opCompleter .candidateChoise int
opCompleter .candidateColNum int
opCompleter .candidateOff int
opCompleter .candidateSource []rune
opCompleter .inCompleteMode bool
opCompleter .inSelectMode bool
opPassword *opPassword
opPassword .backupCfg *Config
opPassword .o *Operation
opSearch *opSearch
opSearch .data []rune
opSearch .dir int
opSearch .inMode bool
opSearch .markEnd int
opSearch .markStart int
opSearch .source *list .Element
opSearch .state int
opVim *opVim
opVim .vimMode int
outchan chan []rune
t *Terminal
w io .Writer
Methods (total 56, in which 47 are exported )
(*T) Clean ()
(*T) Close ()
( T) CompleteRefresh ()
( T) EnterCompleteMode (offset int , candidate [][]rune )
( T) EnterCompleteSelectMode ()
( T) EnterPasswordMode (cfg *Config ) (err error )
( T) EnterVimInsertMode ()
( T) ExitCompleteMode (revent bool )
( T) ExitCompleteSelectMode ()
( T) ExitPasswordMode ()
( T) ExitSearchMode (revert bool )
( T) ExitVimInsertMode ()
( T) ExitVimMode ()
(*T) GenPasswordConfig () *Config
(*T) GetConfig () *Config
( T) HandleCompleteSelect (r rune ) bool
( T) HandleVim (r rune , readNext func() rune ) rune
( T) HandleVimNormal (r rune , readNext func() rune ) (t rune )
( T) IsEnableVimMode () bool
( T) IsInCompleteMode () bool
( T) IsInCompleteSelectMode () bool
(*T) IsNormalMode () bool
( T) IsSearchMode () bool
( T) OnComplete () bool
(*T) Password (prompt string ) ([]byte , error )
( T) PasswordConfig () *Config
(*T) PasswordEx (prompt string , l Listener ) ([]byte , error )
(*T) PasswordWithConfig (cfg *Config ) ([]byte , error )
(*T) Refresh ()
(*T) ResetHistory ()
(*T) Runes () ([]rune , error )
(*T) SaveHistory (content string ) error
if err is not nil, it just mean it fail to write to file
other things goes fine.
( T) SearchBackspace ()
( T) SearchChar (r rune )
( T) SearchMode (dir int ) bool
( T) SearchRefresh (x int )
(*T) SetBuffer (what string )
(*T) SetConfig (cfg *Config ) (*Config , error )
(*T) SetHistoryPath (path string )
(*T) SetMaskRune (r rune )
(*T) SetPrompt (s string )
(*T) SetTitle (t string )
( T) SetVimMode (on bool )
(*T) Slice () ([]byte , error )
(*T) Stderr () io .Writer
(*T) Stdout () io .Writer
(*T) String () (string , error )
/* 9 unexporteds ... */ /* 9 unexporteds: */
( T) aggCandidate (candidate [][]rune ) int
( T) doSelect ()
( T) findHistoryBy (isNewSearch bool ) (int , *list .Element )
( T) getMatrixSize () int
( T) handleVimNormalEnterInsert (r rune , readNext func() rune ) (t rune , handled bool )
( T) handleVimNormalMovement (r rune , readNext func() rune ) (t rune , handled bool )
(*T) ioloop ()
( T) nextCandidate (i int )
( T) search (isChange bool ) bool
As Outputs Of (at least 2, both are exported )
func NewOperation (t *Terminal , cfg *Config ) *Operation
func (*Terminal ).Readline () *Operation
As Inputs Of (at least 3, none are exported )
/* 3+ unexporteds ... */ /* 3+ unexporteds: */
func newOpCompleter (w io .Writer , op *Operation , width int ) *opCompleter
func newOpPassword (o *Operation ) *opPassword
func newVimMode (op *Operation ) *opVim
type PrefixCompleter (struct)
Fields (total 4, all are exported )
Callback DynamicCompleteFunc
Children []PrefixCompleterInterface
Dynamic bool
Name []rune
Methods (total 8, all are exported )
(*T) Do (line []rune , pos int ) (newLine [][]rune , offset int )
(*T) GetChildren () []PrefixCompleterInterface
(*T) GetDynamicNames (line []rune ) [][]rune
(*T) GetName () []rune
(*T) IsDynamic () bool
(*T) Print (prefix string , level int , buf *bytes .Buffer )
(*T) SetChildren (children []PrefixCompleterInterface )
(*T) Tree (prefix string ) string
Implements (at least 3, all are exported )
*T : AutoCompleter
*T : DynamicPrefixCompleterInterface
*T : PrefixCompleterInterface
As Outputs Of (at least 3, all are exported )
func NewPrefixCompleter (pc ...PrefixCompleterInterface ) *PrefixCompleter
func PcItem (name string , pc ...PrefixCompleterInterface ) *PrefixCompleter
func PcItemDynamic (callback DynamicCompleteFunc , pc ...PrefixCompleterInterface ) *PrefixCompleter
type PrefixCompleterInterface (interface)
Methods (total 5, all are exported )
( T) Do (line []rune , pos int ) (newLine [][]rune , length int )
( T) GetChildren () []PrefixCompleterInterface
( T) GetName () []rune
( T) Print (prefix string , level int , buf *bytes .Buffer )
( T) SetChildren (children []PrefixCompleterInterface )
Implemented By (at least 2, both are exported )
DynamicPrefixCompleterInterface (interface)
*PrefixCompleter
Implements (at least one exported )
T : AutoCompleter
As Outputs Of (at least 3, all are exported )
func DynamicPrefixCompleterInterface .GetChildren () []PrefixCompleterInterface
func (*PrefixCompleter ).GetChildren () []PrefixCompleterInterface
func PrefixCompleterInterface.GetChildren () []PrefixCompleterInterface
As Inputs Of (at least 9, in which 8 are exported )
func Do (p PrefixCompleterInterface , line []rune , pos int ) (newLine [][]rune , offset int )
func NewPrefixCompleter (pc ...PrefixCompleterInterface ) *PrefixCompleter
func PcItem (name string , pc ...PrefixCompleterInterface ) *PrefixCompleter
func PcItemDynamic (callback DynamicCompleteFunc , pc ...PrefixCompleterInterface ) *PrefixCompleter
func Print (p PrefixCompleterInterface , prefix string , level int , buf *bytes .Buffer )
func DynamicPrefixCompleterInterface .SetChildren (children []PrefixCompleterInterface )
func (*PrefixCompleter ).SetChildren (children []PrefixCompleterInterface )
func PrefixCompleterInterface.SetChildren (children []PrefixCompleterInterface )
/* at least one unexported ... */ /* at least one unexported: */
func doInternal (p PrefixCompleterInterface , line []rune , pos int , origLine []rune ) (newLine [][]rune , offset int )
type RuneBuffer (struct)
Fields (total 14, in which 1 are exported )
Mutex sync .Mutex
/* 13 unexporteds ... */ /* 13 unexporteds: */
bck *runeBufferBck
buf []rune
cfg *Config
hadClean bool
idx int
interactive bool
lastKill []rune
Mutex .sema uint32
Mutex .state int32
offset string
prompt []rune
w io .Writer
width int
Methods (total 60, in which 46 are exported )
(*T) BackEscapeWord ()
(*T) Backspace ()
(*T) Backup ()
(*T) Clean ()
(*T) CurrentWidth (x int ) int
(*T) CursorLineCount () int
(*T) Delete () (success bool )
(*T) DeleteWord ()
(*T) Erase ()
(*T) IdxLine (width int ) int
(*T) IsCursorInEnd () bool
(*T) Kill ()
(*T) KillFront ()
(*T) Len () int
(*T) LineCount (width int ) int
(*T) Lock ()
Lock locks m.
If the lock is already in use, the calling goroutine
blocks until the mutex is available.
(*T) MoveBackward ()
(*T) MoveForward ()
(*T) MoveTo (ch rune , prevChar, reverse bool ) (success bool )
(*T) MoveToEndWord ()
(*T) MoveToLineEnd ()
(*T) MoveToLineStart ()
(*T) MoveToNextWord ()
(*T) MoveToPrevWord () (success bool )
(*T) OnWidthChange (newWidth int )
(*T) Pos () int
(*T) PromptLen () int
(*T) Refresh (f func())
(*T) Replace (ch rune )
(*T) Reset () []rune
(*T) Restore ()
(*T) RuneSlice (i int ) []rune
(*T) Runes () []rune
(*T) Set (buf []rune )
(*T) SetConfig (cfg *Config )
(*T) SetMask (m rune )
(*T) SetOffset (offset string )
(*T) SetPrompt (prompt string )
(*T) SetStyle (start, end int , style string )
(*T) SetWithIdx (idx int , buf []rune )
(*T) Transpose ()
(*T) Unlock ()
Unlock unlocks m.
It is a run-time error if m is not locked on entry to Unlock.
A locked Mutex is not associated with a particular goroutine.
It is allowed for one goroutine to lock a Mutex and then
arrange for another goroutine to unlock it.
(*T) WriteRune (s rune )
(*T) WriteRunes (s []rune )
(*T) WriteString (s string )
(*T) Yank ()
/* 14 unexporteds ... */ /* 14 unexporteds: */
(*T) calWidth (m int ) int
(*T) clean ()
(*T) cleanOutput (w io .Writer , idxLine int )
(*T) cleanWithIdxLine (idxLine int )
(*T) getBackspaceSequence () []byte
(*T) getSplitByLine (rs []rune ) []string
(*T) idxLine (width int ) int
(*T) isInLineEdge () bool
(*T) lockSlow ()
(*T) output () []byte
(*T) print ()
(*T) promptLen () int
(*T) pushKill (text []rune )
(*T) unlockSlow (new int32 )
Implements (at least one exported )
*T : sync.Locker
As Outputs Of (at least one exported )
func NewRuneBuffer (w io .Writer , prompt string , cfg *Config , width int ) *RuneBuffer
As Inputs Of (at least one unexported )
/* at least one unexported ... */ /* at least one unexported: */
func newOpSearch (w io .Writer , buf *RuneBuffer , history *opHistory , cfg *Config , width int ) *opSearch
type Runes (struct)
Methods (total 18, all are exported )
( T) Aggregate (candicate [][]rune ) (same []rune , size int )
( T) Backspace (r []rune ) []byte
( T) ColorFilter (r []rune ) []rune
( T) Copy (r []rune ) []rune
( T) Equal (a, b []rune ) bool
( T) EqualFold (a, b []rune ) bool
( T) EqualRune (a, b rune , fold bool ) bool
( T) EqualRuneFold (a, b rune ) bool
( T) HasPrefix (r, prefix []rune ) bool
( T) HasPrefixFold (r, prefix []rune ) bool
( T) Index (r rune , rs []rune ) int
( T) IndexAll (r, sub []rune ) int
Search in runes from front to end
( T) IndexAllBck (r, sub []rune ) int
Search in runes from end to front
( T) IndexAllBckEx (r, sub []rune , fold bool ) int
( T) IndexAllEx (r, sub []rune , fold bool ) int
( T) TrimSpaceLeft (in []rune ) []rune
( T) Width (r rune ) int
( T) WidthAll (r []rune ) (length int )
As Types Of (only one, which is unexported )
/* one unexported ... */ /* one unexported: */
var runes
type SegmentComplete (struct)
Fields (only one, which is exported )
SegmentCompleter SegmentCompleter
Methods (total 2, both are exported )
(*T) Do (line []rune , pos int ) (newLine [][]rune , offset int )
( T) DoSegment ([][]rune , int ) [][]rune
a
|- a1
|--- a11
|- a2
b
input:
DoTree([], 0) [a, b]
DoTree([a], 1) [a]
DoTree([a, ], 0) [a1, a2]
DoTree([a, a], 1) [a1, a2]
DoTree([a, a1], 2) [a1]
DoTree([a, a1, ], 0) [a11]
DoTree([a, a1, a], 1) [a11]
Implements (at least 2, both are exported )
*T : AutoCompleter
T : SegmentCompleter
As Outputs Of (at least one exported )
func SegmentAutoComplete (completer SegmentCompleter ) *SegmentComplete
type SegmentCompleter (interface)
Methods (only one, which is exported )
( T) DoSegment ([][]rune , int ) [][]rune
a
|- a1
|--- a11
|- a2
b
input:
DoTree([], 0) [a, b]
DoTree([a], 1) [a]
DoTree([a, ], 0) [a1, a2]
DoTree([a, a], 1) [a1, a2]
DoTree([a, a1], 2) [a1]
DoTree([a, a1, ], 0) [a11]
DoTree([a, a1, a], 1) [a11]
Implemented By (at least 2, in which 1 are exported )
SegmentComplete
/* at least one unexported ... */ /* at least one unexported: */
*dumpSegmentCompleter
As Inputs Of (at least one exported )
func SegmentAutoComplete (completer SegmentCompleter ) *SegmentComplete
/* 15 unexporteds ... */ /* 15 unexporteds: */ type opHistory (struct)
Fields (total 7, none are exported )
/* 7 unexporteds ... */ /* 7 unexporteds: */
cfg *Config
current *list .Element
enable bool
fd *os .File
fdLock sync .Mutex
history *list .List
historyVer int64
Methods (total 21, in which 16 are exported )
(*T) Close ()
(*T) Compact ()
(*T) Disable ()
Disable the current history
(*T) Enable ()
Enable the current history
(*T) FindBck (isNewSearch bool , rs []rune , start int ) (int , *list .Element )
(*T) FindFwd (isNewSearch bool , rs []rune , start int ) (int , *list .Element )
(*T) Init ()
(*T) IsHistoryClosed () bool
(*T) New (current []rune ) (err error )
save history
(*T) Next () ([]rune , bool )
(*T) Prev () []rune
(*T) Push (s []rune )
(*T) Reset ()
(*T) Revert ()
(*T) Rewrite ()
(*T) Update (s []rune , commit bool ) (err error )
/* 5 unexporteds ... */ /* 5 unexporteds: */
(*T) debug ()
(*T) historyUpdatePath (path string )
only called by newOpHistory
(*T) initHistory ()
(*T) rewriteLocked ()
(*T) showItem (obj interface{}) []rune
As Outputs Of (at least one unexported )
/* at least one unexported ... */ /* at least one unexported: */
func newOpHistory (cfg *Config ) (o *opHistory )
As Inputs Of (at least one unexported )
/* at least one unexported ... */ /* at least one unexported: */
func newOpSearch (w io .Writer , buf *RuneBuffer , history *opHistory , cfg *Config , width int ) *opSearch
The pages are generated with Golds v0.3.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .