readline: github.com/bettercap/readline Index | Files | Directories

package readline

import "github.com/bettercap/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

Package Files

complete.go complete_helper.go complete_segment.go history.go operation.go password.go readline.go remote.go runebuf.go runes.go search.go std.go term.go term_linux.go term_unix.go terminal.go utils.go utils_unix.go vim.go

Constants

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
    CharEscapeEx  = 91
    CharBackspace = 127
)
const (
    MetaBackward rune = -iota - 1
    MetaForward
    MetaDelete
    MetaBackspace
    MetaTranspose
)
const (
    VIM_NORMAL = iota
    VIM_INSERT
    VIM_VISUAL
)

Variables

var (
    Stdin  io.ReadCloser  = os.Stdin
    Stdout io.WriteCloser = os.Stdout
    Stderr io.WriteCloser = os.Stderr
)
var (
    ErrInterrupt = errors.New("Interrupt")
)
var TabWidth = 4

func AddHistory Uses

func AddHistory(content string) error

add history to global instance manually raise error only if `SetHistoryPath` is set with a non-empty path

func ClearScreen Uses

func ClearScreen(w io.Writer) (int, error)

ClearScreen clears the console screen

func Debug Uses

func Debug(o ...interface{})

append log info to another file

func DefaultIsTerminal Uses

func DefaultIsTerminal() bool

func DefaultOnWidthChanged Uses

func DefaultOnWidthChanged(f func())

func DialRemote Uses

func DialRemote(n, addr string) error

func Do Uses

func Do(p PrefixCompleterInterface, line []rune, pos int) (newLine [][]rune, offset int)

func GetInt Uses

func GetInt(s []string, def int) int

func GetScreenWidth Uses

func GetScreenWidth() int

func GetSize Uses

func GetSize(fd int) (int, int, error)

GetSize returns the dimensions of the given terminal.

func GetStdin Uses

func GetStdin() int

func IsPrintable Uses

func IsPrintable(key rune) bool

func IsTerminal Uses

func IsTerminal(fd int) bool

IsTerminal returns true if the given file descriptor is a terminal.

func IsWordBreak Uses

func IsWordBreak(i rune) bool

func Line Uses

func Line(prompt string) (string, error)

readline with global configs

func LineCount Uses

func LineCount(screenWidth, w int) int

calculate how many lines for N character

func ListenRemote Uses

func ListenRemote(n, addr string, cfg *Config, h func(*Instance), onListen ...func(net.Listener) error) error

func NewFillableStdin Uses

func NewFillableStdin(stdin io.Reader) (io.ReadCloser, io.Writer)

NewFillableStdin gives you FillableStdin

func Password Uses

func Password(prompt string) ([]byte, error)

func Print Uses

func Print(p PrefixCompleterInterface, prefix string, level int, buf *bytes.Buffer)

func ReadPassword Uses

func ReadPassword(fd int) ([]byte, error)

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 Uses

func Restore(fd int, state *State) error

func RetSegment Uses

func RetSegment(segments [][]rune, cands [][]rune, idx int) ([][]rune, int)

func SetAutoComplete Uses

func SetAutoComplete(completer AutoCompleter)

set auto completer to global instance

func SetHistoryPath Uses

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 Uses

func SplitByLine(start, screenWidth int, rs []rune) []string

func SplitSegment Uses

func SplitSegment(line []rune, pos int) ([][]rune, int)

func SuspendMe Uses

func SuspendMe()

SuspendMe use to send suspend signal to myself, when we in the raw mode. For OSX it need to send to parent's pid For Linux it need to send to myself

func WaitForResume Uses

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.

type AutoCompleter Uses

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 Uses

func SegmentFunc(f func([][]rune, int) [][]rune) AutoCompleter

type CancelableStdin Uses

type CancelableStdin struct {
    // contains filtered or unexported fields
}

func NewCancelableStdin Uses

func NewCancelableStdin(r io.Reader) *CancelableStdin

