Documentation ¶
Overview ¶
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 ClearScreen(w io.Writer) (int, error)
- func Debug(o ...interface{})
- func DefaultIsTerminal() bool
- func DefaultOnWidthChanged(f func())
- 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 Password(prompt string) ([]byte, error)
- func ReadPassword(fd int) ([]byte, error)
- func Restore(fd int, state *State) error
- func SplitByLine(start, screenWidth int, rs []rune) []string
- func SuspendMe()
- func WaitForResume() chan struct{}
- type CancelableStdin
- type Config
- type DumpListener
- type Instance
- func (i *Instance) Clean()
- func (i *Instance) Close() error
- func (i *Instance) GenPasswordConfig() *Config
- 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) Refresh()
- func (i *Instance) SetConfig(cfg *Config) *Config
- func (i *Instance) SetMaskRune(r rune)
- func (i *Instance) SetPrompt(s string)
- func (i *Instance) Stderr() io.Writer
- func (i *Instance) Stdout() io.Writer
- func (i *Instance) Write(b []byte) (int, error)
- type InterruptError
- type Listener
- type Operation
- func (o *Operation) Clean()
- func (o Operation) EnterPasswordMode(cfg *Config) (err error)
- func (o Operation) ExitPasswordMode()
- func (o *Operation) GenPasswordConfig() *Config
- 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) Runes() ([]rune, error)
- func (o *Operation) SetBuf(s string)
- func (op *Operation) SetConfig(cfg *Config) (*Config, error)
- func (o *Operation) SetMaskRune(r rune)
- func (o *Operation) SetPrompt(s string)
- func (o *Operation) SetTitle(t string)
- 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 RawMode
- type Result
- 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(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)
- 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 State
- 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) 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)
Constants ¶
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 CharCtrlZ = 26 CharEsc = 27 CharEscapeEx = 91 CharBackspace = 127 )
const ( MetaBackward rune = -iota - 1 MetaForward MetaDelete MetaBackspace MetaTranspose )
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
Functions ¶
func DefaultIsTerminal ¶
func DefaultIsTerminal() bool
func DefaultOnWidthChanged ¶
func DefaultOnWidthChanged(f func())
func GetScreenWidth ¶
func GetScreenWidth() int
func IsPrintable ¶
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
func IsWordBreak ¶
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 SplitByLine ¶
func SuspendMe ¶
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 ¶
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 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
type Config ¶
type Config struct { // prompt supports ANSI escape sequence, so we can color some characters even in windows Prompt string // Any key press will pass to Listener // NOTE: Listener will be triggered by (nil, 0, 0) immediately Listener Listener InterruptPrompt string EOFPrompt string FuncGetWidth func() int Stdin io.Reader 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 }
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) SetMaskRune ¶
type InterruptError ¶
type InterruptError struct {
Line []rune
}
func (*InterruptError) Error ¶
func (*InterruptError) Error() string
type Listener ¶
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
func NewOperation ¶
func (Operation) EnterPasswordMode ¶
func (Operation) ExitPasswordMode ¶
func (o Operation) ExitPasswordMode()
func (*Operation) GenPasswordConfig ¶
func (Operation) PasswordConfig ¶
func (o Operation) PasswordConfig() *Config
func (*Operation) PasswordEx ¶
func (*Operation) PasswordWithConfig ¶
func (*Operation) SetMaskRune ¶
type Result ¶
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)
type Runes ¶
type Runes struct{}
func (Runes) ColorFilter ¶
func (Runes) EqualRuneFold ¶
func (Runes) HasPrefixFold ¶
func (Runes) IndexAllBck ¶
Search in runes from end to front
func (Runes) TrimSpaceLeft ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State contains the state of a terminal.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
func NewTerminal ¶
func (*Terminal) EnterRawMode ¶
func (*Terminal) ExitRawMode ¶
func (*Terminal) SleepToResume ¶
func (t *Terminal) SleepToResume()
SleepToResume will sleep myself, and return only if I'm resumed.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
example
|
|
readline-pass-strength
This file is licensed under the WTFPL: DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
|
This file is licensed under the WTFPL: DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. |