fixed
Go to file
c-bata b53127c970 Rename package 2017-08-08 00:19:51 +09:00
_example Rename package 2017-08-08 00:19:51 +09:00
_tools Rename package 2017-08-08 00:19:51 +09:00
.gitignore Initial commit 2017-07-03 23:36:56 +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 Rename package 2017-08-08 00:19:51 +09:00
bisect.go Move go files to project root 2017-07-18 05:27:57 +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 Rename Completion to Suggest 2017-08-04 20:30:50 +09:00
console_interface.go Add refactor change 2017-08-04 16:23:18 +09:00
document.go Move go files to project root 2017-07-18 05:27:57 +09:00
document_test.go Move go files to project root 2017-07-18 05:27:57 +09:00
filter.go Rename Completion to Suggest 2017-08-04 20:30:50 +09:00
filter_test.go Rename Completion to Suggest 2017-08-04 20:30:50 +09:00
history.go Fix history clear 2017-08-04 20:33:28 +09:00
key.go Add refactor change 2017-08-04 16:23:18 +09:00
key_string.go Move go files to project root 2017-07-18 05:27:57 +09:00
option.go Rename package 2017-08-08 00:19:51 +09:00
prompt.go Set nonblocking mode 2017-08-07 20:07:02 +09:00
render.go Remove output options 2017-08-06 15:31:44 +09:00
render_test.go Rename Completion to Suggest 2017-08-04 20:30:50 +09:00
vt100_input.go Add refactor change 2017-08-04 16:23:18 +09:00
vt100_output.go Set bold option 2017-07-19 01:16:57 +09:00

go-prompt

demo

Library for building powerful interactive prompt in Go, inspired by python-prompt-toolkit.

Similar Projects

Projects using go-prompt

Getting Started

package main

import (
	"fmt"

	"github.com/c-bata/go-prompt"
)

// executor executes command and print the output.
func executor(in string) {
	fmt.Println("Your input: " + in)
}

// completer returns the completion items from user input.
func completer(in string) []prompt.Suggest {
	s := []prompt.Suggest{
		{Text: "users", Description: "user table"},
		{Text: "sites", Description: "sites table"},
		{Text: "articles", Description: "articles table"},
		{Text: "comments", Description: "comments table"},
	}
	return prompt.FilterHasPrefix(s, in, true)
}

func main() {
	p := prompt.New(
		executor,
		completer,
		prompt.OptionPrefix(">>> "),
		prompt.OptionTitle("sql-prompt"),
	)
	p.Run()
}

Options

options

OptionParser(x ConsoleParser)

OptionWriter(x ConsoleWriter)

OptionTitle(x string)

OptionPrefix(x string)

OptionPrefixTextColor(x Color)

OptionPrefixBackgroundColor(x Color)

OptionInputTextColor(x Color)

OptionInputBGColor(x Color)

OptionPreviewSuggestionTextColor(x Color)

OptionPreviewSuggestionBGColor(x Color)

OptionSuggestionTextColor(x Color)

OptionSuggestionBGColor(x Color)

OptionSelectedSuggestionTextColor(x Color)

OptionSelectedSuggestionBGColor(x Color)

OptionMaxCompletions(x uint16)

OptionDescriptionTextColor(x Color)

OptionDescriptionBGColor(x Color)

OptionSelectedDescriptionTextColor(x Color)

OptionSelectedDescriptionBGColor(x Color)

LICENSE

MIT License

Copyright (c) 2017 Masashi SHIBATA

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.