func (*CancelableStdin) Close Uses

func (c *CancelableStdin) Close() error

func (*CancelableStdin) Read Uses

func (c *CancelableStdin) Read(b []byte) (n int, err error)

type Config Uses

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 Uses

func (c Config) Clone() *Config

func (*Config) Init Uses

func (c *Config) Init() error

func (*Config) SetListener Uses

func (c *Config) SetListener(f func(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool))

func (*Config) SetPainter Uses

func (c *Config) SetPainter(p Painter)

type DumpListener Uses

type DumpListener struct {
    // contains filtered or unexported fields
}

func (*DumpListener) OnChange Uses

func (d *DumpListener) OnChange(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool)

type DynamicCompleteFunc Uses

type DynamicCompleteFunc func(string) []string

Caller type for dynamic completion

type DynamicPrefixCompleterInterface Uses

type DynamicPrefixCompleterInterface interface {
    PrefixCompleterInterface
    IsDynamic() bool
    GetDynamicNames(line []rune) [][]rune
}

type FillableStdin Uses

type FillableStdin struct {
    sync.Mutex
    // contains filtered or unexported fields
}

FillableStdin is a stdin reader which can prepend some data before reading into the real stdin

func (*FillableStdin) Close Uses

func (s *FillableStdin) Close() error

func (*FillableStdin) Read Uses

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 Uses

type Instance struct {
    Config    *Config
    Terminal  *Terminal
    Operation *Operation
}

func HandleConn Uses

func HandleConn(cfg Config, conn net.Conn) (*Instance, error)

func New Uses

func New(prompt string) (*Instance, error)

func NewEx Uses

func NewEx(cfg *Config) (*Instance, error)

func (*Instance) Clean Uses

func (i *Instance) Clean()

func (*Instance) Close Uses

func (i *Instance) Close() error

we must make sure that call Close() before process exit.

func (*Instance) GenPasswordConfig Uses

func (i *Instance) GenPasswordConfig() *Config

func (*Instance) HistoryDisable Uses

func (i *Instance) HistoryDisable()

HistoryDisable the save of the commands into the history

func (*Instance) HistoryEnable Uses

func (i *Instance) HistoryEnable()

HistoryEnable the save of the commands into the history (default on)

func (*Instance) IsVimMode Uses

func (i *Instance) IsVimMode() bool

func (*Instance) Line Uses

func (i *Instance) Line() *Result

func (*Instance) ReadPassword Uses

func (i *Instance) ReadPassword(prompt string) ([]byte, error)

func (*Instance) ReadPasswordEx Uses

func (i *Instance) ReadPasswordEx(prompt string, l Listener) ([]byte, error)

func (*Instance) ReadPasswordWithConfig Uses

func (i *Instance) ReadPasswordWithConfig(cfg *Config) ([]byte, error)

we can generate a config by `i.GenPasswordConfig()`

func (*Instance) ReadSlice Uses

func (i *Instance) ReadSlice() ([]byte, error)

same as readline

func (*Instance) Readline Uses

func (i *Instance) Readline() (string, error)

err is one of (nil, io.EOF, readline.ErrInterrupt)

func (*Instance) ReadlineWithDefault Uses

func (i *Instance) ReadlineWithDefault(what string) (string, error)

func (*Instance) Refresh Uses

func (i *Instance) Refresh()

func (*Instance) ResetHistory Uses

func (i *Instance) ResetHistory()

func (*Instance) SaveHistory Uses

func (i *Instance) SaveHistory(content string) error

func (*Instance) SetConfig Uses

func (i *Instance) SetConfig(cfg *Config) *Config

func (*Instance) SetHistoryPath Uses

func (i *Instance) SetHistoryPath(p string)

change history persistence in runtime

func (*Instance) SetMaskRune Uses

func (i *Instance) SetMaskRune(r rune)

func (*Instance) SetPrompt Uses

func (i *Instance) SetPrompt(s string)

func (*Instance) SetVimMode Uses

