gnureadline

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

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

Go to latest
Published: Jul 20, 2021 License: GPL-3.0 Imports: 6 Imported by: 4

README

Build Status GoDoc

Go bindings to the GNU Readline library

This provides command-line entry, editing and command history

Synopsis

package main
import (
    "code.google.com/p/go-gnureadline"
    "fmt"
    "os"
)

const HISTORY_FILE string = "my.history"

func main() {
     var err error
     term := os.Getenv("TERM")
     gnureadline.ReadHistory(HISTORY_FILE)
     gnureadline.StifleHistory(10)  // Maximum 10 history entries
     gnureadline.ReadInitFile(".inputrc")  // Read in a keybinding initialization file
     line := ""
     for i:=1; err == nil && line != "quit"; i++ {
             line, err = gnureadline.Readline(fmt.Sprintf("Enter something [%d]: ", i), true)
             switch line {
                case "vi":
                        gnureadline.Rl_editing_mode_set(Vi)
                case "emacs":
                        gnureadline.Rl_editing_mode_set(Emacs)
                case "insert":
                        gnureadline.Rl_insert_mode_set(true)
                case "overwrite":
                        gnureadline.Rl_insert_mode_set(false)
                }
                fmt.Printf("You typed: %s\n", line)
     }
     fmt.Printf("History length %d\n",  gnureadline.HistoryLength())
     fmt.Printf("History max entries %d\n",  gnureadline.HistoryMaxEntries())
     gnureadline.WriteHistory(gnureadline.HISTORY_FILE)
     gnureadline.Rl_reset_terminal(term)
}

Description

readline will read a line from the terminal and return it, using prompt as a prompt. If prompt he empty string, no prompt is issued. The line returned has the final newline removed, so only the text of the line remains.

readline offers editing capabilities while the user is entering the line. By default, the line editing commands are similar to those of emacs. A vi-style line editing interface is also available.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHistory

func AddHistory(line string)

Place LINE at the end of the history list.

The associated data field (if any) is set to NULL.

func ClearHistory

func ClearHistory()

Clear the history list and start over.

func CompleterWordBreakCharacters

func CompleterWordBreakCharacters() string

The list of characters that signal a break between words. The default list is the contents of rl_basic_word_break_characters.

func CompleterWordBreakCharacters_

func CompleterWordBreakCharacters_(break_chars string)

Setter for CompleteWordBreakCharacters

func CompletionMatches

func CompletionMatches(text string,
	entry_func func(text string, state int) string) []string

func GetKeymapNameFromEditMode

func GetKeymapNameFromEditMode() string

*** Should we include? ****

func HistoryBase

func HistoryBase() int

The logical `base' of the history array. It defaults to 1.

func HistoryBase_

func HistoryBase_(base int) int

Setter for HistoryBase

func HistoryCommentChar

func HistoryCommentChar() rune

During tokenization, if this character is seen as the first character

of a word, then it, and all subsequent characters upto a newline are
ignored.  For a Bourne shell, this should be '#'.  Bash special cases
the interactive comment character to not be a comment delimiter.

func HistoryCommentChar_

func HistoryCommentChar_(c rune) rune

Setter for HistoryCommentChar

func HistoryExpansionChar

func HistoryExpansionChar() rune

The character that represents the start of a history expansion

request.  This is usually `!'.

func HistoryExpansionChar_

func HistoryExpansionChar_(c rune) rune

Setter for HistoryExpansionChar

func HistoryIsStifled

func HistoryIsStifled() bool

Return true if the history is stifled, false if it is not.

func HistoryLength

func HistoryLength() int

The number of strings currently stored in the history list.

func HistoryMaxEntries

func HistoryMaxEntries() int

If HISTORY_STIFLED is non-zero, then this is the maximum number of

entries to remember.

func HistorySetPos

func HistorySetPos(pos int)

Set the position in the history list to POS.

func HistorySubstChar

func HistorySubstChar() rune

The character that represents the start of a history expansion

