linoise

package module
v0.0.0-...-93e540f Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2013 License: BSD-2-Clause Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-linoise
==========

**go-linoise** is a simple library for line editing, as replacement to GNU
Readline. It is inspired in [linenoise][4].

Features:

+ Licensed under BSD, a liberal license
+ Unicode support
+ History
+ Multi-line editing
+ Facilitate reading related to questions where the answers by default are set
 to bold


## Installation

In the first, there is to install [go-term][5]. And then:

	$ goinstall github.com/kless/go-linoise/linoise


## Configuration

There are several values by default:

+ In the buffer: *BufferCap*, *BufferLen*.
+ In the history file: *HistoryCap*, *HistoryPerm*.
+ In the main code: *PS1*, *PS2*.


## Operating instructions

Read files *linoise_test.go* and *question_test.go*.


## Copyright and licensing

***Copyright 2010  The "go-linoise" Authors***  
See file AUTHORS and CONTRIBUTORS (if any).

Licensed under **Simplified BSD License**.  
See file LICENSE.


## Contact

To contact, send e-mail through [github][1].


## Known bugs

To reporting bugs, please login and create a new issue [here][2].


## Credits and acknowledgments

For credits, see file AUTHORS and CONTRIBUTORS (if any).

I would like to thank Salvatore Sanfilippo for building *linenoise*, and to do it
under a liberal license.


## ChangeLog

For changes between releases, see file NEWS; and for changes between the commits,
see the [commit history][3].


* * *
*Generated by [gowizard](http://github.com/kless/gowizard)*


[1]: http://github.com/kless
[2]: http://github.com/kless/go-linoise/issues
[3]: http://github.com/kless/go-linoise/commits/master
[4]: http://github.com/antirez/linenoise
[5]: http://github.com/kless/go-term

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BufferCap = 4096
	BufferLen = 64 // Initial length
)

Buffer size

View Source
var (
	ErrCtrlD = fmt.Errorf("Interrumpted (Ctrl-d)")

	ErrEmptyHist  = fmt.Errorf("history: empty")
	ErrNilElement = fmt.Errorf("history: no more elements")
)
View Source
var (
	HistoryCap         = 500  // Capacity
	HistoryPerm uint32 = 0600 // History file permission
)

Values by default

View Source
var (
	PS1 = "linoise$ "
	PS2 = "> "
)

Values by default for prompts.

View Source
var (
	QuestionPrefix      = " + " // String placed before of questions
	QuestionErrPrefix   = "  "  // String placed before of error messages
	QuestionTrueString  = "y"   // String to represent 'true' by default
	QuestionFalseString = "n"   // Idem but for 'false'

	QuestionFloatFmt  byte = 'g' // Format for float numbers
	QuestionFloatPrec int  = -1  // Precision for float numbers
)

Values by default

View Source
var ExtraBoolString = make(map[string]bool)

To pass strings in another languages.

Functions

func Init

func Init()

Init sets up our terminal for use. It must be run before anything else.

func NewHistory

func NewHistory(filename string) (*history, error)

Creates a new history using the maximum length by default.

func NewHistorySize

func NewHistorySize(filename string, size int) (*history, error)

Creates a new history whose buffer has the specified size, which must be greater than zero.

Types

type Line

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

Represents a line.

func NewLine

func NewLine(hist *history) *Line

Gets a line type using the primary prompt by default. Sets the TTY raw mode.

func NewLinePrompt

func NewLinePrompt(prompt string, ansiLen int, hist *history) *Line

Gets a line type using the given prompt as primary. Sets the TTY raw mode. 'ansiLen' is the length of ANSI codes that the prompt could have.

func (*Line) Read

func (ln *Line) Read() (line string, err error)

Reads charactes from input to write them to output, allowing line editing. The errors that could return are to indicate if Ctrl-D was pressed, and for both input / output errors.

func (*Line) RestoreTerm

func (ln *Line) RestoreTerm()

Restores terminal settings so it is disabled the raw mode.

type Question

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

func NewQuestion

func NewQuestion() *Question

Gets a question type.

func (*Question) Read

func (q *Question) Read(prompt string) (answer string, err error)

Prints the prompt waiting to get a string not empty.

func (*Question) ReadBool

func (q *Question) ReadBool(prompt string, defaultAnswer bool) (answer bool, err error)

Prints the prompt waiting to get a string that represents a boolean.

func (*Question) ReadChoice

func (q *Question) ReadChoice(prompt string, a []string) (answer string, err error)

Prints the prompt waiting to get an element from array `a`. If input is nil then it returns the first element of `a`.

func (*Question) ReadChoiceDefault

func (q *Question) ReadChoiceDefault(prompt string, a []string, defaultAnswer uint) (answer string, err error)

Prints the prompt waiting to get an element from array `a`. If input is nil then it returns the answer by default which is the position inner array.

func (*Question) ReadFloat

func (q *Question) ReadFloat(prompt string) (answer float64, err error)

Prints the prompt waiting to get a float number.

func (*Question) ReadFloatDefault

func (q *Question) ReadFloatDefault(prompt string, defaultAnswer float64) (answer float64, err error)

Prints the prompt waiting to get a float number. If input is nil then it returns the answer by default.

func (*Question) ReadInt

func (q *Question) ReadInt(prompt string) (answer int, err error)

Prints the prompt waiting to get an integer number.

func (*Question) ReadIntDefault

func (q *Question) ReadIntDefault(prompt string, defaultAnswer int) (answer int, err error)

Prints the prompt waiting to get an integer number. If input is nil then it returns the answer by default.

func (*Question) ReadString

func (q *Question) ReadString(prompt string) (answer string, err error)

Prints the prompt waiting to get a string.

func (*Question) ReadStringDefault

func (q *Question) ReadStringDefault(prompt, defaultAnswer string) (answer string, err error)

Prints the prompt waiting to get a string. If input is nil then it returns the answer by default.

func (*Question) RestoreTerm

func (q *Question) RestoreTerm()

Restores terminal settings.

Jump to

Keyboard shortcuts

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