func (i *Instance) SetVimMode(on bool)

switch VimMode in runtime

func (*Instance) Stderr Uses

func (i *Instance) Stderr() io.Writer

readline will refresh automatic when write through Stdout()

func (*Instance) Stdout Uses

func (i *Instance) Stdout() io.Writer

readline will refresh automatic when write through Stdout()

func (*Instance) Write Uses

func (i *Instance) Write(b []byte) (int, error)

func (*Instance) WriteStdin Uses

func (i *Instance) 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]

type InterruptError Uses

type InterruptError struct {
    Line []rune
}

func (*InterruptError) Error Uses

func (*InterruptError) Error() string

type Listener Uses

type Listener interface {
    OnChange(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool)
}

func FuncListener Uses

func FuncListener(f func(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool)) Listener

type Message Uses

type Message struct {
    Type MsgType
    Data []byte
}

func NewMessage Uses

func NewMessage(t MsgType, data []byte) *Message

func ReadMessage Uses

func ReadMessage(r io.Reader) (*Message, error)

func (*Message) WriteTo Uses

func (m *Message) WriteTo(w io.Writer) (int, error)

type MsgType Uses

type MsgType int16

type Operation Uses

type Operation struct {
    // contains filtered or unexported fields
}

func NewOperation Uses

func NewOperation(t *Terminal, cfg *Config) *Operation

func (*Operation) Clean Uses

func (o *Operation) Clean()

func (*Operation) Close Uses

func (o *Operation) Close()

func (Operation) CompleteRefresh Uses

func (o Operation) CompleteRefresh()

func (Operation) EnterCompleteMode Uses

func (o Operation) EnterCompleteMode(offset int, candidate [][]rune)

func (Operation) EnterCompleteSelectMode Uses

func (o Operation) EnterCompleteSelectMode()

func (Operation) EnterPasswordMode Uses

func (o Operation) EnterPasswordMode(cfg *Config) (err error)

func (Operation) EnterVimInsertMode Uses

func (o Operation) EnterVimInsertMode()

func (Operation) ExitCompleteMode Uses

func (o Operation) ExitCompleteMode(revent bool)

func (Operation) ExitCompleteSelectMode Uses

func (o Operation) ExitCompleteSelectMode()

func (Operation) ExitPasswordMode Uses

func (o Operation) ExitPasswordMode()

func (Operation) ExitSearchMode Uses

func (o Operation) ExitSearchMode(revert bool)

func (Operation) ExitVimInsertMode Uses

func (o Operation) ExitVimInsertMode()

func (Operation) ExitVimMode Uses

func (o Operation) ExitVimMode()

func (*Operation) GenPasswordConfig Uses

func (o *Operation) GenPasswordConfig() *Config

func (*Operation) GetConfig Uses

func (o *Operation) GetConfig() *Config

func (Operation) HandleCompleteSelect Uses

func (o Operation) HandleCompleteSelect(r rune) bool

func (Operation) HandleVim Uses

func (o Operation) HandleVim(r rune, readNext func() rune) rune

func (Operation) HandleVimNormal Uses

func (o Operation) HandleVimNormal(r rune, readNext func() rune) (t rune)

func (Operation) IsEnableVimMode Uses

func (o Operation) IsEnableVimMode() bool

func (Operation) IsInCompleteMode Uses

func (o Operation) IsInCompleteMode() bool

func (Operation) IsInCompleteSelectMode Uses

func (o Operation) IsInCompleteSelectMode() bool

func (*Operation) IsNormalMode Uses

func (o *Operation) IsNormalMode() bool

func (Operation) IsSearchMode Uses

func (o Operation) IsSearchMode() bool

func (Operation) OnComplete Uses

func (o Operation) OnComplete() bool

func (*Operation) Password Uses

func (o *Operation) Password(prompt string) ([]byte, error)

func (Operation) PasswordConfig Uses

func (o Operation) PasswordConfig() *Config

func (*Operation) PasswordEx Uses

