Help us shape the future of Go! Take the 2026 Go Developer Survey

readline

package module
v0.0.0-...-1965204 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: Apache-2.0 Imports: 5 Imported by: 3

README

GoDoc

The readline package provides an easier-to-use API on top of GNU readline library.

Documentation

Overview

Package readline provides an easier-to-use wrapper around creadline.

Example:

readline.Init(readline.Opts{Name: "myapp"})
for {
  line = readline.Readline("> ")
  processInput(line)
  readline.AddHistory(line)
}

Signal handling

Readline intercepts SIGINT (Ctrl-C). On SIGINT, the ongoing Readline call aborts and returns an Interrupt error.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Interrupt is returned by Readline on SIGINT (i.e., Control-C keypress).
	Interrupt = creadline.Interrupt
)

Functions

func AddHistory

func AddHistory(str string) (err error)

AddHistory adds a history entry. It appends the entry both inmemory list and Opts.HistoryPath. It may truncate the history list if it grows larger than Opts.MaxHistoryLen. Thread-hostile.

REQUIRES: Init has been called.

func GetScreenSize

func GetScreenSize() (int, int)

GetScreenSize returns the current screen size, (#rows, #cols). It returns nonpositive values when the stdout is not a terminal, or on any error.

func Init

func Init(o Opts) error

Init sets the configuration parameter. It must be called at least once before calling any other function.

Thread-hostile.

func Readline

func Readline(prompt string) (string, error)

Readline reads one line. On SIGINT, it returns an Inturrupt error. Thread-hostile.

REQUIRES: Init has been called.

Types

type Opts

type Opts struct {
	// Name is the name of the application. It is used to generate the default
	// history pathname (~/.NAME_history). It may be empty.
	Name string
	// InitPath is the name of the readline init file. It may be empty.
	//
	// https://tiswww.case.edu/php/chet/readline/readline.html#SEC9
	InitPath string
	// HistoryPath is the name of the readline history file. If "" and Name is
	// nonempty, then its value will be ~/.NAME_history. If both HistoryPath and
	// Name are empty, then its value will be ~/.history.
	HistoryPath string
	// MaxHistoryLen is the maximum number of history entries to retain. If <= 0,
	// the last 10000 entries will be retained.
	MaxHistoryLen int
	// ExpandHistory enables history expansion, such as "!tok".
	ExpandHistory bool

	// Completer is invoked to complete a line. It may be nil.  The arg line is
	// the current input line. Args start and end are the start and limit offset
	// of the word being completed, respectively.
	Completer func(line string, start, end int) []string
}

Opts define options for the readline package.

Directories

Path Synopsis
Package creadline provides low-level cgo interface to GNU readline.
Package creadline provides low-level cgo interface to GNU readline.

Jump to

Keyboard shortcuts

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