readliner

package module
v0.0.0-...-680157f Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 3 Imported by: 1

README

readliner

An io.Reader that uses github.com/peterh/liner to read from a tty (with command completion and editing).

This is useful for cases where you are trying to create an interactive cli (i.e. REPL) but the input is being processed by a separate entity (like an expression parser) that operates on an io.Reader.

Documentation

Overview

Package readliner implement an io.Reader that reads from a tty with history and completions.

Index

Constants

View Source
const DefaultEOL = "\r\n"

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadLiner

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

ReadLiner is an io.Reader that can read from a tty using `readline`

func New

func New(prompt, history string) *ReadLiner

New creates a new ReadLiner and sets the tty in raw mode.

`prompt` is printed before reading from each line. `history` should be the path to the history file.

func (*ReadLiner) Close

func (r *ReadLiner) Close() error

Close closes the ReadLiner and reset the TTY. If there is an history file, the current history is written to the file.

func (*ReadLiner) IsTerminal

func (r *ReadLiner) IsTerminal() bool

IsTerminal returns true if ReadLiner is operating on a terminal that supports editing (i.e. not redirected from a file)

Note that when not in terminal mode, history is disabled.

func (*ReadLiner) Newline

func (r *ReadLiner) Newline()

Newline indicate we are starting a new line (in multiline mode).

This reset the prompt to the "new line" prompt. The prompt switch to the "continuation" prompt after reading the current line.

func (*ReadLiner) Read

func (r *ReadLiner) Read(b []byte) (int, error)

Read implements io.Reader.Read

func (*ReadLiner) SetCompletions

func (r *ReadLiner) SetCompletions(completions []string, begin bool)

SetCompletions sets a `completer` with a list of completions words.

If `begin` is true, words are completed only at the beginning of the line (i.e. command names). If false, the last word of the line is completed.

func (*ReadLiner) SetContPrompt

func (r *ReadLiner) SetContPrompt(prompt string)

SetContPrompt changes the continuation `prompt` for the ReadLiner

This is used to support multiline. See description of `Newline`.

func (*ReadLiner) SetEol

func (r *ReadLiner) SetEol(eol string)

func (*ReadLiner) SetPrompt

func (r *ReadLiner) SetPrompt(prompt string)

SetPrompt changes the `prompt` for the ReadLiner

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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