func (o *Operation) PasswordEx(prompt string, l Listener) ([]byte, error)

func (*Operation) PasswordWithConfig Uses

func (o *Operation) PasswordWithConfig(cfg *Config) ([]byte, error)

func (*Operation) Refresh Uses

func (o *Operation) Refresh()

func (*Operation) ResetHistory Uses

func (o *Operation) ResetHistory()

func (*Operation) Runes Uses

func (o *Operation) Runes() ([]rune, error)

func (*Operation) SaveHistory Uses

func (o *Operation) SaveHistory(content string) error

if err is not nil, it just mean it fail to write to file other things goes fine.

func (Operation) SearchBackspace Uses

func (o Operation) SearchBackspace()

func (Operation) SearchChar Uses

func (o Operation) SearchChar(r rune)

func (Operation) SearchMode Uses

func (o Operation) SearchMode(dir int) bool

func (Operation) SearchRefresh Uses

func (o Operation) SearchRefresh(x int)

func (*Operation) SetBuffer Uses

func (o *Operation) SetBuffer(what string)

func (*Operation) SetConfig Uses

func (op *Operation) SetConfig(cfg *Config) (*Config, error)

func (*Operation) SetHistoryPath Uses

func (o *Operation) SetHistoryPath(path string)

func (*Operation) SetMaskRune Uses

func (o *Operation) SetMaskRune(r rune)

func (*Operation) SetPrompt Uses

func (o *Operation) SetPrompt(s string)

func (*Operation) SetTitle Uses

func (o *Operation) SetTitle(t string)

func (Operation) SetVimMode Uses

func (o Operation) SetVimMode(on bool)

func (*Operation) Slice Uses

func (o *Operation) Slice() ([]byte, error)

func (*Operation) Stderr Uses

func (o *Operation) Stderr() io.Writer

func (*Operation) Stdout Uses

func (o *Operation) Stdout() io.Writer

func (*Operation) String Uses

func (o *Operation) String() (string, error)

type Painter Uses

type Painter interface {
    Paint(line []rune, pos int) []rune
}

type PrefixCompleter Uses

type PrefixCompleter struct {
    Name     []rune
    Dynamic  bool
    Callback DynamicCompleteFunc
    Children []PrefixCompleterInterface
}

func NewPrefixCompleter Uses

func NewPrefixCompleter(pc ...PrefixCompleterInterface) *PrefixCompleter

func PcItem Uses

func PcItem(name string, pc ...PrefixCompleterInterface) *PrefixCompleter

func PcItemDynamic Uses

func PcItemDynamic(callback DynamicCompleteFunc, pc ...PrefixCompleterInterface) *PrefixCompleter

func (*PrefixCompleter) Do Uses

func (p *PrefixCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int)

func (*PrefixCompleter) GetChildren Uses

func (p *PrefixCompleter) GetChildren() []PrefixCompleterInterface

func (*PrefixCompleter) GetDynamicNames Uses

func (p *PrefixCompleter) GetDynamicNames(line []rune) [][]rune

func (*PrefixCompleter) GetName Uses

func (p *PrefixCompleter) GetName() []rune

func (*PrefixCompleter) IsDynamic Uses

func (p *PrefixCompleter) IsDynamic() bool

func (*PrefixCompleter) Print Uses

func (p *PrefixCompleter) Print(prefix string, level int, buf *bytes.Buffer)

func (*PrefixCompleter) SetChildren Uses

func (p *PrefixCompleter) SetChildren(children []PrefixCompleterInterface)

func (*PrefixCompleter) Tree Uses

func (p *PrefixCompleter) Tree(prefix string) string

type PrefixCompleterInterface Uses

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 Uses

type RawMode struct {
    // contains filtered or unexported fields
}

func (*RawMode) Enter Uses

func (r *RawMode) Enter() (err error)

func (*RawMode) Exit Uses

func (r *RawMode) Exit() error

type RemoteCli Uses

