Documentation ¶
Overview ¶
Package inputrc parses readline inputrc files.
Example ¶
package main import ( "os/user" "github.com/alexj212/readline/inputrc" ) func main() { u, err := user.Current() if err != nil { panic(err) } cfg := inputrc.NewDefaultConfig() if err := inputrc.UserDefault(u, cfg, inputrc.WithApp("bash")); err != nil { panic(err) } }
Output:
Index ¶
- Constants
- func Decontrol(c rune) rune
- func DefaultBinds() map[string]map[string]Bind
- func DefaultVars() map[string]interface{}
- func Demeta(c rune) rune
- func Encontrol(c rune) rune
- func Enmeta(c rune) rune
- func Escape(s string) string
- func EscapeMacro(s string) string
- func IsControl(c rune) bool
- func IsMeta(c rune) bool
- func Parse(r io.Reader, h Handler, opts ...Option) error
- func ParseBytes(buf []byte, h Handler, opts ...Option) error
- func ParseFile(name string, h Handler, opts ...Option) error
- func Unescape(s string) string
- func UserDefault(u *user.User, cfg *Config, opts ...Option) error
- type Bind
- type Config
- func (cfg *Config) Bind(keymap, sequence, action string, macro bool) error
- func (cfg *Config) Do(name, value string) error
- func (cfg *Config) Get(name string) interface{}
- func (cfg *Config) GetBool(name string) bool
- func (cfg *Config) GetInt(name string) int
- func (cfg *Config) GetString(name string) string
- func (cfg *Config) ReadFile(name string) ([]byte, error)
- func (cfg *Config) Set(name string, value interface{}) error
- type ConfigOption
- type Error
- type Handler
- type Option
- type ParseError
- type Parser
Examples ¶
Constants ¶
const ( Control rune = 0x1f Meta rune = 0x80 Esc rune = 0x1b Delete rune = 0x7f Alert rune = '\a' Backspace rune = '\b' Formfeed rune = '\f' Newline rune = '\n' Return rune = '\r' Tab rune = '\t' Vertical rune = '\v' Space rune = ' ' )
Keys.
Variables ¶
This section is empty.
Functions ¶
func DefaultBinds ¶
DefaultBinds are the default readline bind keymaps.
see: INPUTRC=/dev/null bash -c 'bind -pm <keymap>'
func DefaultVars ¶
func DefaultVars() map[string]interface{}
DefaultVars are the default readline vars.
see: INPUTRC=/dev/null bash -c 'bind -v'
func Parse ¶
Parse parses inputrc data from r.
Example ¶
package main import ( "fmt" "strings" "github.com/alexj212/readline/inputrc" ) func main() { const example = ` set editing-mode vi $if Usql set keymap vi-insert "\r": a-usql-action "\d": 'echo test\n' $endif ` cfg := inputrc.NewDefaultConfig() if err := inputrc.Parse(strings.NewReader(example), cfg, inputrc.WithApp("usql")); err != nil { panic(err) } fmt.Println("editing mode:", cfg.GetString("editing-mode")) fmt.Println("vi-insert:") fmt.Printf(" %s: %s\n", inputrc.Escape(string(inputrc.Return)), cfg.Binds["vi-insert"][string(inputrc.Return)].Action) fmt.Printf(" %s: '%s'\n", inputrc.Escape(string(inputrc.Delete)), inputrc.EscapeMacro(cfg.Binds["vi-insert"][string(inputrc.Delete)].Action)) }
Output: editing mode: vi vi-insert: \C-M: a-usql-action \C-?: 'echo test\n'
func ParseBytes ¶
ParseBytes parses inputrc data from buf.
Types ¶
type Config ¶
type Config struct { ReadFileFunc func(string) ([]byte, error) Vars map[string]interface{} Binds map[string]map[string]Bind Funcs map[string]func(string, string) error }
Config is a inputrc config handler.
func NewDefaultConfig ¶
func NewDefaultConfig(opts ...ConfigOption) *Config
NewDefaultConfig creates a new inputrc config with default values.
type ConfigOption ¶
type ConfigOption func(*Config)
ConfigOption is a inputrc config handler option.
func WithConfigReadFileFunc ¶
func WithConfigReadFileFunc(readFileFunc func(string) ([]byte, error)) ConfigOption
WithConfigReadFileFunc is a inputrc config option to set the func used for ReadFile operations.
type Error ¶
type Error string
Error is a error.
const ( // ErrBindMissingClosingQuote is the bind missing closing quote error. ErrBindMissingClosingQuote Error = `bind missing closing quote` // ErrMissingColon is the missing : error. ErrMissingColon Error = "missing :" // ErrMacroMissingClosingQuote is the macro missing closing quote error. ErrMacroMissingClosingQuote Error = `macro missing closing quote` // ErrInvalidKeymap is the invalid keymap error. ErrInvalidKeymap Error = "invalid keymap" // ErrInvalidEditingMode is the invalid editing mode error. ErrInvalidEditingMode Error = "invalid editing mode" // ErrElseWithoutMatchingIf is the $else without matching $if error. ErrElseWithoutMatchingIf Error = "$else without matching $if" // ErrEndifWithoutMatchingIf is the $endif without matching $if error. ErrEndifWithoutMatchingIf Error = "$endif without matching $if" // ErrUnknownModifier is the unknown modifier error. ErrUnknownModifier Error = "unknown modifier" )
Errors.
type Handler ¶
type Handler interface { // ReadFile reads a file. ReadFile(name string) ([]byte, error) // Do handles $constructs. Do(typ string, param string) error // Set sets the value. Set(name string, value interface{}) error // Get gets the value. Get(name string) interface{} // Bind binds a key sequence to an action for the current keymap. Bind(keymap, sequence, action string, macro bool) error }
Handler is the handler interface.
type Option ¶
type Option func(*Parser)
Option is a parser option.
func WithHaltOnErr ¶
WithHaltOnErr is a parser option to set halt on every encountered error.
func WithStrict ¶
WithStrict is a parser option to set strict keymap parsing.
type ParseError ¶
ParseError is a parse error.
func (*ParseError) Error ¶
func (err *ParseError) Error() string
Error satisfies the error interface.
func (*ParseError) Unwrap ¶
func (err *ParseError) Unwrap() error
Unwrap satisfies the errors.Unwrap call.