fixed
Go to file
Nao YONASHIRO 98e83ff8e4 feat: support resize window on windows 2018-02-20 22:40:16 +09:00
.github Add ISSUE_TEMPLATE 2018-02-14 22:56:14 +09:00
_example Remove DEVELOPER_GUIDE and Update README 2018-02-14 22:56:34 +09:00
_tools Add some refactor changes 2018-02-12 19:36:21 +09:00
.gitignore Initial commit 2017-07-03 23:36:56 +09:00
CHANGELOG.md Update CHANGELOG 2018-02-15 03:12:16 +09:00
Gopkg.lock Update go-tty to fix GetWinsize on windows 2018-02-15 01:45:23 +09:00
Gopkg.toml Vendoring with golang/dep 2018-02-14 16:56:33 +09:00
LICENSE Update LICENSE 2017-07-16 13:51:31 +09:00
Makefile Add some tests 2018-02-15 18:15:32 +09:00
README.md Update README 2018-02-15 23:50:39 +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 Fix some lint errors 2018-02-14 01:14:22 +09:00
completion_test.go Fix misspell error 2018-02-19 23:26:28 +09:00
console_interface.go Add godoc comments 2018-02-15 17:34:37 +09:00
document.go Add some tests 2018-02-15 18:15:32 +09:00
document_test.go Add some tests 2018-02-15 18:15:32 +09:00
emacs.go Fix ControlL keybind 2018-02-19 19:55:32 +09:00
emacs_test.go Refactor emacs keybind 2017-08-15 01:50:33 +09:00
filter.go Add a comment to some exported functions 2017-08-18 01:40:41 +09:00
filter_test.go Add prompt.Input and prompt.Choose 2017-08-10 01:06:42 +09:00
history.go Fix some lint errors 2018-02-14 01:14:22 +09:00
history_test.go Refactor tests for history 2017-10-11 12:01:40 +09:00
input.go Fix Input and Choose 2017-08-18 02:12:13 +09:00
key.go Fix a godoc description 2018-02-16 14:48:01 +09:00
key_bind.go Add godoc comments 2018-02-15 17:34:37 +09:00
key_string.go Update key_stringer.go by latest stringer to fix lint errors 2018-02-14 13:22:22 +09:00
option.go Fix typo 2018-02-18 18:18:42 +09:00
posix_input.go Write godoc for ConsoleWriter and ConsoleParser 2018-02-14 12:40:37 +09:00
posix_input_test.go Add some tests 2018-02-15 18:15:32 +09:00
posix_output.go Delete unnecessary color setting 2018-02-18 22:31:41 +09:00
posix_output_test.go Add some tests 2018-02-15 18:15:32 +09:00
prompt.go Remove ControlSpace handling 2018-02-19 23:41:34 +09:00
render.go Refactor render.go 2018-02-19 19:56:10 +09:00
render_test.go Refactor variable names 2017-08-12 18:59:10 +09:00
signal_posix.go windows support 2018-02-12 19:20:57 +09:00
signal_windows.go feat: support resize window on windows 2018-02-20 22:40:16 +09:00
windows_input.go feat: improve rendering performance on windows (#47) 2018-02-18 22:27:59 +09:00
windows_output.go feat: improve rendering performance on windows (#47) 2018-02-18 22:27:59 +09:00

go-prompt

Go Report Card Software License

Library for building a powerful interactive prompt, inspired by python-prompt-toolkit. More easy to build a multi-platform binary of the command line tools because written in Golang.

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 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.
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 confirmed go-prompt works fine on following terminals:

  • iTerm2 (macOS)
  • Terminal.app (macOS)
  • Command Prompt (Windows)
  • GNU Terminal (Ubuntu)

Author

Masashi Shibata

LICENSE

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