Skip to content

Commit

Permalink
Merge pull request #32 from nao1215/feat/s3hub-tui
Browse files Browse the repository at this point in the history
Introduce bucket list
  • Loading branch information
nao1215 authored Jan 10, 2024
2 parents 043777b + bc3ae8c commit 8f47245
Show file tree
Hide file tree
Showing 11 changed files with 782 additions and 506 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [](https://github.com/nao1215/rainbow/compare/77bdf974281a...) (2024-01-08)
## [](https://github.com/nao1215/rainbow/compare/77bdf974281a...) (2024-01-10)

* Add unit test for S3 external layer [#31](https://github.com/nao1215/rainbow/pull/31) ([nao1215](https://github.com/nao1215))
* Introduce localstack pro into GitHub Actions(CI) [#30](https://github.com/nao1215/rainbow/pull/30) ([nao1215](https://github.com/nao1215))
Expand Down
4 changes: 2 additions & 2 deletions cmd/subcmd/s3hub/interactive.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package s3hub

import "github.com/nao1215/rainbow/ui"
import tui "github.com/nao1215/rainbow/ui/s3hub"

// interactive starts s3hub command interactive UI.
func interactive() error {
return ui.RunS3hubUI()
return tui.RunS3hubUI()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.48.0
github.com/charmbracelet/bubbles v0.17.1
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/log v0.3.1
github.com/fatih/color v1.16.0
github.com/google/go-cmp v0.6.0
Expand Down Expand Up @@ -48,7 +49,6 @@ require (
github.com/aws/smithy-go v1.19.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/caarlos0/env/v9 v9.0.0 // indirect
github.com/charmbracelet/lipgloss v0.9.1 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/google/subcommands v1.0.1 // indirect
Expand Down
87 changes: 70 additions & 17 deletions ui/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,45 @@ package ui
import (
"fmt"

"github.com/fatih/color"
"github.com/muesli/termenv"
)

// General stuff for styling the view
var (
term = termenv.EnvColorProfile()
subtle = makeFgStyle("241")
red = makeFgStyle("196")
green = makeFgStyle("46")
yellow = makeFgStyle("226")
Term = termenv.EnvColorProfile()
Subtle = MakeFgStyle("241")
Red = MakeFgStyle("196")
Green = MakeFgStyle("46")
Yellow = MakeFgStyle("226")
)

type (
errMsg error
// ErrMsg is an error message.
ErrMsg error
)

// makeFgStyle returns a function that will colorize the foreground of a given.
func makeFgStyle(color string) func(string) string {
return termenv.Style{}.Foreground(term.Color(color)).Styled
// MakeFgStyle returns a function that will colorize the foreground of a given.
func MakeFgStyle(color string) func(string) string {
return termenv.Style{}.Foreground(Term.Color(color)).Styled
}

// Color a string's foreground with the given value.
func colorFg(val, color string) string {
return termenv.String(val).Foreground(term.Color(color)).String()
// ColorFg a string's foreground with the given value.
func ColorFg(val, color string) string {
return termenv.String(val).Foreground(Term.Color(color)).String()
}

// checkbox represent [ ] and [x] items in the view.
func checkbox(label string, checked bool) string {
// Checkbox represent [ ] and [x] items in the view.
func Checkbox(label string, checked bool) string {
if checked {
return colorFg("[x] "+label, "212")
return ColorFg("[x] "+label, "212")
}
return fmt.Sprintf("[ ] %s", label)
}

// split splits a string into multiple lines.
// Split splits a string into multiple lines.
// Each line has a maximum length of 80 characters.
func split(s string) []string {
func Split(s string) []string {
var result []string
for i := 0; i < len(s); i += 80 {
end := i + 80
Expand All @@ -50,3 +52,54 @@ func split(s string) []string {
}
return result
}

// GoodByeMessage returns a goodbye message.
func GoodByeMessage() string {
s := fmt.Sprintf("\n See you later 🌈\n %s\n %s\n\n",
"Following URL for bug reports and encouragement (e.g. GitHub Star ⭐️ )",
color.GreenString("https://github.com/nao1215/rainbow"))
return s
}

// ErrorMessage returns an error message.
func ErrorMessage(err error) string {
message := fmt.Sprintf("%s\n", Red("[Error]"))
for _, line := range Split(err.Error()) {
message += fmt.Sprintf(" %s\n", Red(line))
}
return message
}

// Choice represents a choice.
type Choice struct {
Choice int
Max int
Min int
}

// NewChoice returns a new choice.
func NewChoice(min, max int) *Choice {
return &Choice{
Choice: min,
Max: max,
Min: min,
}
}

// Increment increments the choice.
// If the choice is greater than the maximum, the choice is set to the minimum.
func (c *Choice) Increment() {
c.Choice++
if c.Choice > c.Max {
c.Choice = c.Min
}
}

// Decrement decrements the choice.
// If the choice is less than the minimum, the choice is set to the maximum.
func (c *Choice) Decrement() {
c.Choice--
if c.Choice < c.Min {
c.Choice = c.Max
}
}
Loading

0 comments on commit 8f47245

Please sign in to comment.