package readline
import "github.com/chzyer/readline"
Readline is a pure go implementation for GNU-Readline kind library.
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) }
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Putting a terminal into raw mode is the most common requirement:
oldState, err := terminal.MakeRaw(0) if err != nil { panic(err) } defer terminal.Restore(0, oldState)
Index ¶
- Constants
- Variables
- func AddHistory(content string) error
- func CaptureExitSignal(f func())
- func ClearScreen(_ io.Writer) error
- func Debug(o ...interface{})
- func DefaultIsTerminal() bool
- func DefaultOnWidthChanged(func())
- func DialRemote(n, addr string) error
- func Do(p PrefixCompleterInterface, line []rune, pos int) (newLine [][]rune, offset int)
- func GetConsoleCursorInfo() (*_CONSOLE_CURSOR_INFO, error)
- func GetConsoleScreenBufferInfo() (*_CONSOLE_SCREEN_BUFFER_INFO, error)
- func GetInt(s []string, def int) int
- func GetScreenWidth() int
- func GetSize(fd int) (width, height int, err error)
- func GetStdin() int
- func IsPrintable(key rune) bool
- func IsTerminal(fd int) bool
- func IsWordBreak(i rune) bool
- func Line(prompt string) (string, error)
- func LineCount(screenWidth, w int) int
- func ListenRemote(n, addr string, cfg *Config, h func(*Instance), onListen ...func(net.Listener) error) error
- func NewFillableStdin(stdin io.Reader) (io.ReadCloser, io.Writer)
- func Password(prompt string) ([]byte, error)
- func Print(p PrefixCompleterInterface, prefix string, level int, buf *bytes.Buffer)
- func ReadPassword(fd int) ([]byte, error)
- func Restore(fd int, state *State) error
- func RetSegment(segments [][]rune, cands [][]rune, idx int) ([][]rune, int)
- func SetAutoComplete(completer AutoCompleter)
- func SetConsoleCursorPosition(c *_COORD) error
- func SetHistoryPath(fp string)
- func SplitByLine(start, screenWidth int, rs []rune) []string
- func SplitSegment(line []rune, pos int) ([][]rune, int)
- func SuspendMe()
- func WaitForResume() chan struct{}
- type ANSIWriter
- func NewANSIWriter(w io.Writer) *ANSIWriter
- func (a *ANSIWriter) Close() error
- func (a *ANSIWriter) Write(b []byte) (int, error)
- type ANSIWriterCtx
- type AutoCompleter
- type CallFunc
- type CancelableStdin
- func NewCancelableStdin(r io.Reader) *CancelableStdin
- func (c *CancelableStdin) Close() error
- func (c *CancelableStdin) Read(b []byte) (n int, err error)
- type Config
- func (c Config) Clone() *Config
- func (c *Config) Init() error
- func (c *Config) SetListener(f func(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool))
- func (c *Config) SetPainter(p Painter)
- type DumpListener
- type DynamicCompleteFunc
- type DynamicPrefixCompleterInterface
- type FillableStdin
- type Instance
- func HandleConn(cfg Config, conn net.Conn) (*Instance, error)
- func New(prompt string) (*Instance, error)
- func NewEx(cfg *Config) (*Instance, error)
- func (i *Instance) CaptureExitSignal()
- func (i *Instance) Clean()
- func (i *Instance) Close() error
- func (i *Instance) GenPasswordConfig() *Config
- func (i *Instance) HistoryDisable()
- func (i *Instance) HistoryEnable()
- func (i *Instance) IsVimMode() bool
- func (i *Instance) Line() *Result
- 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) ReadlineWithDefault(what string) (string, error)
- func (i *Instance) Refresh()
- func (i *Instance) ResetHistory()
- func (i *Instance) SaveHistory(content string) error
- 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
- func (i *Instance) Write(b []byte) (int, error)
- func (i *Instance) WriteStdin(val []byte) (int, error)
- type InterruptError
- type Kernel
- type Listener
- type Message
- func NewMessage(t MsgType, data []byte) *Message
- func ReadMessage(r io.Reader) (*Message, error)
- func (m *Message) WriteTo(w io.Writer) (int, error)
- type MsgType
- type Operation
- func NewOperation(t *Terminal, cfg *Config) *Operation
- func (o *Operation) Clean()
- func (o *Operation) Close()
- 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) GenPasswordConfig() *Config
- func (o *Operation) GetConfig() *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) IsEnableVimMode() bool
- func (o Operation) IsInCompleteMode() bool
- func (o Operation) IsInCompleteSelectMode() bool
- func (o *Operation) IsNormalMode() bool
- func (o Operation) IsSearchMode() bool
- func (o Operation) OnComplete() bool
- 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) Refresh()
- func (o *Operation) ResetHistory()
- func (o *Operation) Runes() ([]rune, error)
- func (o *Operation) SaveHistory(content string) error
- func (o Operation) SearchBackspace()
- func (o Operation) SearchChar(r rune)
- func (o Operation) SearchMode(dir int) bool
- func (o Operation) SearchRefresh(x int)
- func (o *Operation) SetBuffer(what string)
- 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)
- type Painter
- type PrefixCompleter
- func NewPrefixCompleter(pc ...PrefixCompleterInterface) *PrefixCompleter
- func PcItem(name string, pc ...PrefixCompleterInterface) *PrefixCompleter
- func PcItemDynamic(callback DynamicCompleteFunc, pc ...PrefixCompleterInterface) *PrefixCompleter
- func (p *PrefixCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int)
- func (p *PrefixCompleter) GetChildren() []PrefixCompleterInterface
- func (p *PrefixCompleter) GetDynamicNames(line []rune) [][]rune
- func (p *PrefixCompleter) GetName() []rune
- func (p *PrefixCompleter) IsDynamic() bool
- func (p *PrefixCompleter) Print(prefix string, level int, buf *bytes.Buffer)
- func (p *PrefixCompleter) SetChildren(children []PrefixCompleterInterface)
- func (p *PrefixCompleter) Tree(prefix string) string
- type PrefixCompleterInterface
- type RawMode
- type RawReader
- func NewRawReader() *RawReader
- func (r *RawReader) Close() error
- func (r *RawReader) Read(buf []byte) (int, error)
- type RemoteCli
- func NewRemoteCli(conn net.Conn) (*RemoteCli, error)
- func (r *RemoteCli) Close()
- func (r *RemoteCli) MarkIsTerminal(is bool)
- func (r *RemoteCli) Serve() error
- func (r *RemoteCli) ServeBy(source io.Reader) error
- func (r *RemoteCli) Write(b []byte) (int, error)
- type RemoteSvr
- func NewRemoteSvr(conn net.Conn) (*RemoteSvr, error)
- func (r *RemoteSvr) Close() error
- func (r *RemoteSvr) EnterRawMode() error
- func (r *RemoteSvr) ExitRawMode() error
- func (r *RemoteSvr) GetWidth() int
- func (r *RemoteSvr) GotIsTerminal(data []byte)
- func (r *RemoteSvr) GotReportWidth(data []byte)
- func (r *RemoteSvr) HandleConfig(cfg *Config)
- func (r *RemoteSvr) IsTerminal() bool
- func (r *RemoteSvr) Read(b []byte) (int, error)
- func (r *RemoteSvr) Write(b []byte) (int, error)
- type Result
- type RuneBuffer
- func NewRuneBuffer(w io.Writer, prompt string, cfg *Config, width int) *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(width int) int
- func (r *RuneBuffer) IsCursorInEnd() bool
- func (r *RuneBuffer) Kill()
- func (r *RuneBuffer) KillFront()
- func (r *RuneBuffer) Len() int
- func (r *RuneBuffer) LineCount(width int) int
- func (r *RuneBuffer) MoveBackward()
- func (r *RuneBuffer) MoveForward()
- func (r *RuneBuffer) MoveTo(ch rune, prevChar, reverse bool) (success bool)
- func (r *RuneBuffer) MoveToEndWord()
- func (r *RuneBuffer) MoveToLineEnd()
- func (r *RuneBuffer) MoveToLineStart()
- func (r *RuneBuffer) MoveToNextWord()
- func (r *RuneBuffer) MoveToPrevWord() (success bool)
- func (r *RuneBuffer) OnWidthChange(newWidth int)
- func (r *RuneBuffer) Pos() int
- func (r *RuneBuffer) PromptLen() int
- func (r *RuneBuffer) Refresh(f func())
- func (r *RuneBuffer) Replace(ch rune)
- 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) SetConfig(cfg *Config)
- func (r *RuneBuffer) SetMask(m rune)
- func (r *RuneBuffer) SetOffset(offset string)
- 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)
- func (r *RuneBuffer) Yank()
- type Runes
- func (Runes) Aggregate(candicate [][]rune) (same []rune, size int)
- func (Runes) Backspace(r []rune) []byte
- func (Runes) ColorFilter(r []rune) []rune
- func (Runes) Copy(r []rune) []rune
- func (Runes) Equal(a, b []rune) bool
- func (r Runes) EqualFold(a, b []rune) bool
- func (Runes) EqualRune(a, b rune, fold bool) bool
- func (r Runes) EqualRuneFold(a, b rune) bool
- func (Runes) HasPrefix(r, prefix []rune) bool
- func (Runes) HasPrefixFold(r, prefix []rune) bool
- func (Runes) Index(r rune, rs []rune) int
- func (rs Runes) IndexAll(r, sub []rune) int
- func (rs Runes) IndexAllBck(r, sub []rune) int
- func (rs Runes) IndexAllBckEx(r, sub []rune, fold bool) int
- func (rs Runes) IndexAllEx(r, sub []rune, fold bool) int
- func (Runes) TrimSpaceLeft(in []rune) []rune
- func (Runes) Width(r rune) int
- func (Runes) WidthAll(r []rune) (length int)
- type SegmentComplete
- func SegmentAutoComplete(completer SegmentCompleter) *SegmentComplete
- func (c *SegmentComplete) Do(line []rune, pos int) (newLine [][]rune, offset int)
- type SegmentCompleter
- type State
- type TabCompleter
- type Terminal
- func NewTerminal(cfg *Config) (*Terminal, error)
- func (t *Terminal) Bell()
- func (t *Terminal) Close() error
- func (t *Terminal) EnterRawMode() (err error)
- func (t *Terminal) ExitRawMode() (err error)
- func (t *Terminal) GetConfig() *Config
- func (t *Terminal) GetOffset(f func(offset string))
- 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) SleepToResume()
- func (t *Terminal) Write(b []byte) (int, error)
- func (t *Terminal) WriteStdin(b []byte) (int, error)
Constants ¶
const ( COLOR_FBLUE = 0x0001 COLOR_FGREEN = 0x0002 COLOR_FRED = 0x0004 COLOR_FINTENSITY = 0x0008 COLOR_BBLUE = 0x0010 COLOR_BGREEN = 0x0020 COLOR_BRED = 0x0040 COLOR_BINTENSITY = 0x0080 COMMON_LVB_UNDERSCORE = 0x8000 COMMON_LVB_BOLD = 0x0007 )
const ( VK_CANCEL = 0x03 VK_BACK = 0x08 VK_TAB = 0x09 VK_RETURN = 0x0D VK_SHIFT = 0x10 VK_CONTROL = 0x11 VK_MENU = 0x12 VK_ESCAPE = 0x1B VK_LEFT = 0x25 VK_UP = 0x26 VK_RIGHT = 0x27 VK_DOWN = 0x28 VK_DELETE = 0x2E VK_LSHIFT = 0xA0 VK_RSHIFT = 0xA1 VK_LCONTROL = 0xA2 VK_RCONTROL = 0xA3 )
const ( T_DATA = MsgType(iota) T_WIDTH T_WIDTH_REPORT T_ISTTY_REPORT T_RAW T_ERAW // exit raw T_EOF )
const ( S_STATE_FOUND = iota S_STATE_FAILING )
const ( S_DIR_BCK = iota S_DIR_FWD )
const ( CharLineStart = 1 CharBackward = 2 CharInterrupt = 3 CharDelete = 4 CharLineEnd = 5 CharForward = 6 CharBell = 7 CharCtrlH = 8 CharTab = 9 CharCtrlJ = 10 CharKill = 11 CharCtrlL = 12 CharEnter = 13 CharNext = 14 CharPrev = 16 CharBckSearch = 18 CharFwdSearch = 19 CharTranspose = 20 CharCtrlU = 21 CharCtrlW = 23 CharCtrlY = 25 CharCtrlZ = 26 CharEsc = 27 CharO = 79 CharEscapeEx = 91 CharBackspace = 127 )
const ( VIM_NORMAL = iota VIM_INSERT VIM_VISUAL )
const ( EVENT_KEY = 0x0001 EVENT_MOUSE = 0x0002 EVENT_WINDOW_BUFFER_SIZE = 0x0004 EVENT_MENU = 0x0008 EVENT_FOCUS = 0x0010 )
Variables ¶
var ( Stdin io.ReadCloser = os.Stdin Stdout io.WriteCloser = os.Stdout Stderr io.WriteCloser = os.Stderr )
var ColorTableBg = []word{
0,
COLOR_BRED,
COLOR_BGREEN,
COLOR_BRED | COLOR_BGREEN,
COLOR_BBLUE,
COLOR_BRED | COLOR_BBLUE,
COLOR_BGREEN | COLOR_BBLUE,
COLOR_BRED | COLOR_BBLUE | COLOR_BGREEN,
}
var ColorTableFg = []word{
0,
COLOR_FRED,
COLOR_FGREEN,
COLOR_FRED | COLOR_FGREEN,
COLOR_FBLUE,
COLOR_FRED | COLOR_FBLUE,
COLOR_FGREEN | COLOR_FBLUE,
COLOR_FRED | COLOR_FBLUE | COLOR_FGREEN,
}
var TabWidth = 4
Functions ¶
func AddHistory ¶
add history to global instance manually raise error only if `SetHistoryPath` is set with a non-empty path
func CaptureExitSignal ¶
func CaptureExitSignal(f func())
func ClearScreen ¶
ClearScreen clears the console screen
func Debug ¶
func Debug(o ...interface{})
append log info to another file
func DefaultIsTerminal ¶
func DefaultIsTerminal() bool
func DefaultOnWidthChanged ¶
func DefaultOnWidthChanged(func())
func DialRemote ¶
func Do ¶
func Do(p PrefixCompleterInterface, line []rune, pos int) (newLine [][]rune, offset int)
func GetConsoleCursorInfo ¶
func GetConsoleCursorInfo() (*_CONSOLE_CURSOR_INFO, error)
func GetConsoleScreenBufferInfo ¶
func GetConsoleScreenBufferInfo() (*_CONSOLE_SCREEN_BUFFER_INFO, error)
func GetInt ¶
func GetScreenWidth ¶
func GetScreenWidth() int
get width of the terminal
func GetSize ¶
GetSize returns the dimensions of the given terminal.
func GetStdin ¶
func GetStdin() int
func IsPrintable ¶
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
func IsWordBreak ¶
func Line ¶
readline with global configs
func LineCount ¶
calculate how many lines for N character
func ListenRemote ¶
func ListenRemote(n, addr string, cfg *Config, h func(*Instance), onListen ...func(net.Listener) error) error
func NewFillableStdin ¶
NewFillableStdin gives you FillableStdin
func Password ¶
func Print ¶
func Print(p PrefixCompleterInterface, prefix string, level int, buf *bytes.Buffer)
func ReadPassword ¶
ReadPassword reads a line of input from a terminal without local echo. This is commonly used for inputting passwords and other sensitive data. The slice returned does not include the \n.
func Restore ¶
func RetSegment ¶
func SetAutoComplete ¶
func SetAutoComplete(completer AutoCompleter)
set auto completer to global instance
func SetConsoleCursorPosition ¶
func SetConsoleCursorPosition(c *_COORD) error
func SetHistoryPath ¶
func SetHistoryPath(fp string)
let readline load history from filepath and try to persist history into disk set fp to "" to prevent readline persisting history to disk so the `AddHistory` will return nil error forever.
func SplitByLine ¶
func SplitSegment ¶
func SuspendMe ¶
func SuspendMe()
func WaitForResume ¶
func WaitForResume() chan struct{}
WaitForResume need to call before current process got suspend. It will run a ticker until a long duration is occurs, which means this process is resumed.
Types ¶
type ANSIWriter ¶
func NewANSIWriter ¶
func NewANSIWriter(w io.Writer) *ANSIWriter
func (*ANSIWriter) Close ¶
func (a *ANSIWriter) Close() error
func (*ANSIWriter) Write ¶
func (a *ANSIWriter) Write(b []byte) (int, error)
type ANSIWriterCtx ¶
type ANSIWriterCtx struct {
// contains filtered or unexported fields
}
func NewANSIWriterCtx ¶
func NewANSIWriterCtx(target io.Writer) *ANSIWriterCtx
func (*ANSIWriterCtx) Flush ¶
func (a *ANSIWriterCtx) Flush()
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: // [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 Do(line []rune, pos int) (newLine [][]rune, length int) }
func SegmentFunc ¶
func SegmentFunc(f func([][]rune, int) [][]rune) AutoCompleter
type CallFunc ¶
type CancelableStdin ¶
type CancelableStdin struct {
// contains filtered or unexported fields
}
func NewCancelableStdin ¶
func NewCancelableStdin(r io.Reader) *CancelableStdin
func (*CancelableStdin) Close ¶
func (c *CancelableStdin) Close() error
func (*CancelableStdin) Read ¶
func (c *CancelableStdin) Read(b []byte) (n int, err error)
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 DisableAutoSaveHistory bool // enable case-insensitive history searching HistorySearchFold bool // 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 Painter Painter // If VimMode is true, readline will in vim.insert mode by default VimMode bool InterruptPrompt string EOFPrompt string FuncGetWidth func() int Stdin io.ReadCloser StdinWriter io.Writer Stdout io.Writer Stderr io.Writer EnableMask bool MaskRune rune // erase the editing line after user submited it // it use in IM usually. UniqueEditLine 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 FuncFilterInputRune func(rune) (rune, bool) // force use interactive even stdout is not a tty FuncIsTerminal func() bool FuncMakeRaw func() error FuncExitRaw func() error FuncOnWidthChanged func(func()) ForceUseInteractive bool // contains filtered or unexported fields }
func (Config) Clone ¶
func (*Config) Init ¶
func (*Config) SetListener ¶
func (c *Config) SetListener(f func(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool))
func (*Config) SetPainter ¶
type DumpListener ¶
type DumpListener struct {
// contains filtered or unexported fields
}
func (*DumpListener) OnChange ¶
func (d *DumpListener) OnChange(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool)
type DynamicCompleteFunc ¶
Caller type for dynamic completion
type DynamicPrefixCompleterInterface ¶
type DynamicPrefixCompleterInterface interface { PrefixCompleterInterface IsDynamic() bool GetDynamicNames(line []rune) [][]rune }
type FillableStdin ¶
FillableStdin is a stdin reader which can prepend some data before reading into the real stdin
func (*FillableStdin) Close ¶
func (s *FillableStdin) Close() error
func (*FillableStdin) Read ¶
func (s *FillableStdin) Read(p []byte) (n int, err error)
Read will read from the local buffer and if no data, read from stdin
type Instance ¶
func HandleConn ¶
func New ¶
func NewEx ¶
func (*Instance) CaptureExitSignal ¶
func (i *Instance) CaptureExitSignal()
call CaptureExitSignal when you want readline exit gracefully.
func (*Instance) Clean ¶
func (i *Instance) Clean()
func (*Instance) Close ¶
we must make sure that call Close() before process exit. if there has a pending reading operation, that reading will be interrupted. so you can capture the signal and call Instance.Close(), it's thread-safe.
func (*Instance) GenPasswordConfig ¶
func (*Instance) HistoryDisable ¶
func (i *Instance) HistoryDisable()
HistoryDisable the save of the commands into the history
func (*Instance) HistoryEnable ¶
func (i *Instance) HistoryEnable()
HistoryEnable the save of the commands into the history (default on)
func (*Instance) IsVimMode ¶
func (*Instance) Line ¶
func (*Instance) ReadPassword ¶
func (*Instance) ReadPasswordEx ¶
func (*Instance) ReadPasswordWithConfig ¶
we can generate a config by `i.GenPasswordConfig()`
func (*Instance) ReadSlice ¶
same as readline
func (*Instance) Readline ¶
err is one of (nil, io.EOF, readline.ErrInterrupt)
func (*Instance) ReadlineWithDefault ¶
func (*Instance) Refresh ¶
func (i *Instance) Refresh()
func (*Instance) ResetHistory ¶
func (i *Instance) ResetHistory()
func (*Instance) SaveHistory ¶
func (*Instance) SetConfig ¶
func (*Instance) SetHistoryPath ¶
change history persistence in runtime
func (*Instance) SetMaskRune ¶
func (*Instance) SetPrompt ¶
func (*Instance) SetVimMode ¶
switch VimMode in runtime
func (*Instance) Stderr ¶
readline will refresh automatic when write through Stdout()
func (*Instance) Stdout ¶
readline will refresh automatic when write through Stdout()
func (*Instance) Write ¶
func (*Instance) WriteStdin ¶
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]
type InterruptError ¶
type InterruptError struct { Line []rune }
func (*InterruptError) Error ¶
func (*InterruptError) Error() string
type Kernel ¶
type Kernel struct { SetConsoleCursorPosition, SetConsoleTextAttribute, FillConsoleOutputCharacterW, FillConsoleOutputAttribute, ReadConsoleInputW, GetConsoleScreenBufferInfo, GetConsoleCursorInfo, GetStdHandle CallFunc }
func NewKernel ¶
func NewKernel() *Kernel
func (*Kernel) Wrap ¶
type Listener ¶
type Listener interface { OnChange(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool) }
func FuncListener ¶
func FuncListener(f func(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool)) Listener
type Message ¶
func NewMessage ¶
func ReadMessage ¶
func (*Message) WriteTo ¶
type MsgType ¶
type MsgType int16
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
func NewOperation ¶
func (*Operation) Clean ¶
func (o *Operation) Clean()
func (*Operation) Close ¶
func (o *Operation) Close()
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) GenPasswordConfig ¶
func (*Operation) GetConfig ¶
func (Operation) HandleCompleteSelect ¶
func (Operation) HandleVim ¶
func (Operation) HandleVimNormal ¶
func (Operation) IsEnableVimMode ¶
func (o Operation) IsEnableVimMode() 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) OnComplete ¶
func (o Operation) OnComplete() bool
func (*Operation) Password ¶
func (Operation) PasswordConfig ¶
func (o Operation) PasswordConfig() *Config
func (*Operation) PasswordEx ¶
func (*Operation) PasswordWithConfig ¶
func (*Operation) Refresh ¶
func (o *Operation) Refresh()
func (*Operation) ResetHistory ¶
func (o *Operation) ResetHistory()
func (*Operation) Runes ¶
func (*Operation) SaveHistory ¶
if err is not nil, it just mean it fail to write to file other things goes fine.
func (Operation) SearchBackspace ¶
func (o Operation) SearchBackspace()
func (Operation) SearchChar ¶
func (o Operation) SearchChar(r rune)
func (Operation) SearchMode ¶
func (Operation) SearchRefresh ¶
func (o Operation) SearchRefresh(x int)
func (*Operation) SetBuffer ¶
func (*Operation) SetConfig ¶
func (*Operation) SetHistoryPath ¶
func (*Operation) SetMaskRune ¶
func (*Operation) SetPrompt ¶
func (*Operation) SetTitle ¶
func (Operation) SetVimMode ¶
func (o Operation) SetVimMode(on bool)
func (*Operation) Slice ¶
func (*Operation) Stderr ¶
func (*Operation) Stdout ¶
func (*Operation) String ¶
type Painter ¶
type PrefixCompleter ¶
type PrefixCompleter struct { Name []rune Dynamic bool Callback DynamicCompleteFunc Children []PrefixCompleterInterface }
func NewPrefixCompleter ¶
func NewPrefixCompleter(pc ...PrefixCompleterInterface) *PrefixCompleter
func PcItem ¶
func PcItem(name string, pc ...PrefixCompleterInterface) *PrefixCompleter
func PcItemDynamic ¶
func PcItemDynamic(callback DynamicCompleteFunc, 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) GetDynamicNames ¶
func (p *PrefixCompleter) GetDynamicNames(line []rune) [][]rune
func (*PrefixCompleter) GetName ¶
func (p *PrefixCompleter) GetName() []rune
func (*PrefixCompleter) IsDynamic ¶
func (p *PrefixCompleter) IsDynamic() bool
func (*PrefixCompleter) Print ¶
func (p *PrefixCompleter) Print(prefix string, level int, buf *bytes.Buffer)
func (*PrefixCompleter) SetChildren ¶
func (p *PrefixCompleter) SetChildren(children []PrefixCompleterInterface)
func (*PrefixCompleter) Tree ¶
func (p *PrefixCompleter) Tree(prefix string) string
type PrefixCompleterInterface ¶
type PrefixCompleterInterface interface { Print(prefix string, level int, buf *bytes.Buffer) Do(line []rune, pos int) (newLine [][]rune, length int) GetName() []rune GetChildren() []PrefixCompleterInterface SetChildren(children []PrefixCompleterInterface) }
type RawMode ¶
type RawMode struct {
// contains filtered or unexported fields
}
func (*RawMode) Enter ¶
func (*RawMode) Exit ¶
type RawReader ¶
type RawReader struct {
// contains filtered or unexported fields
}
RawReader translate input record to ANSI escape sequence. To provides same behavior as unix terminal.
func NewRawReader ¶
func NewRawReader() *RawReader
func (*RawReader) Close ¶
func (*RawReader) Read ¶
only process one action in one read
type RemoteCli ¶
type RemoteCli struct {
// contains filtered or unexported fields
}
func NewRemoteCli ¶
func (*RemoteCli) Close ¶
func (r *RemoteCli) Close()
func (*RemoteCli) MarkIsTerminal ¶
func (*RemoteCli) Serve ¶
func (*RemoteCli) ServeBy ¶
func (*RemoteCli) Write ¶
type RemoteSvr ¶
type RemoteSvr struct {
// contains filtered or unexported fields
}
func NewRemoteSvr ¶
func (*RemoteSvr) Close ¶
func (*RemoteSvr) EnterRawMode ¶
func (*RemoteSvr) ExitRawMode ¶
func (*RemoteSvr) GetWidth ¶
func (*RemoteSvr) GotIsTerminal ¶
func (*RemoteSvr) GotReportWidth ¶
func (*RemoteSvr) HandleConfig ¶
func (*RemoteSvr) IsTerminal ¶
func (*RemoteSvr) Read ¶
func (*RemoteSvr) Write ¶
type Result ¶
func (*Result) CanBreak ¶
func (*Result) CanContinue ¶
type RuneBuffer ¶
func NewRuneBuffer ¶
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(width int) int
func (*RuneBuffer) IsCursorInEnd ¶
func (r *RuneBuffer) IsCursorInEnd() bool
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(width int) 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) MoveToEndWord ¶
func (r *RuneBuffer) MoveToEndWord()
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) OnWidthChange ¶
func (r *RuneBuffer) OnWidthChange(newWidth int)
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) Replace ¶
func (r *RuneBuffer) Replace(ch rune)
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) SetConfig ¶
func (r *RuneBuffer) SetConfig(cfg *Config)
func (*RuneBuffer) SetMask ¶
func (r *RuneBuffer) SetMask(m rune)
func (*RuneBuffer) SetOffset ¶
func (r *RuneBuffer) SetOffset(offset string)
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)
func (*RuneBuffer) Yank ¶
func (r *RuneBuffer) Yank()
type Runes ¶
type Runes struct{}
func (Runes) Aggregate ¶
func (Runes) Backspace ¶
func (Runes) ColorFilter ¶
func (Runes) Copy ¶
func (Runes) Equal ¶
func (Runes) EqualFold ¶
func (Runes) EqualRune ¶
func (Runes) EqualRuneFold ¶
func (Runes) HasPrefix ¶
func (Runes) HasPrefixFold ¶
func (Runes) Index ¶
func (Runes) IndexAll ¶
Search in runes from front to end
func (Runes) IndexAllBck ¶
Search in runes from end to front
func (Runes) IndexAllBckEx ¶
func (Runes) IndexAllEx ¶
func (Runes) TrimSpaceLeft ¶
func (Runes) Width ¶
func (Runes) WidthAll ¶
type SegmentComplete ¶
type SegmentComplete struct { SegmentCompleter }
func SegmentAutoComplete ¶
func SegmentAutoComplete(completer SegmentCompleter) *SegmentComplete
func (*SegmentComplete) Do ¶
func (c *SegmentComplete) Do(line []rune, pos int) (newLine [][]rune, offset int)
type SegmentCompleter ¶
type SegmentCompleter interface { // 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] DoSegment([][]rune, int) [][]rune }
type State ¶
type State struct {
// contains filtered or unexported fields
}
func GetState ¶
GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.
func MakeRaw ¶
MakeRaw put the terminal connected to the given file descriptor into raw mode and returns the previous state of the terminal so that it can be restored.
type TabCompleter ¶
type TabCompleter struct{}
func (*TabCompleter) Do ¶
func (t *TabCompleter) Do([]rune, int) ([][]rune, int)
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
func NewTerminal ¶
func (*Terminal) Bell ¶
func (t *Terminal) Bell()
func (*Terminal) Close ¶
func (*Terminal) EnterRawMode ¶
func (*Terminal) ExitRawMode ¶
func (*Terminal) GetConfig ¶
func (*Terminal) GetOffset ¶
func (*Terminal) IsReading ¶
func (*Terminal) KickRead ¶
func (t *Terminal) KickRead()
func (*Terminal) Print ¶
func (*Terminal) PrintRune ¶
func (*Terminal) ReadRune ¶
return rune(0) if meet EOF
func (*Terminal) Readline ¶
func (*Terminal) SetConfig ¶
func (*Terminal) SleepToResume ¶
func (t *Terminal) SleepToResume()
SleepToResume will sleep myself, and return only if I'm resumed.
func (*Terminal) Write ¶
func (*Terminal) WriteStdin ¶
WriteStdin prefill the next Stdin fetch Next time you call ReadLine() this value will be writen before the user input
Source Files ¶
ansi_windows.go complete.go complete_helper.go complete_segment.go history.go operation.go password.go rawreader_windows.go readline.go remote.go runebuf.go runes.go search.go std.go std_windows.go term_windows.go terminal.go utils.go utils_windows.go vim.go windows_api.go
Directories ¶
Path | Synopsis |
---|---|
example | |
example/readline-demo | |
example/readline-im | |
example/readline-multiline | |
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. |
example/readline-remote | |
example/readline-remote/readline-remote-client | |
example/readline-remote/readline-remote-server | |
runes | deprecated. |
- Version
- v1.5.1 (latest)
- Published
- Jul 15, 2022
- Platform
- windows/amd64
- Imports
- 20 packages
- Last checked
- 2 weeks ago –
Tools for package owners.