fixed
Go to file
2021-01-08 21:46:14 +05:30
_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
.github Change wf name to build 2021-01-08 21:46:14 +05:30
completer Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
internal Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
.gitignore Integrate with Travis CI (#103) 2018-10-25 22:59:47 +09:00
buffer_test.go Support CJK and Cyrillic characters 2018-06-22 01:11:58 +09:00
buffer.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
CHANGELOG.md Update change log to release v0.2.3 2018-10-25 03:15:32 +09:00
completion_test.go Fix misspell error 2018-02-19 23:26:28 +09:00
completion.go Change for status box 2020-11-25 12:42:23 +05:30
document_test.go Add examples for Document component 2018-12-09 21:05:15 +09:00
document.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
emacs_test.go Support CJK and Cyrillic characters 2018-06-22 01:11:58 +09:00
emacs.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
filter_test.go Add refactor changes of fuzzy filter 2018-10-20 15:50:53 +09:00
filter.go Fix golint-cli -fast warnings 2020-02-24 14:13:36 +01:00
go.mod Fix the space issues 2021-01-06 09:11:19 +05:30
go.sum Fix the space issues 2021-01-06 09:11:19 +05:30
history_test.go Refactor tests for history 2017-10-11 12:01:40 +09:00
history.go Fix some lint errors 2018-02-14 01:14:22 +09:00
input_posix.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
input_test.go Refactor input parser 2018-12-18 03:13:07 +09:00
input.go Refactor input parser 2018-12-18 03:13:07 +09:00
key_bind_func.go Update CHANGELOG for v0.2.2 release. (#84) 2018-06-28 22:06:28 +09:00
key_bind.go add ascii-code-bind-option-and-find-current-word-end 2018-04-11 20:14:38 +08:00
key_string.go Update key_stringer.go by latest stringer to fix lint errors 2018-02-14 13:22:22 +09:00
key.go Use go generate 2018-12-14 22:34:13 +09:00
LICENSE Update LICENSE 2017-07-16 13:51:31 +09:00
Makefile Remove travis-ci config 2020-09-19 00:06:03 +09:00
option.go Fix the space issues 2021-01-06 09:11:19 +05:30
output_posix.go Add debug logger and assert 2018-12-10 04:16:49 +09:00
output_vt100_test.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
output_vt100.go Remove unnecessary comments 2020-12-08 11:15:04 +05:30
output.go Remove unnecessary comments 2020-12-08 11:15:04 +05:30
prompt.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
README.md Add Bit as a project using go-prompt. 2020-10-03 17:01:30 +09:00
render_test.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
render.go Fix the space issues 2021-01-06 09:11:19 +05:30
shortcut.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30
signal_posix.go Some code tweaks and change to use fatih/color 2020-11-23 08:56:14 +05:30

go-prompt

Go Report Card Software License GoDoc tests

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.