Skip to content

Commit e03525c

Browse files
author
CHIKAMATSU Naohiro
committed
Introduce S3 Bucket List TUI
1 parent f03b386 commit e03525c

File tree

10 files changed

+781
-611
lines changed

10 files changed

+781
-611
lines changed

cmd/subcmd/s3hub/interactive.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package s3hub
22

3-
import "github.com/nao1215/rainbow/ui"
3+
import tui "github.com/nao1215/rainbow/ui/s3hub"
44

55
// interactive starts s3hub command interactive UI.
66
func interactive() error {
7-
return ui.RunS3hubUI()
7+
return tui.RunS3hubUI()
88
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/aws/aws-sdk-go-v2/service/s3 v1.48.0
1313
github.com/charmbracelet/bubbles v0.17.1
1414
github.com/charmbracelet/bubbletea v0.25.0
15+
github.com/charmbracelet/lipgloss v0.9.1
1516
github.com/charmbracelet/log v0.3.1
1617
github.com/fatih/color v1.16.0
1718
github.com/google/go-cmp v0.6.0
@@ -48,7 +49,6 @@ require (
4849
github.com/aws/smithy-go v1.19.0 // indirect
4950
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
5051
github.com/caarlos0/env/v9 v9.0.0 // indirect
51-
github.com/charmbracelet/lipgloss v0.9.1 // indirect
5252
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
5353
github.com/go-logfmt/logfmt v0.6.0 // indirect
5454
github.com/google/subcommands v1.0.1 // indirect

ui/common.go

+70-17
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,45 @@ package ui
33
import (
44
"fmt"
55

6+
"github.com/fatih/color"
67
"github.com/muesli/termenv"
78
)
89

910
// General stuff for styling the view
1011
var (
11-
term = termenv.EnvColorProfile()
12-
subtle = makeFgStyle("241")
13-
red = makeFgStyle("196")
14-
green = makeFgStyle("46")
15-
yellow = makeFgStyle("226")
12+
Term = termenv.EnvColorProfile()
13+
Subtle = MakeFgStyle("241")
14+
Red = MakeFgStyle("196")
15+
Green = MakeFgStyle("46")
16+
Yellow = MakeFgStyle("226")
1617
)
1718

1819
type (
19-
errMsg error
20+
// ErrMsg is an error message.
21+
ErrMsg error
2022
)
2123

22-
// makeFgStyle returns a function that will colorize the foreground of a given.
23-
func makeFgStyle(color string) func(string) string {
24-
return termenv.Style{}.Foreground(term.Color(color)).Styled
24+
// MakeFgStyle returns a function that will colorize the foreground of a given.
25+
func MakeFgStyle(color string) func(string) string {
26+
return termenv.Style{}.Foreground(Term.Color(color)).Styled
2527
}
2628

27-
// Color a string's foreground with the given value.
28-
func colorFg(val, color string) string {
29-
return termenv.String(val).Foreground(term.Color(color)).String()
29+
// ColorFg a string's foreground with the given value.
30+
func ColorFg(val, color string) string {
31+
return termenv.String(val).Foreground(Term.Color(color)).String()
3032
}
3133

32-
// checkbox represent [ ] and [x] items in the view.
33-
func checkbox(label string, checked bool) string {
34+
// Checkbox represent [ ] and [x] items in the view.
35+
func Checkbox(label string, checked bool) string {
3436
if checked {
35-
return colorFg("[x] "+label, "212")
37+
return ColorFg("[x] "+label, "212")
3638
}
3739
return fmt.Sprintf("[ ] %s", label)
3840
}
3941

40-
// split splits a string into multiple lines.
42+
// Split splits a string into multiple lines.
4143
// Each line has a maximum length of 80 characters.
42-
func split(s string) []string {
44+
func Split(s string) []string {
4345
var result []string
4446
for i := 0; i < len(s); i += 80 {
4547
end := i + 80
@@ -50,3 +52,54 @@ func split(s string) []string {
5052
}
5153
return result
5254
}
55+
56+
// GoodByeMessage returns a goodbye message.
57+
func GoodByeMessage() string {
58+
s := fmt.Sprintf("\n See you later 🌈\n %s\n %s\n\n",
59+
"Following URL for bug reports and encouragement (e.g. GitHub Star ⭐️ )",
60+
color.GreenString("https://github.com/nao1215/rainbow"))
61+
return s
62+
}
63+
64+
// ErrorMessage returns an error message.
65+
func ErrorMessage(err error) string {
66+
message := fmt.Sprintf("%s\n", Red("[Error]"))
67+
for _, line := range Split(err.Error()) {
68+
message += fmt.Sprintf(" %s\n", Red(line))
69+
}
70+
return message
71+
}
72+
73+
// Choice represents a choice.
74+
type Choice struct {
75+
Choice int
76+
Max int
77+
Min int
78+
}
79+
80+
// NewChoice returns a new choice.
81+
func NewChoice(min, max int) *Choice {
82+
return &Choice{
83+
Choice: min,
84+
Max: max,
85+
Min: min,
86+
}
87+
}
88+
89+
// Increment increments the choice.
90+
// If the choice is greater than the maximum, the choice is set to the minimum.
91+
func (c *Choice) Increment() {
92+
c.Choice++
93+
if c.Choice > c.Max {
94+
c.Choice = c.Min
95+
}
96+
}
97+
98+
// Decrement decrements the choice.
99+
// If the choice is less than the minimum, the choice is set to the maximum.
100+
func (c *Choice) Decrement() {
101+
c.Choice--
102+
if c.Choice < c.Min {
103+
c.Choice = c.Max
104+
}
105+
}

0 commit comments

Comments
 (0)