Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.
Clone or download
Latest commit f18d04e Aug 26, 2018
Permalink
Failed to load latest commit information.
.github Update ISSUE_TEMPLATE Jun 24, 2018
_example Rearrange example scripts and tools Jun 21, 2018
_tools Refactor FilePathCompleter Jun 24, 2018
completer Fix FilePathCompleter Jun 24, 2018
.gitignore Initial commit Jul 3, 2017
CHANGELOG.md Fix CHANGELOG Jun 28, 2018
Gopkg.lock Support CJK and Cyrillic characters Jun 21, 2018
Gopkg.toml Support CJK and Cyrillic characters Jun 21, 2018
LICENSE Update LICENSE Jul 16, 2017
Makefile Add some tests Feb 15, 2018
README.md Update README Aug 26, 2018
buffer.go Support CJK and Cyrillic characters Jun 21, 2018
buffer_test.go Support CJK and Cyrillic characters Jun 21, 2018
completion.go Delete break line characters from Suggests Jun 24, 2018
completion_test.go Fix misspell error Feb 19, 2018
document.go Update CHANGELOG for v0.2.2 release. (#84) Jun 28, 2018
document_test.go Add option to customize insertion points for completions Jun 23, 2018
emacs.go Fix ControlL keybind Feb 19, 2018
emacs_test.go Support CJK and Cyrillic characters Jun 21, 2018
filter.go Revert "Move suggest filters to github.com/c-bata/filter package" Jun 24, 2018
filter_test.go Add prompt.Input and prompt.Choose Aug 9, 2017
history.go Fix some lint errors Feb 13, 2018
history_test.go Refactor tests for history Oct 11, 2017
input.go Refactor project structure Jun 20, 2018
input_posix.go use fresh /dev/tty fd for stdin in input parser Aug 12, 2018
input_posix_test.go Rename files Jun 20, 2018
input_windows.go Refactor project structure Jun 20, 2018
key.go Fix a godoc description Feb 16, 2018
key_bind.go add ascii-code-bind-option-and-find-current-word-end Apr 11, 2018
key_bind_func.go Update CHANGELOG for v0.2.2 release. (#84) Jun 28, 2018
key_string.go Update key_stringer.go by latest stringer to fix lint errors Feb 14, 2018
option.go Update CHANGELOG for v0.2.2 release. (#84) Jun 28, 2018
output.go Update CHANGELOG for v0.2.2 release. (#84) Jun 28, 2018
output_posix.go Separate VT100 writer Jun 20, 2018
output_vt100.go Update CHANGELOG for v0.2.2 release. (#84) Jun 28, 2018
output_vt100_test.go Separate VT100 writer Jun 20, 2018
output_windows.go Separate VT100 writer Jun 20, 2018
prompt.go Add option to customize insertion points for completions Jun 23, 2018
render.go Add option to customize insertion points for completions Jun 23, 2018
render_test.go Refactor variable names Aug 12, 2017
shortcut.go Refactor project structure Jun 20, 2018
signal_posix.go windows support Feb 12, 2018
signal_windows.go Add hundling to stopHandleSignalCh Feb 12, 2018

README.md

go-prompt

Go Report Card Software License Backers on Open Collective Sponsors on Open Collective

A library for building powerful interactive prompts inspired by python-prompt-toolkit, making it easier to build cross-platform command line tools using Go.

package main

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

func completer(d prompt.Document) []prompt.Suggest {
	s := []prompt.Suggest{
		{Text: "users", Description: "Store the username and age"},
		{Text: "articles", Description: "Store the article text posted by user"},
		{Text: "comments", Description: "Store the text commented to articles"},
	}
	return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}

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

Projects using go-prompt

Features

Powerful auto-completion

demo

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

Flexible options

go-prompt provides many options. Please check option section of GoDoc for more details.

options

Keyboard Shortcuts

Emacs-like keyboard shortcuts are available by default (these also are the default shortcuts in Bash shell). You can customize and expand these shortcuts.

keyboard shortcuts

Key Binding Description
Ctrl + A Go to the beginning of the line (Home)
Ctrl + E Go to the end of the line (End)
Ctrl + P Previous command (Up arrow)
Ctrl + N Next command (Down arrow)
Ctrl + F Forward one character
Ctrl + B Backward one character
Ctrl + D Delete character under the cursor
Ctrl + H Delete character before the cursor (Backspace)
Ctrl + W Cut the word before the cursor to the clipboard
Ctrl + K Cut the line after the cursor to the clipboard
Ctrl + U Cut the line before the cursor to the clipboard
Ctrl + L Clear the screen

History

You can use Up arrow and Down arrow to walk through the history of commands executed.

History

Multiple platform support

We have confirmed go-prompt works fine in the following terminals:

  • iTerm2 (macOS)
  • Terminal.app (macOS)
  • Command Prompt (Windows)
  • gnome-terminal (Ubuntu)

Links

Author

Masashi Shibata

Supporting go-prompt

Contributors

This project exists thanks to all the people who contribute.

Backers and Sponsors (OpenCollective)

Started getting support via opencollective. If you support this project by becoming a sponsor, your logo will show up here with a link to your website.

Become a backer

License

This software is licensed under the MIT license, see LICENSE for more information.