diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..127b0d1
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,11 @@
+github: [c-bata] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
+patreon: # Replace with a single Patreon username
+open_collective: c-bata # Replace with a single Open Collective username
+ko_fi: # Replace with a single Ko-fi username
+tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
+community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
+liberapay: # Replace with a single Liberapay username
+issuehunt: # Replace with a single IssueHunt username
+otechie: # Replace with a single Otechie username
+custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE/bug_report.md
similarity index 78%
rename from .github/ISSUE_TEMPLATE.md
rename to .github/ISSUE_TEMPLATE/bug_report.md
index 83b2e63..4c8c031 100644
--- a/.github/ISSUE_TEMPLATE.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -1,13 +1,15 @@
-# Suggestions
-
-*Please write your suggestion here and remove "Bug reports" section.*
-
+---
+name: "Bug report"
+about: Create a bug report to improve go-prompt
+title: "[Bug]"
+labels: bug
+assignees: ''
---
# Bug reports
-*Please file a bug report here and remove "Suggestions" section.*
+*Please file a bug report here.*
## Expected Behavior
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 0000000..cb816a2
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,13 @@
+---
+name: "Feature request"
+about: Suggest an idea for new features in go-prompt.
+title: "[Feature Request]"
+labels: enhancement
+assignees: ''
+
+---
+
+# Feature Request
+
+*Please write your suggestion here.*
+
diff --git a/README.md b/README.md
index 5406610..86e6da3 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,6 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/c-bata/go-prompt)](https://goreportcard.com/report/github.com/c-bata/go-prompt)
![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)
-[![Backers on Open Collective](https://opencollective.com/go-prompt/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/go-prompt/sponsors/badge.svg)](#sponsors)
[![GoDoc](https://godoc.org/github.com/c-bata/go-prompt?status.svg)](https://godoc.org/github.com/c-bata/go-prompt)
[![Build Status](https://travis-ci.org/c-bata/go-prompt.svg?branch=master)](https://travis-ci.org/c-bata/go-prompt)
@@ -43,6 +42,10 @@ func main() {
* [CrushedPixel/moshpit: A Command-line tool for datamoshing.](https://github.com/CrushedPixel/moshpit)
* [last-ent/testy-go: Testy Go: A tool for easy testing!](https://github.com/last-ent/testy-go)
* [tiagorlampert/CHAOS: a PoC that allow generate payloads and control remote operating systems.](https://github.com/tiagorlampert/CHAOS)
+* [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)
+* [takashabe/btcli: btcli is a CLI client for the Bigtable. Has many read options and auto-completion.](https://github.com/takashabe/btcli)
+* [ysn2233/kafka-prompt: An interactive kafka-prompt(kafka-shell) built on existing kafka command client](https://github.com/ysn2233/kafka-prompt)
+* [fishi0x01/vsh: HashiCorp Vault interactive shell](https://github.com/fishi0x01/vsh)
* (If you create a CLI utility using go-prompt and want your own project to be listed here, please submit a GitHub issue.)
## Features
@@ -109,30 +112,6 @@ Masashi Shibata
* Twitter: [@c\_bata\_](https://twitter.com/c_bata_/)
* Github: [@c-bata](https://github.com/c-bata/)
-## Supporting go-prompt
-
-### Contributors
-
-This project exists thanks to all the people who contribute.
-
-
-
-### Backers and Sponsors (OpenCollective)
-
-Started getting support via opencollective. If you support this project by becoming a sponsor, your logo will show up here with a link to your website.
-
-[![Become a backer](https://opencollective.com/go-prompt/tiers/backer.svg?avatarHeight=64)](https://opencollective.com/go-prompt#backers)
-
-
-
-
-
-
-
-
-
-
-
## License
This software is licensed under the MIT license, see [LICENSE](./LICENSE) for more information.
diff --git a/_example/http-prompt/main.go b/_example/http-prompt/main.go
index 7c16e2d..b372a35 100644
--- a/_example/http-prompt/main.go
+++ b/_example/http-prompt/main.go
@@ -105,6 +105,9 @@ func executor(in string) {
var method, body string
blocks := strings.Split(in, " ")
switch blocks[0] {
+ case "exit":
+ fmt.Println("Bye!")
+ os.Exit(0)
case "cd":
if len(blocks) < 2 {
ctx.url.Path = "/"
diff --git a/go.mod b/go.mod
index 45f3b12..570b588 100644
--- a/go.mod
+++ b/go.mod
@@ -6,5 +6,5 @@ require (
github.com/mattn/go-runewidth v0.0.3
github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a
github.com/pkg/term v0.0.0-20180423043932-cda20d4ac917
- golang.org/x/sys v0.0.0-20180620133508-ad87a3a340fa // indirect
+ golang.org/x/sys v0.0.0-20180620133508-ad87a3a340fa
)
diff --git a/input_posix.go b/input_posix.go
index 14cf8c3..f104303 100644
--- a/input_posix.go
+++ b/input_posix.go
@@ -4,9 +4,9 @@ package prompt
import (
"syscall"
- "unsafe"
"github.com/c-bata/go-prompt/internal/term"
+ "golang.org/x/sys/unix"
)
const maxReadBytes = 1024
@@ -50,25 +50,11 @@ func (t *PosixParser) Read() ([]byte, error) {
return buf[:n], nil
}
-// winsize is winsize struct got from the ioctl(2) system call.
-type ioctlWinsize struct {
- Row uint16
- Col uint16
- X uint16 // pixel value
- Y uint16 // pixel value
-}
-
// GetWinSize returns WinSize object to represent width and height of terminal.
func (t *PosixParser) GetWinSize() *WinSize {
- ws := &ioctlWinsize{}
- retCode, _, errno := syscall.Syscall(
- syscall.SYS_IOCTL,
- uintptr(t.fd),
- uintptr(syscall.TIOCGWINSZ),
- uintptr(unsafe.Pointer(ws)))
-
- if int(retCode) == -1 {
- panic(errno)
+ ws, err := unix.IoctlGetWinsize(t.fd, unix.TIOCGWINSZ)
+ if err != nil {
+ panic(err)
}
return &WinSize{
Row: ws.Row,
diff --git a/option.go b/option.go
index a5ebee1..ada1b77 100644
--- a/option.go
+++ b/option.go
@@ -242,6 +242,14 @@ func OptionShowCompletionAtStart() Option {
}
}
+// OptionBreakLineCallback to run a callback at every break line
+func OptionBreakLineCallback(fn func(*Document)) Option {
+ return func(p *Prompt) error {
+ p.renderer.breakLineCallback = fn
+ return nil
+ }
+}
+
// New returns a Prompt with powerful auto-completion.
func New(executor Executor, completer Completer, opts ...Option) *Prompt {
defaultWriter := NewStdoutWriter()
diff --git a/render.go b/render.go
index cffc16c..53f464d 100644
--- a/render.go
+++ b/render.go
@@ -13,6 +13,7 @@ type Render struct {
out ConsoleWriter
prefix string
livePrefixCallback func() (prefix string, useLivePrefix bool)
+ breakLineCallback func(*Document)
title string
row uint16
col uint16
@@ -278,6 +279,9 @@ func (r *Render) BreakLine(buffer *Buffer) {
r.out.WriteStr(buffer.Document().Text + "\n")
r.out.SetColor(DefaultColor, DefaultColor, false)
debug.AssertNoError(r.out.Flush())
+ if r.breakLineCallback != nil {
+ r.breakLineCallback(buffer.Document())
+ }
r.previousCursor = 0
}
diff --git a/render_test.go b/render_test.go
index a87aea3..98cb27c 100644
--- a/render_test.go
+++ b/render_test.go
@@ -2,6 +2,7 @@ package prompt
import (
"reflect"
+ "syscall"
"testing"
)
@@ -65,3 +66,48 @@ func TestFormatCompletion(t *testing.T) {
}
}
}
+
+func TestBreakLineCallback(t *testing.T) {
+ var i int
+ r := &Render{
+ prefix: "> ",
+ out: &PosixWriter{
+ fd: syscall.Stdin, // "write" to stdin just so we don't mess with the output of the tests
+ },
+ livePrefixCallback: func() (string, bool) { return "", false },
+ prefixTextColor: Blue,
+ prefixBGColor: DefaultColor,
+ inputTextColor: DefaultColor,
+ inputBGColor: DefaultColor,
+ previewSuggestionTextColor: Green,
+ previewSuggestionBGColor: DefaultColor,
+ suggestionTextColor: White,
+ suggestionBGColor: Cyan,
+ selectedSuggestionTextColor: Black,
+ selectedSuggestionBGColor: Turquoise,
+ descriptionTextColor: Black,
+ descriptionBGColor: Turquoise,
+ selectedDescriptionTextColor: White,
+ selectedDescriptionBGColor: Cyan,
+ scrollbarThumbColor: DarkGray,
+ scrollbarBGColor: Cyan,
+ col: 1,
+ }
+ b := NewBuffer()
+ r.BreakLine(b)
+
+ if i != 0 {
+ t.Errorf("i should initially be 0, before applying a break line callback")
+ }
+
+ r.breakLineCallback = func(doc *Document) {
+ i++
+ }
+ r.BreakLine(b)
+ r.BreakLine(b)
+ r.BreakLine(b)
+
+ if i != 3 {
+ t.Errorf("BreakLine callback not called, i should be 3")
+ }
+}