request.  This is usually `!'.

func HistorySubstChar_

func HistorySubstChar_(c rune) rune

Setter for HistorySubstChar

func HistoryTotalBytes

func HistoryTotalBytes() int

Return the number of bytes that the primary history entries are using.

This just adds up the lengths of the_history->lines.

func LineBuffer

func LineBuffer() string

func ParseAndBind

func ParseAndBind(s string) bool

Read the binding command from STRING and perform it. A key binding command looks like: Keyname: function-name\0, a variable binding command looks like: set variable value. A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark.

True is returned if there wasn't an error, false otherwise.

func ReReadInitFile

func ReReadInitFile() error

Re-read the current keybindings file.

func ReadHistory

func ReadHistory(filename string) int

Add the contents of FILENAME to the history list, a line at a time.

If FILENAME is '', then read from ~/.history.  Returns 0 if
successful, or errno if not.

func ReadInitFile

func ReadInitFile(filename string) error

func Readline

func Readline(prompt string, add_history ...bool) (string, error)

Readline will read a line from the terminal and return it, using prompt as a prompt. If prompt the empty string, no prompt is issued. The line returned has the final newline removed, so only the text of the line remains.

Readline offers editing capabilities while the user is entering the line. By default, the line editing commands are similar to those of emacs. A vi-style line editing interface is also available.

func RemoveHistory

func RemoveHistory(which int) error

RemoveHistory removes the history entry "which". The removed element is free'd

func Rl_deprep_terminal

func Rl_deprep_terminal()

Undo the effects of `rl_prep_terminal()', leaving the terminal in the state in which it was before the most recent call to `rl_prep_terminal()'.

func Rl_ding

func Rl_ding() int

Ring the terminal bell, obeying the setting of `bell-style'.

func Rl_gnu_readline_p

func Rl_gnu_readline_p() bool

True if this is real GNU readline. (It's probably true here.)

func Rl_insert_mode

func Rl_insert_mode() bool

Insert or overwrite mode for emacs mode. 1 means insert mode; 0 means

overwrite mode.  Reset to insert mode on each input line.

func Rl_insert_mode_set

func Rl_insert_mode_set(set_insert bool) bool

func Rl_prefer_env_winsize

func Rl_prefer_env_winsize() int

If non-zero, Readline gives values found in the `LINES' and `COLUMNS' environment variables greater precedence than values fetched from the kernel when computing the screen dimensions.

func Rl_prep_terminal

func Rl_prep_terminal(meta_flag int)

Modify the terminal settings for Readline's use, so `readline()' can read a single character at a time from the keyboard. The META_FLAG argument should be non-zero if Readline should read eight-bit input.

func Rl_read_init_file

func Rl_read_init_file(filename string) int

Read keybindings and variable assignments from FILENAME

func Rl_readline_library_version

func Rl_readline_library_version() string

The version number of this revision of the library. e.g. "6.2"

func Rl_readline_name

func Rl_readline_name() string

This variable is set to a unique name by each application using Readline. The value allows conditional parsing of the inputrc file

func Rl_readline_terminal_name

func Rl_readline_terminal_name() string

The terminal type, used for initialization. If not set by the application, Readline sets this to the value of the `TERM' environment variable the first time it is called.

func Rl_readline_version

func Rl_readline_version() int

An integer encoding the current version of the library. The encoding is of the form 0xMMMM, where MM is the two-digit major version number, and MM is the two-digit minor version number. For example, for Readline-4.2, `rl_readline_version' would have the value 0x0402.

func Rl_reset_terminal

func Rl_reset_terminal(terminal_name string) int

Reinitialize Readline's idea of the terminal settings using TERMINAL_NAME as the terminal type (e.g., `vt100'). If TERMINAL_NAME is the empty string, the value of the `TERM' environment variable is used.

func Rl_resize_terminal

func Rl_resize_terminal()

Update Readline's internal screen size by reading values from the kernel.

func Rl_variable_value

func Rl_variable_value(variable string) string

Return a string representing the value of the Readline variable VARIABLE. For boolean variables, this string is either `on' or `off'.

func SetAttemptedCompletionFunction

func SetAttemptedCompletionFunction(entry_func func(text string,
	start, end int) []string)

func SetKeymapNameFromEditMode

func SetKeymapNameFromEditMode()

func StifleHistory

func StifleHistory(max int)

Stifle the history list, remembering only MAX number of entries.

func UnstifleHistory

func UnstifleHistory() int

Stop stifling the history. This returns the previous amount the

history was stifled by.  The value is positive if the history was
stifled, negative if it wasn't.

func UsingHistory

func UsingHistory()

Begin a session in which the history functions might be used. This

just initializes the interactive variables.

func WhereHistory

func WhereHistory() int

Returns the number which says what history element we are now

looking at.

func WriteHistory

func WriteHistory(filename string) int

Write the current history to FILENAME. If FILENAME is "",

then write the history list to ~/.history.  Values returned
are as in ReadHistory().

Types

type EditingMode

type EditingMode int
const (
	Vi    EditingMode = 0
	Emacs EditingMode = 1
)

func Rl_editing_mode

func Rl_editing_mode() EditingMode

Says which editing mode readline is currently using: Emacs or Vi

func Rl_editing_mode_set

func Rl_editing_mode_set(new_value EditingMode) EditingMode

Set editing mode readline is currently using. 1 means emacs mode;

0 means vi mode.

Directories

Path Synopsis
+build ignore +build ignore +build ignore
+build ignore +build ignore +build ignore

Jump to

Keyboard shortcuts

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