linenoise

package module
v3.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: BSD-2-Clause Imports: 4 Imported by: 4

README

PkgGoDev GitHub Actions CI Status Code Climate Maintainability Codebeat badge GitHub Actions CodeQL Status

ExampleCI StatusLicense


go-linenoise is a Go package wrapping the linenoise C library. Since v3 we use @yhirose fork with UTF-8 support.

This is fork of go.linenoise package used in EK projects.

Example

package main

// ////////////////////////////////////////////////////////////////////////// //

import (
  "fmt"

  linenoise "github.com/essentialkaos/go-linenoise/v3"
)

// ////////////////////////////////////////////////////////////////////////// //

func main() {
  input, err := linenoise.Line("> ")

  if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
  }

  fmt.Printf("Input: %s\n", input)
}

CI Status

Branch Status
master CI
develop CI

License

All code in this repository is licensed under a BSD license. This project wraps linenoise which is written by Salvatore Sanfilippo and Pieter Noordhuis. The license for linenoise is included in the files linenoise.c and linenoise.h. For all other files please read the LICENSE file.

Documentation

Overview

Package linenoise wraps the linenoise library (https://github.com/yhirose/linenoise).

Index

Constants

This section is empty.

Variables

View Source
var ErrKillSignal = errors.New("Prompt was quited with a kill signal")

ErrKillSignal is returned returned by Line() when a user quits from prompt. This occurs when the user enters ctrl+C or ctrl+D.

Functions

func AddHistory

func AddHistory(line string) error

AddHistory adds a line to history. Returns non-nil error on fail

func Clear

func Clear()

Clear clears the screen

func Line

func Line(prompt string) (string, error)

Line displays given string and returns line from user input

func LoadHistory

func LoadHistory(filename string) error

LoadHistory loads from file with given filename. Returns non-nil error on fail

func PrintKeyCodes

func PrintKeyCodes()

PrintKeyCodes puts linenoise in key codes debugging mode. Press keys and key combinations to see key codes. Type 'quit' at any time to exit. PrintKeyCodes blocks until user enters 'quit'.

func SaveHistory

func SaveHistory(filename string) error

SaveHistory saves from file with given filename. Returns non-nil error on fail

func SetCompletionHandler

func SetCompletionHandler(h CompletionHandler)

SetCompletionHandler sets the CompletionHandler to be used for completion (using Tab key)

You can pass nil as the handler to remove the previously set handler

func SetHintColor

func SetHintColor(color uint8, bold bool) error

SetHintColor sets hint text color to color with given ANSI code

Color codes: https://github.com/essentialkaos/fmtc/wiki#816-colors

func SetHintHandler

func SetHintHandler(h HintHandler)

SetHintHandler sets the HintHandler to be used for input hints

You can pass nil as the handler to remove the previously set handler

func SetHistoryCapacity

func SetHistoryCapacity(capacity int) error

SetHistoryCapacity changes the maximum length of history. Returns non-nil error on fail

func SetMaskMode added in v3.4.0

func SetMaskMode(enable bool)

SetMaskMode sets mask mode. When it is enabled, instead of the input that the user is typing, the terminal will just display a corresponding number of asterisks, like "****". This is useful for passwords and other secrets that should not be displayed.

func SetMultiline

func SetMultiline(enable bool)

SetMultiline sets linenoise to multiline or single line. In multiline mode the user input will be wrapped to a new line when the length exceeds the amount of available rows in the terminal.

Types

type CompletionHandler

type CompletionHandler func(input string) []string

CompletionHandler provides possible completions for given input

type HintHandler

type HintHandler func(input string) string

HintHandler provides hint for user input

Jump to

Keyboard shortcuts

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