Skip to content

Commit 970b5dd

Browse files
authored
Merge pull request #1 from SaltFishPr/dev_load_animation
2 parents 897c930 + dda1b4a commit 970b5dd

File tree

13 files changed

+60
-31
lines changed

13 files changed

+60
-31
lines changed

.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ run:
1919
clean:
2020
sh scripts/clean.sh
2121

22-
.PHONY: generate
23-
# run go generate
24-
generate:
25-
go generate ./...
22+
.PHONY: release
23+
# release a version and push to github
24+
release:
25+
git tag -a v$(VERSION) -m "Release $(VERSION)"
26+
goreleaser release --rm-dist
2627

2728
# show help
2829
help:

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"log"
66
"os"
77

8-
"redis-viewer/internal/config"
9-
"redis-viewer/internal/tui"
8+
"github.com/SaltFishPr/redis-viewer/internal/config"
9+
"github.com/SaltFishPr/redis-viewer/internal/tui"
1010

1111
tea "github.com/charmbracelet/bubbletea"
1212
"github.com/go-redis/redis/v8"

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
module redis-viewer
1+
module github.com/SaltFishPr/redis-viewer
22

33
go 1.16
44

55
require (
6-
github.com/charmbracelet/bubbles v0.10.2
7-
github.com/charmbracelet/bubbletea v0.19.3
8-
github.com/charmbracelet/lipgloss v0.4.0
6+
github.com/charmbracelet/bubbles v0.10.3
7+
github.com/charmbracelet/bubbletea v0.20.0
8+
github.com/charmbracelet/lipgloss v0.5.0
99
github.com/go-redis/redis/v8 v8.11.4
1010
github.com/json-iterator/go v1.1.12
1111
github.com/muesli/reflow v0.3.0

go.sum

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
7373
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
7474
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
7575
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
76-
github.com/charmbracelet/bubbles v0.10.2 h1:VK1Q7nnBMDFTlrMmvBgE9nidtU5udsIcZvFXvjE2Cfk=
77-
github.com/charmbracelet/bubbles v0.10.2/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
78-
github.com/charmbracelet/bubbletea v0.19.3 h1:OKeO/Y13rQQqt4snX+lePB0QrnW80UdrMNolnCcmoAw=
76+
github.com/charmbracelet/bubbles v0.10.3 h1:fKarbRaObLn/DCsZO4Y3vKCwRUzynQD9L+gGev1E/ho=
77+
github.com/charmbracelet/bubbles v0.10.3/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
7978
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
79+
github.com/charmbracelet/bubbletea v0.20.0 h1:/b8LEPgCbNr7WWZ2LuE/BV1/r4t5PyYJtDb+J3vpwxc=
80+
github.com/charmbracelet/bubbletea v0.20.0/go.mod h1:zpkze1Rioo4rJELjRyGlm9T2YNou1Fm4LIJQSa5QMEM=
8081
github.com/charmbracelet/harmonica v0.1.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
81-
github.com/charmbracelet/lipgloss v0.4.0 h1:768h64EFkGUr8V5yAKV7/Ta0NiVceiPaV+PphaW1K9g=
8282
github.com/charmbracelet/lipgloss v0.4.0/go.mod h1:vmdkHvce7UzX6xkyf4cca8WlwdQ5RQr8fzta+xl7BOM=
83+
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
84+
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
8385
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
8486
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
8587
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -96,8 +98,9 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
9698
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
9799
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
98100
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
99-
github.com/containerd/console v1.0.2 h1:Pi6D+aZXM+oUw1czuKgH5IJ+y0jhYcwBJfx5/Ghn9dE=
100101
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
102+
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
103+
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
101104
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
102105
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
103106
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@@ -315,8 +318,10 @@ github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBc
315318
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
316319
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
317320
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
318-
github.com/muesli/termenv v0.9.0 h1:wnbOaGz+LUR3jNT0zOzinPnyDaCZUQRZj9GxK8eRVl8=
319321
github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw=
322+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
323+
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
324+
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
320325
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
321326
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
322327
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
@@ -335,7 +340,6 @@ github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhEC
335340
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
336341
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
337342
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
338-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
339343
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
340344
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
341345
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"path/filepath"
1212
"runtime"
1313

14-
"redis-viewer/internal/util"
14+
"github.com/SaltFishPr/redis-viewer/internal/util"
1515

1616
"github.com/spf13/viper"
1717
)

internal/tui/command.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"context"
99
"fmt"
1010

