go-prompt/README.md

105 lines
3.2 KiB
Markdown
Raw Normal View History

2017-08-07 15:19:51 +00:00
# go-prompt
2017-07-03 14:36:56 +00:00
2017-07-17 13:32:13 +00:00
![demo](./_resources/demo.gif)
2017-08-07 15:19:51 +00:00
Library for building powerful interactive prompt in Go, inspired by python-prompt-toolkit.
2017-07-03 14:36:56 +00:00
2017-07-17 13:32:13 +00:00
#### Similar Projects
2017-08-07 15:19:51 +00:00
* [jonathanslenders/python-prompt-toolkit](https://github.com/jonathanslenders/python-prompt-toolkit): **go-prompt** is inspired by this library.
2017-07-17 13:32:13 +00:00
* [peterh/liner](https://github.com/peterh/liner): The most similar project in golang is **liner** that I've ever seen.
2017-08-07 15:19:51 +00:00
#### Projects using go-prompt
2017-07-17 13:32:13 +00:00
2017-08-07 15:19:51 +00:00
* [kube-prompt : An interactive kubernetes client featuring auto-complete written in Go.](https://github.com/c-bata/kube-prompt)
2017-07-16 18:41:00 +00:00
2017-07-17 13:32:13 +00:00
## Getting Started
2017-07-16 18:41:00 +00:00
```go
package main
import (
2017-08-07 15:19:51 +00:00
"fmt"
2017-07-23 15:35:13 +00:00
2017-08-07 15:19:51 +00:00
"github.com/c-bata/go-prompt"
2017-07-16 18:41:00 +00:00
)
2017-08-06 06:31:44 +00:00
// executor executes command and print the output.
2017-08-07 15:19:51 +00:00
func executor(in string) {
fmt.Println("Your input: " + in)
2017-07-16 18:41:00 +00:00
}
2017-07-17 05:49:41 +00:00
// completer returns the completion items from user input.
2017-08-07 09:48:33 +00:00
func completer(in string) []prompt.Suggest {
2017-08-07 15:19:51 +00:00
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)
2017-07-16 18:41:00 +00:00
}
func main() {
2017-08-07 15:19:51 +00:00
p := prompt.New(
executor,
completer,
prompt.OptionPrefix(">>> "),
prompt.OptionTitle("sql-prompt"),
)
p.Run()
2017-07-16 18:41:00 +00:00
}
```
2017-07-03 14:36:56 +00:00
2017-07-16 17:58:51 +00:00
## Options
![options](./_resources/prompt-options.png)
2017-07-17 13:32:13 +00:00
#### `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)`
2017-07-18 15:36:16 +00:00
#### `OptionDescriptionTextColor(x Color)`
#### `OptionDescriptionBGColor(x Color)`
#### `OptionSelectedDescriptionTextColor(x Color)`
#### `OptionSelectedDescriptionBGColor(x Color)`
2017-07-16 18:41:00 +00:00
2017-07-16 17:20:59 +00:00
2017-07-03 14:36:56 +00:00
## LICENSE
```
MIT License
2017-07-16 04:51:31 +00:00
Copyright (c) 2017 Masashi SHIBATA
2017-07-03 14:36:56 +00:00
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.
```