type RemoteCli struct {
    // contains filtered or unexported fields
}

func NewRemoteCli Uses

func NewRemoteCli(conn net.Conn) (*RemoteCli, error)

func (*RemoteCli) Close Uses

func (r *RemoteCli) Close()

func (*RemoteCli) MarkIsTerminal Uses

func (r *RemoteCli) MarkIsTerminal(is bool)

func (*RemoteCli) Serve Uses

func (r *RemoteCli) Serve() error

func (*RemoteCli) ServeBy Uses

func (r *RemoteCli) ServeBy(source io.Reader) error

func (*RemoteCli) Write Uses

func (r *RemoteCli) Write(b []byte) (int, error)

type RemoteSvr Uses

type RemoteSvr struct {
    // contains filtered or unexported fields
}

func NewRemoteSvr Uses

func NewRemoteSvr(conn net.Conn) (*RemoteSvr, error)

func (*RemoteSvr) Close Uses

func (r *RemoteSvr) Close() error

func (*RemoteSvr) EnterRawMode Uses

func (r *RemoteSvr) EnterRawMode() error

func (*RemoteSvr) ExitRawMode Uses

func (r *RemoteSvr) ExitRawMode() error

func (*RemoteSvr) GetWidth Uses

func (r *RemoteSvr) GetWidth() int

func (*RemoteSvr) GotIsTerminal Uses

func (r *RemoteSvr) GotIsTerminal(data []byte)

func (*RemoteSvr) GotReportWidth Uses

func (r *RemoteSvr) GotReportWidth(data []byte)

func (*RemoteSvr) HandleConfig Uses

func (r *RemoteSvr) HandleConfig(cfg *Config)

func (*RemoteSvr) IsTerminal Uses

func (r *RemoteSvr) IsTerminal() bool

func (*RemoteSvr) Read Uses

func (r *RemoteSvr) Read(b []byte) (int, error)

func (*RemoteSvr) Write Uses

func (r *RemoteSvr) Write(b []byte) (int, error)

type Result Uses

type Result struct {
    Line  string
    Error error
}

func (*Result) CanBreak Uses

func (l *Result) CanBreak() bool

func (*Result) CanContinue Uses

func (l *Result) CanContinue() bool

type RuneBuffer Uses

type RuneBuffer struct {
    sync.Mutex
    // contains filtered or unexported fields
}

func NewRuneBuffer Uses

func NewRuneBuffer(w io.Writer, prompt string, cfg *Config, width int) *RuneBuffer

func (*RuneBuffer) BackEscapeWord Uses

func (r *RuneBuffer) BackEscapeWord()

func (*RuneBuffer) Backspace Uses

func (r *RuneBuffer) Backspace()

func (*RuneBuffer) Backup Uses

func (r *RuneBuffer) Backup()

func (*RuneBuffer) Clean Uses

func (r *RuneBuffer) Clean()

func (*RuneBuffer) CurrentWidth Uses

func (r *RuneBuffer) CurrentWidth(x int) int

func (*RuneBuffer) CursorLineCount Uses

func (r *RuneBuffer) CursorLineCount() int

func (*RuneBuffer) Delete Uses

func (r *RuneBuffer) Delete() (success bool)

func (*RuneBuffer) DeleteWord Uses

func (r *RuneBuffer) DeleteWord()

func (*RuneBuffer) Erase Uses

func (r *RuneBuffer) Erase()

func (*RuneBuffer) IdxLine Uses

func (r *RuneBuffer) IdxLine(width int) int

func (*RuneBuffer) IsCursorInEnd Uses

func (r *RuneBuffer) IsCursorInEnd() bool

func (*RuneBuffer) Kill Uses

func (r *RuneBuffer) Kill()

func (*RuneBuffer) KillFront Uses

func (r *RuneBuffer) KillFront()

func (*RuneBuffer) Len Uses

func (r *RuneBuffer) Len() int

func (*RuneBuffer) LineCount Uses

func (r *RuneBuffer) LineCount(width int) int

func (*RuneBuffer) MoveBackward Uses

func (r *RuneBuffer) MoveBackward()

func (*RuneBuffer) MoveForward Uses

func (r *RuneBuffer) MoveForward()

func (*RuneBuffer) MoveTo Uses

func (r *RuneBuffer) MoveTo(ch rune, prevChar, reverse bool) (success bool)

func (*RuneBuffer) MoveToEndWord Uses

func (r *RuneBuffer) MoveToEndWord()

func (*RuneBuffer) MoveToLineEnd Uses

func (r *RuneBuffer) MoveToLineEnd()

func (*RuneBuffer) MoveToLineStart Uses

func (r *RuneBuffer) MoveToLineStart()

func (*RuneBuffer) MoveToNextWord Uses

func (r *RuneBuffer) MoveToNextWord()

func (*RuneBuffer) MoveToPrevWord Uses

func (r *RuneBuffer) MoveToPrevWord() (success bool)

func (*RuneBuffer) OnWidthChange Uses

func (r *RuneBuffer) OnWidthChange(newWidth int)

func (*RuneBuffer) Pos Uses

func (r *RuneBuffer) Pos() int

func (*RuneBuffer) PromptLen Uses

func (r *RuneBuffer) PromptLen() int

func (*RuneBuffer) Refresh Uses

func (r *RuneBuffer) Refresh(f func())

func (*RuneBuffer) Replace Uses

func (r *RuneBuffer) Replace(ch rune)

func (*RuneBuffer) Reset Uses

func (r *RuneBuffer) Reset() []rune

func (*RuneBuffer) Restore Uses

func (r *RuneBuffer) Restore()

func (*RuneBuffer) RuneSlice Uses

func (r *RuneBuffer) RuneSlice(i int) []rune

func (*RuneBuffer) Runes Uses

func (r *RuneBuffer) Runes() []rune

func (*RuneBuffer) Set Uses

func (r *RuneBuffer) Set(buf []rune)

func (*RuneBuffer) SetConfig Uses

func (r *RuneBuffer) SetConfig(cfg *Config)

func (*RuneBuffer) SetMask Uses

func (r *RuneBuffer) SetMask(m rune)

func (*RuneBuffer) SetOffset Uses

func (r *RuneBuffer) SetOffset(offset string)

func (*RuneBuffer) SetPrompt Uses

func (r *RuneBuffer) SetPrompt(prompt string)

func (*RuneBuffer) SetStyle Uses

func (r *RuneBuffer) SetStyle(start, end int, style string)

func (*RuneBuffer) SetWithIdx Uses

func (r *RuneBuffer) SetWithIdx(idx int, buf []rune)

func (*RuneBuffer) Transpose Uses

func (r *RuneBuffer) Transpose()

func (*RuneBuffer) WriteRune Uses

func (r *RuneBuffer) WriteRune(s rune)

func (*RuneBuffer) WriteRunes Uses

func (r *RuneBuffer) WriteRunes(s []rune)

func (*RuneBuffer) WriteString Uses

func (r *RuneBuffer) WriteString(s string)

func (*RuneBuffer) Yank Uses

func (r *RuneBuffer) Yank()

type Runes Uses

type Runes struct{}

func (Runes) Aggregate Uses

func (Runes) Aggregate(candicate [][]rune) (same []rune, size int)

func (Runes) Backspace Uses

func (Runes) Backspace(r []rune) []byte

func (Runes) ColorFilter Uses

func (Runes) ColorFilter(r []rune) []rune

func (Runes) Copy Uses

func (Runes) Copy(r []rune) []rune

func (Runes) Equal Uses

func (Runes) Equal(a, b []rune) bool

func (Runes) EqualFold Uses

func (r Runes) EqualFold(a, b []rune) bool

func (Runes) EqualRune Uses

func (Runes) EqualRune(a, b rune, fold bool) bool

func (Runes) EqualRuneFold Uses

