Skip to content

Commit 4c1e893

Browse files
authored
Merge pull request #2 from ktr0731/apply-239
apply c-bata/go-prompt c-bata#239
2 parents 0e7d60a + 56b175f commit 4c1e893

File tree

11 files changed

+25
-142
lines changed

11 files changed

+25
-142
lines changed

README.md

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1 @@
1-
# go-prompt
2-
3-
[![Go Report Card](https://goreportcard.com/badge/github.com/c-bata/go-prompt)](https://goreportcard.com/report/github.com/c-bata/go-prompt)
4-
![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)
5-
[![GoDoc](https://godoc.org/github.com/c-bata/go-prompt?status.svg)](https://godoc.org/github.com/c-bata/go-prompt)
6-
![tests](https://github.com/c-bata/go-prompt/workflows/tests/badge.svg)
7-
8-
A library for building powerful interactive prompts inspired by [python-prompt-toolkit](https://github.com/jonathanslenders/python-prompt-toolkit),
9-
making it easier to build cross-platform command line tools using Go.
10-
11-
```go
12-
package main
13-
14-
import (
15-
"fmt"
16-
"github.com/c-bata/go-prompt"
17-
)
18-
19-
func completer(d prompt.Document) []prompt.Suggest {
20-
s := []prompt.Suggest{
21-
{Text: "users", Description: "Store the username and age"},
22-
{Text: "articles", Description: "Store the article text posted by user"},
23-
{Text: "comments", Description: "Store the text commented to articles"},
24-
}
25-
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
26-
}
27-
28-
func main() {
29-
fmt.Println("Please select table.")
30-
t := prompt.Input("> ", completer)
31-
fmt.Println("You selected " + t)
32-
}
33-
```
34-
35-
#### Projects using go-prompt
36-
37-
* [c-bata/kube-prompt : An interactive kubernetes client featuring auto-complete written in Go.](https://github.com/c-bata/kube-prompt)
38-
* [rancher/cli : The Rancher Command Line Interface (CLI)is a unified tool to manage your Rancher server](https://github.com/rancher/cli)
39-
* [kubicorn/kubicorn : Simple, cloud native infrastructure for Kubernetes.](https://github.com/kubicorn/kubicorn)
40-
* [cch123/asm-cli : Interactive shell of assembly language(X86/X64) based on unicorn and rasm2](https://github.com/cch123/asm-cli)
41-
* [ktr0731/evans : more expressive universal gRPC client](https://github.com/ktr0731/evans)
42-
* [CrushedPixel/moshpit: A Command-line tool for datamoshing.](https://github.com/CrushedPixel/moshpit)
43-
* [last-ent/testy-go: Testy Go: A tool for easy testing!](https://github.com/last-ent/testy-go)
44-
* [tiagorlampert/CHAOS: a PoC that allow generate payloads and control remote operating systems.](https://github.com/tiagorlampert/CHAOS)
45-
* [abs-lang/abs: ABS is a scripting language that works best on terminal. It tries to combine the elegance of languages such as Python, or Ruby, to the convenience of Bash.](https://github.com/abs-lang/abs)
46-
* [takashabe/btcli: btcli is a CLI client for the Bigtable. Has many read options and auto-completion.](https://github.com/takashabe/btcli)
47-
* [ysn2233/kafka-prompt: An interactive kafka-prompt(kafka-shell) built on existing kafka command client](https://github.com/ysn2233/kafka-prompt)
48-
* [fishi0x01/vsh: HashiCorp Vault interactive shell](https://github.com/fishi0x01/vsh)
49-
* [mstrYoda/docker-shell: A simple interactive prompt for docker](https://github.com/mstrYoda/docker-shell)
50-
* [c-bata/gh-prompt: An interactive GitHub CLI featuring auto-complete.](https://github.com/c-bata/gh-prompt)
51-
* [docker-slim/docker-slim: Don't change anything in your Docker container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)](https://github.com/docker-slim/docker-slim)
52-
* [rueyaa332266/ezcron: Ezcron is a CLI tool, helping you deal with cron expression easier.](https://github.com/rueyaa332266/ezcron)
53-
* [qingstor/qsctl: Advanced command line tool for QingStor Object Storage.](https://github.com/qingstor/qsctl)
54-
* [segmentio/topicctl: Tool for declarative management of Kafka topics](https://github.com/segmentio/topicctl)
55-
* [chriswalz/bit: Bit is a modern Git CLI](https://github.com/chriswalz/bit)
56-
* (If you create a CLI utility using go-prompt and want your own project to be listed here, please submit a GitHub issue.)
57-
58-
## Features
59-
60-
### Powerful auto-completion
61-
62-
[![demo](https://github.com/c-bata/assets/raw/master/go-prompt/kube-prompt.gif)](https://github.com/c-bata/kube-prompt)
63-
64-
(This is a GIF animation of kube-prompt.)
65-
66-
### Flexible options
67-
68-
go-prompt provides many options. Please check [option section of GoDoc](https://godoc.org/github.com/c-bata/go-prompt#Option) for more details.
69-
70-
[![options](https://github.com/c-bata/assets/raw/master/go-prompt/prompt-options.png)](#flexible-options)
71-
72-
### Keyboard Shortcuts
73-
74-
Emacs-like keyboard shortcuts are available by default (these also are the default shortcuts in Bash shell).
75-
You can customize and expand these shortcuts.
76-
77-
[![keyboard shortcuts](https://github.com/c-bata/assets/raw/master/go-prompt/keyboard-shortcuts.gif)](#keyboard-shortcuts)
78-
79-
Key Binding | Description
80-
---------------------|---------------------------------------------------------
81-
<kbd>Ctrl + A</kbd> | Go to the beginning of the line (Home)
82-
<kbd>Ctrl + E</kbd> | Go to the end of the line (End)
83-
<kbd>Ctrl + P</kbd> | Previous command (Up arrow)
84-
<kbd>Ctrl + N</kbd> | Next command (Down arrow)
85-
<kbd>Ctrl + F</kbd> | Forward one character
86-
<kbd>Ctrl + B</kbd> | Backward one character
87-
<kbd>Ctrl + D</kbd> | Delete character under the cursor
88-
<kbd>Ctrl + H</kbd> | Delete character before the cursor (Backspace)
89-
<kbd>Ctrl + W</kbd> | Cut the word before the cursor to the clipboard
90-
<kbd>Ctrl + K</kbd> | Cut the line after the cursor to the clipboard
91-
<kbd>Ctrl + U</kbd> | Cut the line before the cursor to the clipboard
92-
<kbd>Ctrl + L</kbd> | Clear the screen
93-
94-
### History
95-
96-
You can use <kbd>Up arrow</kbd> and <kbd>Down arrow</kbd> to walk through the history of commands executed.
97-
98-
[![History](https://github.com/c-bata/assets/raw/master/go-prompt/history.gif)](#history)
99-
100-
### Multiple platform support
101-
102-
We have confirmed go-prompt works fine in the following terminals:
103-
104-
* iTerm2 (macOS)
105-
* Terminal.app (macOS)
106-
* Command Prompt (Windows)
107-
* gnome-terminal (Ubuntu)
108-
109-
## Links
110-
111-
* [Change Log](./CHANGELOG.md)
112-
* [GoDoc](http://godoc.org/github.com/c-bata/go-prompt)
113-
* [gocover.io](https://gocover.io/github.com/c-bata/go-prompt)
114-
115-
## Author
116-
117-
Masashi Shibata
118-
119-
* Twitter: [@c\_bata\_](https://twitter.com/c_bata_/)
120-
* Github: [@c-bata](https://github.com/c-bata/)
121-
122-
## License
123-
124-
This software is licensed under the MIT license, see [LICENSE](./LICENSE) for more information.
125-
1+
This is a fork of c-bata/go-prompt optimized for ktr0731/evans. It's not recommended to use this fork for other projects!

_example/exec-command/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"os/exec"
66

7-
prompt "github.com/c-bata/go-prompt"
7+
prompt "github.com/ktr0731/go-prompt"
88
)
99

1010
func executor(t string) {

_example/http-prompt/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"path"
1111
"strings"
1212

13-
prompt "github.com/c-bata/go-prompt"
13+
prompt "github.com/ktr0731/go-prompt"
1414
)
1515

1616
type RequestContext struct {

_example/live-prefix/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"fmt"
55

6-
prompt "github.com/c-bata/go-prompt"
6+
prompt "github.com/ktr0731/go-prompt"
77
)
88

99
var LivePrefixState struct {

_example/simple-echo/cjk-cyrillic/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"fmt"
55

6-
prompt "github.com/c-bata/go-prompt"
6+
prompt "github.com/ktr0731/go-prompt"
77
)
88

99
func executor(in string) {

_example/simple-echo/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package main
22

33
import (
44
"fmt"
5+
"log"
56

6-
prompt "github.com/c-bata/go-prompt"
7+
prompt "github.com/ktr0731/go-prompt"
78
)
89

910
func completer(in prompt.Document) []prompt.Suggest {
@@ -17,12 +18,15 @@ func completer(in prompt.Document) []prompt.Suggest {
1718
}
1819

1920
func main() {
20-
in := prompt.Input(">>> ", completer,
21+
in, err := prompt.Input(">>> ", completer,
2122
prompt.OptionTitle("sql-prompt"),
2223
prompt.OptionHistory([]string{"SELECT * FROM users;"}),
2324
prompt.OptionPrefixTextColor(prompt.Yellow),
2425
prompt.OptionPreviewSuggestionTextColor(prompt.Blue),
2526
prompt.OptionSelectedSuggestionBGColor(prompt.LightGray),
2627
prompt.OptionSuggestionBGColor(prompt.DarkGray))
28+
if err != nil {
29+
log.Fatal(err)
30+
}
2731
fmt.Println("Your input: " + in)
2832
}

_tools/complete_file/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"os"
66
"strings"
77

8-
prompt "github.com/c-bata/go-prompt"
9-
"github.com/c-bata/go-prompt/completer"
8+
prompt "github.com/ktr0731/go-prompt"
9+
"github.com/ktr0731/go-prompt/completer"
1010
)
1111

1212
var filePathCompleter = completer.FilePathCompleter{

_tools/vt100_debug/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package main
@@ -6,8 +7,8 @@ import (
67
"fmt"
78
"syscall"
89

9-
prompt "github.com/c-bata/go-prompt"
10-
"github.com/c-bata/go-prompt/internal/term"
10+
prompt "github.com/ktr0731/go-prompt"
11+
"github.com/ktr0731/go-prompt/internal/term"
1112
)
1213

1314
func main() {

document_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ This is a`),
182182
func ExampleDocument_GetWordBeforeCursorUntilSeparator() {
183183
d := &Document{
184184
Text: `hello,i am ktr0731`,
185-
cursorPosition: len(`hello,i am c`),
185+
cursorPosition: len(`hello,i am k`),
186186
}
187187
fmt.Println(d.GetWordBeforeCursorUntilSeparator(","))
188188
// Output:
189-
// i am c
189+
// i am k
190190
}
191191

192192
func ExampleDocument_GetWordAfterCursorUntilSeparator() {

internal/term/raw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ func SetRaw(fd int) error {
2525
n.Cc[syscall.VMIN] = 1
2626
n.Cc[syscall.VTIME] = 0
2727

28-
return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*unix.Termios)(n))
28+
return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*unix.Termios)(&n))
2929
}

0 commit comments

Comments
 (0)