Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
2de51c1ac8
11
.github/FUNDING.yml
vendored
Normal file
11
.github/FUNDING.yml
vendored
Normal file
@ -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']
|
||||
|
@ -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
|
||||
|
13
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
13
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -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.*
|
||||
|
29
README.md
29
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.
|
||||
|
||||
<a href="https://github.com/c-bata/go-prompt/graphs/contributors"><img src="https://opencollective.com/go-prompt/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
### 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)
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/0/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/1/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/2/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/3/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/4/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/5/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/6/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/7/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/8/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/go-prompt/sponsor/9/website" target="_blank"><img src="https://opencollective.com/go-prompt/sponsor/9/avatar.svg"></a>
|
||||
|
||||
## License
|
||||
|
||||
This software is licensed under the MIT license, see [LICENSE](./LICENSE) for more information.
|
||||
|
@ -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 = "/"
|
||||
|
2
go.mod
2
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
|
||||
)
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user