editor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package editor provides simple readline functionality for Go programs.

Index

Constants

This section is empty.

Variables

View Source
var DefaultEditor = NewEditor(os.Stdin, os.Stdout)

DefaultEditor is the default Editor.

Functions

func GetLine

func GetLine(prompt string) (string, error)

GetLine gets a line from the terminal.

func GetPass

func GetPass(prompt string) (string, error)

GetPass gets a password from the terminal.

Types

type Editor

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

Editor is a command line editor with history and completion handling.

func NewEditor

func NewEditor(in *os.File, out *os.File) *Editor

NewEditor creates a new editor.

func (*Editor) GetLine

func (self *Editor) GetLine(prompt string) (string, error)

GetLine gets a line from the terminal.

func (*Editor) GetPass

func (self *Editor) GetPass(prompt string) (string, error)

GetPass gets a password from the terminal.

func (*Editor) History

func (self *Editor) History() *History

History returns the editor's command line history.

func (*Editor) SetCompletionHandler

func (self *Editor) SetCompletionHandler(handler func(line string) []string)

SetCompletionHandler sets a completion handler.

type History

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

History maintains a buffer of command lines.

func NewHistory

func NewHistory() *History

NewHistory creates a new history buffer.

func (*History) Add

func (self *History) Add(line string)

Add adds a new command line to the history buffer.

func (*History) Clear

func (self *History) Clear()

Clear clears all command lines from the history buffer.

func (*History) Delete

func (self *History) Delete(id int)

Delete deletes a command line from the history buffer. The special id's of 0 or -1 mean to delete the first or last command line respectively.

func (*History) Enum

func (self *History) Enum(id int, fn func(id int, line string) bool)

Enum enumerates all command lines in the history buffer starting at id. The special id's of 0 or -1 mean to start the enumeration with the first or last command line respectively.

func (*History) Get

func (self *History) Get(id int, dir int) (int, string)

Get gets a command line from the history buffer.

Command lines are identified by an integer id. The special id's of 0 or -1 mean to retrieve the first or last command line respectively. The dir parameter is used to determine which command line to retrieve relative to the one identified by id: 0 is the current command line, +1 is the next command line, -1 is the previous command line, etc. When retrieving command lines the history is treated as a circular buffer.

func (*History) Len

func (self *History) Len() int

Len returns the length of the history buffer.

func (*History) Read

func (self *History) Read(reader io.Reader) (err error)

Read reads command lines from a reader into the history buffer.

func (*History) Reset

func (self *History) Reset()

Reset fully resets the history buffer.

func (*History) SetCap

func (self *History) SetCap(cap int)

SetCap sets the capacity (number of command lines) of the history buffer.

func (*History) Write

func (self *History) Write(writer io.Writer) (err error)

Write writes command lines to a writer from the history buffer.

Jump to

Keyboard shortcuts

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