Skip to content

Commit 27a2e41

Browse files
committed
feat!: major UI overhaul with BubbleTea TUI
1 parent 91bfe6e commit 27a2e41

File tree

7 files changed

+619
-95
lines changed

7 files changed

+619
-95
lines changed

.goreleaser.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
77
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
88

9-
version: 1
9+
version: 2
1010

1111
before:
1212
hooks:
@@ -24,7 +24,7 @@ builds:
2424
- darwin
2525

2626
archives:
27-
- format: tar.gz
27+
- formats: [ 'tar.gz' ]
2828
# this name template makes the OS and Arch compatible with the results of `uname`.
2929
name_template: >-
3030
{{ .ProjectName }}_
@@ -36,7 +36,7 @@ archives:
3636
# use zip for windows archives
3737
format_overrides:
3838
- goos: windows
39-
format: zip
39+
formats: [ 'zip' ]
4040

4141
changelog:
4242
sort: asc

cmd/root.go

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,34 @@ package cmd
22

33
import (
44
"os"
5-
"strings"
65

7-
"github.com/manifoldco/promptui"
86
"github.com/neptship/ignore/internal"
97
"github.com/spf13/cobra"
108
)
119

1210
var rootCmd = &cobra.Command{
1311
Use: "ignore",
14-
Short: "Create files .ignore quickly and simply",
15-
Run: func(cmd *cobra.Command, args []string) {
16-
ignoreFile, err := chooseIgnoreFile()
12+
Short: "Create files .ignore quickly and simply", Run: func(cmd *cobra.Command, args []string) {
13+
ignoreFile, template, err := chooseBothViaTUI()
1714
if err != nil {
1815
internal.CallClear()
1916
os.Exit(1)
2017
}
21-
ignoreTemplate, err := chooseIgnoreTemplate()
22-
if err != nil {
18+
19+
if ignoreFile == "" || template == "" {
2320
internal.CallClear()
24-
os.Exit(1)
21+
return
2522
}
26-
internal.AddIgnoreTemplate(ignoreFile, ignoreTemplate)
27-
},
28-
}
29-
30-
func chooseIgnoreFile() (string, error) {
31-
tr := internal.NewTemplateRegistry()
32-
templatesIgnore := tr.List()
33-
34-
templates := &promptui.SelectTemplates{
35-
Active: `{{">" | blue | bold }} {{ . | blue | bold }}`,
36-
Inactive: `{{.}}`,
37-
Selected: `{{ "√ " | green | bold }} {{ "Choose .ignore file" | bold }} {{"»" | black}} {{ . | blue }}`,
38-
Label: `{{ . | bold }}`,
39-
}
4023

41-
prompt := promptui.Select{
42-
Label: promptui.IconInitial + " Choose .ignore file",
43-
Templates: templates,
44-
Items: internal.IgnoreFiles,
45-
Size: 8,
46-
Searcher: func(input string, index int) bool {
47-
pepper := templatesIgnore[index]
48-
name := strings.Replace(strings.ToLower(pepper), " ", "", -1)
49-
input = strings.Replace(strings.ToLower(input), " ", "", -1)
50-
51-
return strings.Contains(name, input)
52-
},
53-
}
54-
55-
_, ignoreFile, err := prompt.Run()
56-
return ignoreFile, err
24+
internal.AddIgnoreTemplate(ignoreFile, template)
25+
},
5726
}
5827

59-
func chooseIgnoreTemplate() (string, error) {
28+
func chooseBothViaTUI() (string, string, error) {
6029
tr := internal.NewTemplateRegistry()
61-
templatesIgnore := tr.List()
62-
63-
templates := &promptui.SelectTemplates{
64-
Active: `{{">" | blue | bold }} {{ . | blue | bold }}`,
65-
Inactive: `{{ . | underline}}`,
66-
Selected: `{{ "√ " | green | bold }} {{ "Choose .ignore template" | bold }} {{"»" | black}} {{ . | blue }}`,
67-
Label: `{{ . | bold }}`,
68-
}
69-
70-
prompt := promptui.Select{
71-
Label: promptui.IconInitial + " Choose .ignore template",
72-
Templates: templates,
73-
Items: templatesIgnore,
74-
Size: 8,
75-
Searcher: func(input string, index int) bool {
76-
pepper := templatesIgnore[index]
77-
name := strings.Replace(strings.ToLower(pepper), " ", "", -1)
78-
input = strings.Replace(strings.ToLower(input), " ", "", -1)
79-
80-
return strings.Contains(name, input)
81-
},
82-
}
30+
templates := tr.List()
8331

84-
_, ignoreTemplate, err := prompt.Run()
85-
return ignoreTemplate, err
32+
return internal.RunBubbleTUI(internal.IgnoreFiles, templates)
8633
}
8734

8835
func Execute() {

go.mod

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
module github.com/neptship/ignore
22

3-
go 1.21
3+
go 1.23.0
44

5-
require github.com/spf13/cobra v1.8.0
5+
toolchain go1.24.2
6+
7+
require (
8+
github.com/charmbracelet/bubbletea v1.3.6
9+
github.com/charmbracelet/lipgloss v1.1.0
10+
github.com/spf13/cobra v1.8.0
11+
)
12+
13+
require (
14+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
15+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
16+
github.com/charmbracelet/x/ansi v0.9.3 // indirect
17+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
18+
github.com/charmbracelet/x/term v0.2.1 // indirect
19+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
20+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
21+
github.com/mattn/go-localereader v0.0.1 // indirect
22+
github.com/mattn/go-runewidth v0.0.16 // indirect
23+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
24+
github.com/muesli/cancelreader v0.2.2 // indirect
25+
github.com/muesli/termenv v0.16.0 // indirect
26+
github.com/rivo/uniseg v0.4.7 // indirect
27+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
28+
golang.org/x/sync v0.15.0 // indirect
29+
golang.org/x/text v0.3.8 // indirect
30+
)
631

732
require (
8-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
933
github.com/fatih/color v1.13.0
1034
github.com/inconshreveable/mousetrap v1.1.0 // indirect
11-
github.com/manifoldco/promptui v0.9.0
1235
github.com/mattn/go-colorable v0.1.9 // indirect
13-
github.com/mattn/go-isatty v0.0.18 // indirect
36+
github.com/mattn/go-isatty v0.0.20 // indirect
1437
github.com/spf13/pflag v1.0.5 // indirect
15-
golang.org/x/sys v0.13.0 // indirect
38+
golang.org/x/sys v0.33.0 // indirect
1639
)

go.sum

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,64 @@
1-
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
2-
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
3-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
4-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
5-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
6-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
1+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
2+
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
3+
github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU=
4+
github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc=
5+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
6+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
7+
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
8+
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
9+
github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0=
10+
github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
11+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
12+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
13+
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
14+
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
715
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
16+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
17+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
818
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
919
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
1020
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
1121
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
12-
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
13-
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
22+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
23+
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
1424
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
1525
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
1626
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
1727
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
18-
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
19-
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
28+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
29+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
30+
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
31+
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
32+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
33+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
34+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
35+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
36+
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
37+
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
38+
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
39+
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
40+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
41+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
42+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
2043
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
2144
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
2245
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
2346
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
2447
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
25-
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
48+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
49+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
50+
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
51+
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
52+
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
53+
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
2654
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2755
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2856
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
57+
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2958
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30-
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
31-
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
59+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
60+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
61+
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
62+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
3263
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3364
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)