fixed
Go to file
c-bata b5d7d9eae3 Refactor emacs keybind 2017-08-15 01:50:33 +09:00
_example Update example 2017-08-15 01:48:07 +09:00
_tools Update README and Add DEVELOPER_GUIDE 2017-08-15 01:47:46 +09:00
.gitignore Initial commit 2017-07-03 23:36:56 +09:00
DEVELOPER_GUIDE.md Update README and Add DEVELOPER_GUIDE 2017-08-15 01:47:46 +09:00
LICENSE Update LICENSE 2017-07-16 13:51:31 +09:00
Makefile Rename package 2017-08-08 00:19:51 +09:00
README.md Update README and Add DEVELOPER_GUIDE 2017-08-15 01:47:46 +09:00
bisect.go Add tests for bisect 2017-08-15 01:50:21 +09:00
bisect_test.go Add tests for bisect 2017-08-15 01:50:21 +09:00
buffer.go Replace panic to log.Print 2017-08-06 15:21:14 +09:00
buffer_test.go Move go files to project root 2017-07-18 05:27:57 +09:00
completion.go Run fmt 2017-08-15 01:50:04 +09:00
completion_test.go Run fmt 2017-08-15 01:50:04 +09:00
console_interface.go Add refactor change 2017-08-04 16:23:18 +09:00
document.go Run fmt 2017-08-15 01:50:04 +09:00
document_test.go Move go files to project root 2017-07-18 05:27:57 +09:00
emacs.go Refactor emacs keybind 2017-08-15 01:50:33 +09:00
emacs_test.go Refactor emacs keybind 2017-08-15 01:50:33 +09:00
filter.go Add prompt.Input and prompt.Choose 2017-08-10 01:06:42 +09:00
filter_test.go Add prompt.Input and prompt.Choose 2017-08-10 01:06:42 +09:00
history.go Fix history clear 2017-08-04 20:33:28 +09:00
input.go Alter the argument of completer to Document 2017-08-13 16:43:10 +09:00
key.go Add refactor change 2017-08-04 16:23:18 +09:00
key_bind.go Refactor emacs keybind 2017-08-15 01:50:33 +09:00
key_string.go Move go files to project root 2017-07-18 05:27:57 +09:00
option.go Add OptionKeyBindMode 2017-08-13 13:42:40 +09:00
prompt.go Run fmt 2017-08-15 01:50:04 +09:00
render.go Refactor variable names 2017-08-12 18:59:10 +09:00
render_test.go Refactor variable names 2017-08-12 18:59:10 +09:00
vt100_input.go Refactor completions 2017-08-09 21:33:47 +09:00
vt100_output.go Add flush 2017-08-11 18:24:44 +09:00

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.

demo

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

Projects using go-prompt

Features

Flexible options

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

options

Keyboard Shortcuts

Emacs-like keyboard shortcut is available by default (it's also default shortcuts in Bash shell). You can customize and expand these shortcuts.

keyboard shortcuts

KeyBinding 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/delete the Line before the cursor to the clipboard.

Easy to use

Usage is like this:

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)
}

More practical example is available from _example directory and a source code of kube-prompt.

Author

Masashi Shibata

LICENSE

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