mirror of
https://github.com/charmbracelet/gum
synced 2024-05-06 00:13:17 +02:00
Initial commit
This commit is contained in:
commit
92a2d31291
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Files
|
||||
test
|
||||
|
||||
# Binaries
|
||||
sea
|
||||
seashell
|
||||
sea-shell
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 Charmbracelet, Inc
|
||||
|
||||
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.
|
94
README.md
Normal file
94
README.md
Normal file
|
@ -0,0 +1,94 @@
|
|||
# Soda Pop
|
||||
|
||||
Command line utilities to make your command-line `pop`.
|
||||
|
||||
Soda Pop provides utilities to help you create shell scripts make your user's
|
||||
shells `pop`. Powered by [Bubbles](https://github.com/charmbracelet/bubbles)
|
||||
and [Lip Gloss](https://github.com/charmbracelet/lipgloss)
|
||||
|
||||
## Interaction
|
||||
|
||||
#### Input
|
||||
Prompt your users for input with a simple command.
|
||||
|
||||
```bash
|
||||
pop input > answer.text
|
||||
```
|
||||
|
||||
#### Search
|
||||
|
||||
Allow your users to filter through a list of options by fuzzy searching.
|
||||
|
||||
```bash
|
||||
echo Gastropoda >> options.text
|
||||
echo Bivalvia >> options.text
|
||||
echo Polyplacophora >> options.text
|
||||
cat options.text | pop search > selection.text
|
||||
```
|
||||
|
||||
#### Loading
|
||||
|
||||
Display a progress bar while loading.
|
||||
|
||||
```bash
|
||||
pop loading --time 5s
|
||||
```
|
||||
|
||||
#### Spinners
|
||||
|
||||
Display a spinner while taking some running action. We specify the command to
|
||||
run while showing the spinner, the spinner will automatically stop after the
|
||||
command exits.
|
||||
|
||||
```bash
|
||||
pop spin --spinner dot --title "Buying Soda Pop..." -- sleep 5
|
||||
```
|
||||
|
||||
```
|
||||
⣽ Buying Soda Pop...
|
||||
```
|
||||
|
||||
|
||||
## Styling
|
||||
|
||||
Pretty print any string with any layout with one command.
|
||||
|
||||
```bash
|
||||
pop style \
|
||||
--foreground "#FF06B7" --border "double" \
|
||||
--margin 2 --padding "2 4" --width 50 \
|
||||
"And oh gosh, how delicious the fabulous frizzy frobscottle was!
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```
|
||||
╔══════════════════════════════════════════════════╗
|
||||
║ ║
|
||||
║ ║
|
||||
║ And oh gosh, how delicious the fabulous ║
|
||||
║ frizzy frobscottle was! ║
|
||||
║ ║
|
||||
║ ║
|
||||
╚══════════════════════════════════════════════════╝
|
||||
```
|
||||
|
||||
## Feedback
|
||||
|
||||
We’d love to hear your thoughts on this project. Feel free to drop us a note!
|
||||
|
||||
* [Twitter](https://twitter.com/charmcli)
|
||||
* [The Fediverse](https://mastodon.technology/@charm)
|
||||
* [Slack](https://charm.sh/slack)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/charmbracelet/seashell/raw/main/LICENSE)
|
||||
|
||||
***
|
||||
|
||||
Part of [Charm](https://charm.sh).
|
||||
|
||||
<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>
|
||||
|
||||
Charm热爱开源 • Charm loves open source
|
26
go.mod
Normal file
26
go.mod
Normal file
|
@ -0,0 +1,26 @@
|
|||
module github.com/charmbracelet/sodapop
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/alecthomas/kong v0.6.1
|
||||
github.com/charmbracelet/bubbles v0.13.0
|
||||
github.com/charmbracelet/bubbletea v0.22.0
|
||||
github.com/charmbracelet/lipgloss v0.5.0
|
||||
github.com/mattn/go-runewidth v0.0.13
|
||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739
|
||||
github.com/sahilm/fuzzy v0.1.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/containerd/console v1.0.3 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
|
||||
github.com/muesli/cancelreader v0.2.1 // indirect
|
||||
github.com/muesli/reflow v0.3.0 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
)
|
61
go.sum
Normal file
61
go.sum
Normal file
|
@ -0,0 +1,61 @@
|
|||
github.com/alecthomas/kong v0.6.1 h1:1kNhcFepkR+HmasQpbiKDLylIL8yh5B5y1zPp5bJimA=
|
||||
github.com/alecthomas/kong v0.6.1/go.mod h1:JfHWDzLmbh/puW6I3V7uWenoh56YNVONW+w8eKeUr9I=
|
||||
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=
|
||||
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/charmbracelet/bubbles v0.13.0 h1:zP/ROH3wJEBqZWKIsD50ZKKlx3ydLInq3LdD/Nrlb8w=
|
||||
github.com/charmbracelet/bubbles v0.13.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc=
|
||||
github.com/charmbracelet/bubbletea v0.21.0/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4=
|
||||
github.com/charmbracelet/bubbletea v0.22.0 h1:E1BTNSE3iIrq0G0X6TjGAmrQ32cGCbFDPcIuImikrUc=
|
||||
github.com/charmbracelet/bubbletea v0.22.0/go.mod h1:aoVIwlNlr5wbCB26KhxfrqAn0bMp4YpJcoOelbxApjs=
|
||||
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
||||
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
|
||||
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
|
||||
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
|
||||
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
|
||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
|
||||
github.com/muesli/cancelreader v0.2.0/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/cancelreader v0.2.1 h1:Xzd1B4U5bWQOuSKuN398MyynIGTNT89dxzpEDsalXZs=
|
||||
github.com/muesli/cancelreader v0.2.1/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
|
||||
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
|
||||
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
|
||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
|
||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
|
||||
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
|
||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
32
main.go
Normal file
32
main.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/charmbracelet/sodapop/internal/stdin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
pop := &Pop{}
|
||||
ctx := kong.Parse(pop,
|
||||
kong.Name("pop"),
|
||||
kong.Description("Make your shell pop."),
|
||||
kong.UsageOnError(),
|
||||
kong.ConfigureHelp(kong.HelpOptions{
|
||||
Compact: true,
|
||||
Summary: false,
|
||||
}))
|
||||
switch ctx.Command() {
|
||||
case "input":
|
||||
pop.Input.Run()
|
||||
case "search":
|
||||
pop.Search.Run()
|
||||
case "spin <command>":
|
||||
pop.Spin.Run()
|
||||
case "style":
|
||||
pop.Style.Text, _ = stdin.Read()
|
||||
pop.Style.Run()
|
||||
case "style <text>":
|
||||
pop.Style.Run()
|
||||
case "layout":
|
||||
}
|
||||
}
|
83
pop.go
Normal file
83
pop.go
Normal file
|
@ -0,0 +1,83 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/sodapop/input"
|
||||
"github.com/charmbracelet/sodapop/search"
|
||||
"github.com/charmbracelet/sodapop/spin"
|
||||
"github.com/charmbracelet/sodapop/style"
|
||||
)
|
||||
|
||||
// Pop is the command-line interface for Soda Pop.
|
||||
type Pop struct {
|
||||
// Input provides a shell script interface for the text input bubble.
|
||||
// https://github.com/charmbracelet/bubbles/textinput
|
||||
//
|
||||
// It can be used to prompt the user for some input. The text the user
|
||||
// entered will be sent to stdout.
|
||||
//
|
||||
// $ pop input --placeholder "What's your favorite pop?" > answer.text
|
||||
//
|
||||
Input input.Options `cmd:"" help:"Prompt for input."`
|
||||
|
||||
// Search provides a fuzzy searching text input to allow filtering a list of
|
||||
// options to select one option.
|
||||
//
|
||||
// By default it will list all the files (recursively) in the current directory
|
||||
// for the user to choose one, but the script (or user) can provide different
|
||||
// new-line separated options to choose from.
|
||||
//
|
||||
// I.e. let's pick from a list of soda pop flavors:
|
||||
//
|
||||
// $ cat flavors.text | pop search
|
||||
//
|
||||
Search search.Options `cmd:"" help:"Fuzzy search options."`
|
||||
|
||||
// Spin provides a shell script interface for the spinner bubble.
|
||||
// https://github.com/charmbracelet/bubbles/spinner
|
||||
//
|
||||
// It is useful for displaying that some task is running in the background
|
||||
// while consuming it's output so that it is not shown to the user.
|
||||
//
|
||||
// For example, let's do a long running task:
|
||||
// $ sleep 5
|
||||
//
|
||||
// We can simply prepend a spinner to this task to show it to the user,
|
||||
// while performing the task / command in the background.
|
||||
//
|
||||
// $ pop spin -t "Taking a nap..." -- sleep 5
|
||||
//
|
||||
// The spinner will automatically exit when the task is complete.
|
||||
Spin spin.Options `cmd:"" help:"Show spinner while executing a command."`
|
||||
|
||||
// Style provides a shell script interface for Lip Gloss.
|
||||
// https://github.com/charmbracelet/lipgloss
|
||||
//
|
||||
// It allows you to use Lip Gloss to style text without needing to use Go.
|
||||
// All of the styling options are available as flags.
|
||||
//
|
||||
// Let's make some text glamorous using bash:
|
||||
//
|
||||
// $ pop style \
|
||||
// --foreground "#FF06B7" --border "double" \
|
||||
// --margin 2 --padding "2 4" --width 50 \
|
||||
// "And oh gosh, how delicious the fabulous frizzy frobscottle" \
|
||||
// "was! It was sweet and refreshing. It tasted of vanilla and" \
|
||||
// "cream, with just the faintest trace of raspberries on the" \
|
||||
// "edge of the flavour. And the bubbles were wonderful."
|
||||
//
|
||||
//
|
||||
// ╔══════════════════════════════════════════════════╗
|
||||
// ║ ║
|
||||
// ║ ║
|
||||
// ║ And oh gosh, how delicious the fabulous ║
|
||||
// ║ frizzy frobscottle was It was sweet and ║
|
||||
// ║ refreshing. It tasted of vanilla and ║
|
||||
// ║ cream, with just the faintest trace of ║
|
||||
// ║ raspberries on the edge of the flavour. ║
|
||||
// ║ And the bubbles were wonderful. ║
|
||||
// ║ ║
|
||||
// ║ ║
|
||||
// ╚══════════════════════════════════════════════════╝
|
||||
//
|
||||
Style style.Options `cmd:"" help:"Style some text."`
|
||||
}
|
Loading…
Reference in a new issue