func (r Runes) EqualRuneFold(a, b rune) bool

func (Runes) HasPrefix Uses

func (Runes) HasPrefix(r, prefix []rune) bool

func (Runes) HasPrefixFold Uses

func (Runes) HasPrefixFold(r, prefix []rune) bool

func (Runes) Index Uses

func (Runes) Index(r rune, rs []rune) int

func (Runes) IndexAll Uses

func (rs Runes) IndexAll(r, sub []rune) int

Search in runes from front to end

func (Runes) IndexAllBck Uses

func (rs Runes) IndexAllBck(r, sub []rune) int

Search in runes from end to front

func (Runes) IndexAllBckEx Uses

func (rs Runes) IndexAllBckEx(r, sub []rune, fold bool) int

func (Runes) IndexAllEx Uses

func (rs Runes) IndexAllEx(r, sub []rune, fold bool) int

func (Runes) TrimSpaceLeft Uses

func (Runes) TrimSpaceLeft(in []rune) []rune

func (Runes) Width Uses

func (Runes) Width(r rune) int

func (Runes) WidthAll Uses

func (Runes) WidthAll(r []rune) (length int)

type SegmentComplete Uses

type SegmentComplete struct {
    SegmentCompleter
}

func SegmentAutoComplete Uses

func SegmentAutoComplete(completer SegmentCompleter) *SegmentComplete

func (*SegmentComplete) Do Uses

func (c *SegmentComplete) Do(line []rune, pos int) (newLine [][]rune, offset int)

type SegmentCompleter Uses

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 Uses

type State struct {
    // contains filtered or unexported fields
}

State contains the state of a terminal.

func GetState Uses

func GetState(fd int) (*State, error)

GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.

func MakeRaw Uses

func MakeRaw(fd int) (*State, error)

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 Uses

type TabCompleter struct{}

func (*TabCompleter) Do Uses

func (t *TabCompleter) Do([]rune, int) ([][]rune, int)

type Terminal Uses

type Terminal struct {
    // contains filtered or unexported fields
}

func NewTerminal Uses

func NewTerminal(cfg *Config) (*Terminal, error)

func (*Terminal) Bell Uses

func (t *Terminal) Bell()

func (*Terminal) Close Uses

func (t *Terminal) Close() error

func (*Terminal) EnterRawMode Uses

func (t *Terminal) EnterRawMode() (err error)

func (*Terminal) ExitRawMode Uses

func (t *Terminal) ExitRawMode() (err error)

func (*Terminal) GetConfig Uses

func (t *Terminal) GetConfig() *Config

func (*Terminal) GetOffset Uses

func (t *Terminal) GetOffset(f func(offset string))

func (*Terminal) IsReading Uses

func (t *Terminal) IsReading() bool

func (*Terminal) KickRead Uses

func (t *Terminal) KickRead()

func (*Terminal) Print Uses

func (t *Terminal) Print(s string)

func (*Terminal) PrintRune Uses

func (t *Terminal) PrintRune(r rune)

func (*Terminal) ReadRune Uses

func (t *Terminal) ReadRune() rune

return rune(0) if meet EOF

func (*Terminal) Readline Uses

func (t *Terminal) Readline() *Operation

func (*Terminal) SetConfig Uses

func (t *Terminal) SetConfig(c *Config) error

func (*Terminal) SleepToResume Uses

func (t *Terminal) SleepToResume()

SleepToResume will sleep myself, and return only if I'm resumed.

func (*Terminal) Write Uses

func (t *Terminal) Write(b []byte) (int, error)

func (*Terminal) WriteStdin Uses

func (t *Terminal) WriteStdin(b []byte) (int, error)

WriteStdin prefill the next Stdin fetch Next time you call ReadLine() this value will be writen before the user input

type Termios Uses

type Termios syscall.Termios

Directories

PathSynopsis
runesdeprecated.

Package readline imports 19 packages (graph) and is imported by 3 packages. Updated 2018-02-27. Refresh now. Tools for package owners.