go-prompt/README.md
2017-08-12 23:43:35 +09:00

2.4 KiB

go-prompt

Library for building a powerful interactive prompt, inspired by python-prompt-toolkit. Easy building a multi-platform binary of the command line tools because built with Golang.

Similar Projects

Projects using go-prompt

Features

Powerful auto completion

demo

(This is a GIF animation of kube-prompt.)

Keyboard Shortcuts

Keyboard shortcuts

go-prompt implements the bash compatible keyboard shortcuts.

  • Ctrl+A: Go to the beginning of the line.
  • Ctrl+E: Go to the end of the line.
  • Ctrl+K: Cut the part of the line after the cursor.
  • etc...

Easy to use

Usage is like this:

package main

import (
	"fmt"
	"github.com/c-bata/go-prompt"
)

func completer(buf prompt.Buffer) []prompt.Suggest {
	s := []prompt.Suggest{
		{Text: "users", Description: "user table"},
		{Text: "sites", Description: "sites table"},
		{Text: "articles", Description: "articles table"},
	}
	return prompt.FilterHasPrefix(s, buf.Text(), true)
}

func main() {
	fmt.Println("Please select table.")
	t := prompt.Input("> ", completer)
	fmt.Println("You selected " + t)
}

More practical example is avairable from _example directory or kube-prompt.

Flexible customize

options go-prompt has many color options. All options are listed in Developer Guide.

History

up-arrow and down-arrow to walk through the command line history.

History

Other Information

  • If you want to create projects using go-prompt, you might want to look at the Getting Started.
  • If you want to contribute go-prompt, you might want to look at the Developer Guide.

Author

Masashi Shibata

LICENSE

This software is licensed under the MIT License (See LICENSE ).