VictoriaMetrics/vendor/github.com/ergochat/readline
2024-10-01 12:23:07 +02:00
..
internal app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
.check-gofmt.sh app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
.gitignore app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
complete.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
complete_helper.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
history.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
LICENSE app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
Makefile app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
operation.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
readline.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
README.md app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
runebuf.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
search.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
terminal.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
undo.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
utils.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00
vim.go app/vlogscli: add interactive command-line tool for querying VictoriaLogs 2024-10-01 12:23:07 +02:00

readline

Godoc

This is a pure Go implementation of functionality comparable to GNU Readline, i.e. line editing and command history for simple TUI programs.

It is a fork of chzyer/readline.

  • Relative to the upstream repository, it is actively maintained and has numerous bug fixes
    • See our changelog for details on fixes and improvements
    • See our migration guide for advice on how to migrate from upstream
  • Relative to x/term, it has more features (e.g. tab-completion)
  • In use by multiple projects: gopass, fq, and ircdog
package main

import (
	"fmt"
	"log"

	"github.com/ergochat/readline"
)

func main() {
	// see readline.NewFromConfig for advanced options:
	rl, err := readline.New("> ")
	if err != nil {
		log.Fatal(err)
	}
	defer rl.Close()
	log.SetOutput(rl.Stderr()) // redraw the prompt correctly after log output

	for {
		line, err := rl.ReadLine()
		// `err` is either nil, io.EOF, readline.ErrInterrupt, or an unexpected
		// condition in stdin:
		if err != nil {
			return
		}
		// `line` is returned without the terminating \n or CRLF:
		fmt.Fprintf(rl, "you wrote: %s\n", line)
	}
}