fixed
Go to file
c-bata 3a148d1647 Add gh-prompt: An interactive GitHub CLI featuring auto-complete 2020-02-13 20:46:36 +09:00
.github Separate issue template 2019-07-31 22:13:43 +09:00
_example Fix http-prompt example (no exit) 2019-06-28 12:28:00 +02:00
_tools Refactor input parser 2018-12-18 03:13:07 +09:00
completer Fix logger of completer/file.go 2019-02-07 12:21:20 +09:00
internal Refactor input parser 2018-12-18 03:13:07 +09:00
.gitignore Integrate with Travis CI (#103) 2018-10-25 22:59:47 +09:00
.travis.yml Cache go mod 2019-02-23 16:55:44 +09:00
CHANGELOG.md Update change log to release v0.2.3 2018-10-25 03:15:32 +09:00
LICENSE Update LICENSE 2017-07-16 13:51:31 +09:00
Makefile Migrate to go modules 2019-02-23 03:25:51 +09:00
README.md Add gh-prompt: An interactive GitHub CLI featuring auto-complete 2020-02-13 20:46:36 +09:00
buffer.go Add debug.AssertNoError for simplify 2018-12-14 22:28:41 +09:00
buffer_test.go Support CJK and Cyrillic characters 2018-06-22 01:11:58 +09:00
completion.go Add debug.AssertNoError for simplify 2018-12-14 22:28:41 +09:00
completion_test.go Fix misspell error 2018-02-19 23:26:28 +09:00
document.go Move some strings utilities to internal/strings 2018-12-09 21:04:57 +09:00
document_test.go Add examples for Document component 2018-12-09 21:05:15 +09:00
emacs.go Add debug.AssertNoError for simplify 2018-12-14 22:28:41 +09:00
emacs_test.go Support CJK and Cyrillic characters 2018-06-22 01:11:58 +09:00
filter.go Add refactor changes of fuzzy filter 2018-10-20 15:50:53 +09:00
filter_test.go Add refactor changes of fuzzy filter 2018-10-20 15:50:53 +09:00
go.mod Added document as an argument to the LineBreakCallback 2019-08-16 14:37:33 +04:00
go.sum Run go mod tidy 2019-02-23 03:28:20 +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 Refactor input parser 2018-12-18 03:13:07 +09:00
input_posix.go syscall.SYS_IOCTL is not portable 2019-04-10 15:14:54 +01:00
input_test.go Refactor input parser 2018-12-18 03:13:07 +09:00
input_windows.go Refactor input parser 2018-12-18 03:13:07 +09:00
key.go Use go generate 2018-12-14 22:34:13 +09:00
key_bind.go add ascii-code-bind-option-and-find-current-word-end 2018-04-11 20:14:38 +08:00
key_bind_func.go Update CHANGELOG for v0.2.2 release. (#84) 2018-06-28 22:06:28 +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 make BreaklineCallback private (`breaklineCallback`) 2019-08-26 17:41:23 +04:00
output.go Fix golint 2018-10-20 13:49:52 +09:00
output_posix.go Add debug logger and assert 2018-12-10 04:16:49 +09:00
output_vt100.go Fix resetting attributes for arch linux 2018-10-20 14:28:43 +09:00
output_vt100_test.go Separate VT100 writer 2018-06-21 01:34:12 +09:00
output_windows.go Update .travis.yml (#114) 2018-12-09 20:42:33 +09:00
prompt.go Refactor input parser 2018-12-18 03:13:07 +09:00
render.go make BreaklineCallback private (`breaklineCallback`) 2019-08-26 17:41:23 +04:00
render_test.go make BreaklineCallback private (`breaklineCallback`) 2019-08-26 17:41:23 +04:00
shortcut.go Refactor project structure 2018-06-21 02:27:27 +09:00
signal_posix.go Add debug logger and assert 2018-12-10 04:16:49 +09:00
signal_windows.go Add debug logger and assert 2018-12-10 04:16:49 +09:00

go-prompt

Go Report Card Software License GoDoc Build Status

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)

Author

Masashi Shibata

License

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