11-
"redis-viewer/internal/config"
12-
"redis-viewer/internal/util"
11+
"github.com/SaltFishPr/redis-viewer/internal/config"
12+
"github.com/SaltFishPr/redis-viewer/internal/util"
1313

1414
"github.com/charmbracelet/bubbles/list"
1515
tea "github.com/charmbracelet/bubbletea"
@@ -21,6 +21,9 @@ type errMsg struct {
2121

2222
type scanMsg struct {
2323
items []list.Item
24+
}
25+
26+
type countMsg struct {
2427
count int
2528
}
2629

@@ -63,7 +66,15 @@ func (m model) scanCmd() tea.Cmd {
6366
}
6467
}
6568

69+
return scanMsg{items: items}
70+
}
71+
}
72+
73+
func (m model) countCmd() tea.Cmd {
74+
return func() tea.Msg {
75+
ctx := context.Background()
6676
var count int
77+
6778
iter := m.rdb.Scan(ctx, 0, m.searchValue, 0).Iterator()
6879
for iter.Next(ctx) {
6980
count++
@@ -75,6 +86,6 @@ func (m model) scanCmd() tea.Cmd {
7586
return errMsg{err: err}
7687
}
7788

78-
return scanMsg{items: items, count: count}
89+
return countMsg{count: count}
7990
}
8091
}

internal/tui/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ package tui
66
import tea "github.com/charmbracelet/bubbletea"
77

88
func (m model) Init() tea.Cmd {
9-
return tea.Batch(m.scanCmd())
9+
return tea.Batch(m.spinner.Tick, m.scanCmd(), m.countCmd())
1010
}

internal/tui/tui.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package tui
66

77
import (
88
"github.com/charmbracelet/bubbles/list"
9+
"github.com/charmbracelet/bubbles/spinner"
910
"github.com/charmbracelet/bubbles/textinput"
1011
"github.com/charmbracelet/bubbles/viewport"
1112
"github.com/charmbracelet/lipgloss"
@@ -18,10 +19,12 @@ type model struct {
1819
list list.Model
1920
textinput textinput.Model
2021
viewport viewport.Model
22+
spinner spinner.Model
2123

2224
rdb *redis.Client
2325
searchValue string
2426
statusMessage string
27+
ready bool
2528

2629
keyMap
2730
state
@@ -39,9 +42,13 @@ func New(rdb *redis.Client) *model {
3942
l.SetShowHelp(false)
4043
l.SetFilteringEnabled(false)
4144

45+
s := spinner.New()
46+
s.Spinner = spinner.Dot
47+
4248
return &model{
4349
list: l,
4450
textinput: t,
51+
spinner: s,
4552

4653
rdb: rdb,
4754

internal/tui/update.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func (m *model) handleKeys(msg tea.KeyMsg) tea.Cmd {
4040
m.textinput.Focus()
4141
return textinput.Blink
4242
case key.Matches(msg, m.keyMap.scan):
43-
cmd = m.scanCmd()
44-
cmds = append(cmds, cmd)
43+
m.ready = false
44+
cmds = append(cmds, m.scanCmd(), m.countCmd())
4545
}
4646
case tea.KeyCtrlC:
4747
cmd = tea.Quit
@@ -66,8 +66,8 @@ func (m *model) handleKeys(msg tea.KeyMsg) tea.Cmd {
6666
m.textinput.Reset()
6767
m.state = defaultState
6868

69-
cmd = m.scanCmd()
70-
cmds = append(cmds, cmd)
69+
m.ready = false
70+
cmds = append(cmds, m.scanCmd(), m.countCmd())
7171
default:
7272
m.textinput, cmd = m.textinput.Update(msg)
7373
cmds = append(cmds, cmd)
@@ -100,11 +100,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
100100
m.viewport.SetContent(m.detailView())
101101
case scanMsg:
102102
m.list.SetItems(msg.items)
103+
case countMsg:
103104
if msg.count > maxScanCount {
104105
m.statusMessage = fmt.Sprintf("%d+ keys found", maxScanCount)
105106
} else {
106107
m.statusMessage = fmt.Sprintf("%d keys found", msg.count)
107108
}
109+
m.ready = true
108110
case tea.MouseMsg:
109111
m.handleMouse(msg)
110112
case tea.KeyMsg:
@@ -119,6 +121,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
119121

120122
m.viewport, cmd = m.viewport.Update(msg)
121123
cmds = append(cmds, cmd)
124+
125+
m.spinner, cmd = m.spinner.Update(msg)
126+
cmds = append(cmds, cmd)
122127
}
123128

124129
return m, tea.Batch(cmds...)

0 commit comments

Comments
 (0)