prompt
prompt is a terminal prompt library for Go for building interactive command-line interfaces. It is a maintained replacement for the archived c-bata/go-prompt, keeping the same core idea, a read loop with completion and history, while running on Linux, macOS, and Windows.
The animation is example/demo, a toy SQL shell built on this library, driven by demo.tape. Run it yourself with go run ./example/demo.
Features
- Tab completion, including fuzzy matching, with customizable suggestions and completer-chosen replacement spans
- Command history with arrow-key navigation, persistence, and reverse search (Ctrl+R)
- Emacs-style key bindings
- Multi-line input with cursor navigation
- Built-in color themes
- A small API using the functional options pattern
- Runs on Linux, macOS, and Windows
Installation
go get github.com/nao1215/promptBuilding needs Go 1.26 or later.
Quick start
Basic usage
package main
import (
"context"
"errors"
"fmt"
"log"
"github.com/nao1215/prompt"
)
func main() {
p, err := prompt.New("$ ")log.Fatal(err) } defer p.Close()
for { input, err := p.Run(context.Background()) if err != nil { if errors.Is(err, prompt.ErrEOF) { fmt.Println("Goodbye!") break } log.Printf("Error: %v\n", err) continue }
if input == "exit" { break } fmt.Printf("You entered: %s\n", input) } }
### With auto-completion
package main
import ( "context" "errors" "log" "github.com/nao1215/prompt" )