readline

package module
v0.0.0-...-458bddc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2017 License: MIT Imports: 12 Imported by: 0

README

readline

Golang imitation of library readline for command line operations, including line-editing shortcut keys and auto-completion.

Support multi-byte encoding.

Usage

Implementation

Completable elements may include commands, arguments, file names and other entities, depending on the specific interpreter and its configuration.

TODO

feature

  • add self-defined auto-complete interface.

  • add auto-complete interface for list files and directories.

  • use completer

  • multi-line input strings, single-line input strings that are long enough to wrap,

  • [o] separate it to a library

  • can not auto-complete multi sub-commands as options, like git add --a --b a.c, here, '--a', '--b' and 'a.c(fs-completer)' are sub-commands.

  • Make pretty output formate of candidates

  • Add test case

bug

  • can not auto-complete 'ls //usr/l'
  • fs-completer: when tab enter and complete to 'ls /usr/ ', there is an extra space after '/', which make user to delete this space and then enter space to auto-complete for the next path node.

Documentation

Index

Constants

View Source
const (
	CharInterrupt = 3    // Ctrl+C
	CharEOF       = 4    // Ctrl+D
	CharTab       = '\t' // 9
	CharEnter     = '\r' // 13 or 10('\n')
	CharESC       = 27   // ansi escape code
	CharBackspace = 127
)

Variables

This section is empty.

Functions

func InputLoop

func InputLoop(inst *Instance)

func ReadPassword

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.

Types

type Completer

type Completer interface {
	// contains filtered or unexported methods
}

func Cmd

func Cmd(name string, subs ...Completer) Completer

func ListFs

func ListFs() Completer

type ExecuteFunc

type ExecuteFunc func(line string, data interface{}) bool

type Instance

type Instance struct {
	Debug bool
	// contains filtered or unexported fields
}

func New

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

func (*Instance) Destroy

func (inst *Instance) Destroy()

func (*Instance) Error

func (inst *Instance) Error(v ...interface{})

func (*Instance) Errorf

func (inst *Instance) Errorf(format string, v ...interface{})

func (*Instance) Log

func (inst *Instance) Log(format string, v ...interface{})

func (*Instance) Print

func (inst *Instance) Print(v ...interface{})

func (*Instance) PrintTree

func (inst *Instance) PrintTree(w io.Writer)

func (*Instance) Printf

func (inst *Instance) Printf(format string, v ...interface{})

func (*Instance) Println

func (inst *Instance) Println(v ...interface{})

func (*Instance) SetCompleter

func (inst *Instance) SetCompleter(subs ...Completer)

func (*Instance) SetExecute

func (inst *Instance) SetExecute(f ExecuteFunc, data interface{})

type State

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

func GetState

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

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL