Skip to content

Commit 266b190

Browse files
authored
feat: hide preview mode (#96)
1 parent 461f7f0 commit 266b190

File tree

6 files changed

+98
-60
lines changed

6 files changed

+98
-60
lines changed

README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,26 @@ The application is designed to help in visualization, navigation, and analyzing
2626
## Table of content
2727

2828
- [JSON Log Viewer](#json-log-viewer)
29-
- [Table of content](#table-of-content)
30-
- [Usage](#usage)
31-
- [Install](#install)
32-
- [MacOS/Linux HomeBrew](#macoslinux-homebrew)
33-
- [Go](#go)
34-
- [Package](#package)
35-
- [Standalone Binary](#standalone-binary)
36-
- [Source](#source)
37-
- [Customization](#customization)
38-
- [Time Formats](#time-formats)
39-
- [`time`](#time)
40-
- [`numerictime`](#numerictime)
41-
- [`secondtime`](#secondtime)
42-
- [`millitime`](#millitime)
43-
- [`microtime`](#microtime)
44-
- [Resources](#resources)
45-
- [Contribution](#contribution)
46-
- [License](#license)
29+
- [Table of content](#table-of-content)
30+
- [Usage](#usage)
31+
- [Reading from file](#reading-from-file)
32+
- [Reading from Stdin](#reading-from-stdin)
33+
- [Hotkeys](#hotkeys)
34+
- [Install](#install)
35+
- [MacOS/Linux HomeBrew](#macoslinux-homebrew)
36+
- [Package](#package)
37+
- [Standalone Binary](#standalone-binary)
38+
- [Source](#source)
39+
- [Customization](#customization)
40+
- [Time Formats](#time-formats)
41+
- [`time`](#time)
42+
- [`numerictime`](#numerictime)
43+
- [`secondtime`](#secondtime)
44+
- [`millitime`](#millitime)
45+
- [`microtime`](#microtime)
46+
- [Resources](#resources)
47+
- [Contribution](#contribution)
48+
- [License](#license)
4749

4850
## Usage
4951

@@ -98,13 +100,6 @@ brew install hedhyw/main/jlv
98100
# jlv application.log
99101
```
100102

101-
### Go
102-
103-
```sh
104-
go install github.com/hedhyw/json-log-viewer/cmd/jlv@latest
105-
# jlv application.log
106-
```
107-
108103
### Package
109104

110105
Latest DEB and RPM packages are available on [the releases page](https://github.com/hedhyw/json-log-viewer/releases/latest).

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ module github.com/hedhyw/json-log-viewer
22

33
go 1.23
44

5-
replace github.com/antonmedv/fx => github.com/chirino/fx v0.0.0-20240818132837-248e67b184d9
5+
replace github.com/antonmedv/fx => github.com/hedhyw/fx v0.0.3
66

77
replace github.com/charmbracelet/bubbles => github.com/hedhyw/bubbles v0.0.4
88

99
require (
1010
github.com/antonmedv/fx v0.0.0-20240807042048-dd653cf7bf83
11-
github.com/charmbracelet/bubbles v0.18.0
11+
github.com/charmbracelet/bubbles v0.20.0
1212
github.com/charmbracelet/bubbletea v1.1.1
1313
github.com/charmbracelet/lipgloss v0.13.0
1414
github.com/go-playground/validator/v10 v10.22.1
@@ -22,29 +22,29 @@ require (
2222
require (
2323
github.com/atotto/clipboard v0.1.4 // indirect
2424
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
25-
github.com/charmbracelet/x/ansi v0.2.3 // indirect
25+
github.com/charmbracelet/x/ansi v0.3.2 // indirect
2626
github.com/charmbracelet/x/term v0.2.0 // indirect
2727
github.com/davecgh/go-spew v1.1.1 // indirect
2828
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
29-
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
29+
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
3030
github.com/go-playground/locales v0.14.1 // indirect
3131
github.com/go-playground/universal-translator v0.18.1 // indirect
3232
github.com/kr/text v0.2.0 // indirect
3333
github.com/leodido/go-urn v1.4.0 // indirect
3434
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
3535
github.com/mattn/go-isatty v0.0.20 // indirect
3636
github.com/mattn/go-localereader v0.0.1 // indirect
37-
github.com/mattn/go-runewidth v0.0.15 // indirect
37+
github.com/mattn/go-runewidth v0.0.16 // indirect
3838
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
3939
github.com/muesli/cancelreader v0.2.2 // indirect
4040
github.com/muesli/termenv v0.15.2 // indirect
4141
github.com/pmezard/go-difflib v1.0.0 // indirect
4242
github.com/rivo/uniseg v0.4.7 // indirect
4343
github.com/sahilm/fuzzy v0.1.1 // indirect
44-
golang.org/x/crypto v0.24.0 // indirect
45-
golang.org/x/net v0.26.0 // indirect
44+
golang.org/x/crypto v0.28.0 // indirect
45+
golang.org/x/net v0.30.0 // indirect
4646
golang.org/x/sync v0.8.0 // indirect
47-
golang.org/x/sys v0.24.0 // indirect
48-
golang.org/x/text v0.16.0 // indirect
47+
golang.org/x/sys v0.26.0 // indirect
48+
golang.org/x/text v0.19.0 // indirect
4949
gopkg.in/yaml.v3 v3.0.1 // indirect
5050
)

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ github.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqK
88
github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=
99
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
1010
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
11-
github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY=
12-
github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
11+
github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY=
12+
github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
1313
github.com/charmbracelet/x/exp/teatest v0.0.0-20230904163802-ca705a396e0f h1:kI7ZjLqp210CeIUKhjdLmtnc9UIVcfKSePgwGTxQ0J4=
1414
github.com/charmbracelet/x/exp/teatest v0.0.0-20230904163802-ca705a396e0f/go.mod h1:TckAxPtan3aJ5wbTgBkySpc50SZhXJRZ8PtYICnZJEw=
1515
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
1616
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
17-
github.com/chirino/fx v0.0.0-20240818132837-248e67b184d9 h1:v5OXoBrEplJ65ylCZ0gZ9DCTB7EWd+SWIvVL9jxdPTc=
18-
github.com/chirino/fx v0.0.0-20240818132837-248e67b184d9/go.mod h1:km/FnS8aa6d/z086KPzYtYzLv/lWMEnF275IS3wC0jE=
1917
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2018
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2119
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2220
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
2321
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
24-
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
25-
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
22+
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
23+
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
2624
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
2725
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
2826
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -33,6 +31,8 @@ github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27
3331
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
3432
github.com/hedhyw/bubbles v0.0.4 h1:4QZeYNa6KcE2CAszgQ07rSk4qd2EDj4FlH9Q3oECq5w=
3533
github.com/hedhyw/bubbles v0.0.4/go.mod h1:0B5SDVyyRXMteAgJRkYRJQ6bvsKtWdzeepp8rN+RhXQ=
34+
github.com/hedhyw/fx v0.0.3 h1:JR7w2nR1lWAzJXA5Hsp3pq76tdsG5cYJDC1P+z2eQuY=
35+
github.com/hedhyw/fx v0.0.3/go.mod h1:km/FnS8aa6d/z086KPzYtYzLv/lWMEnF275IS3wC0jE=
3636
github.com/hedhyw/jsoncjson v1.1.0 h1:uw/aqmbSXAQNJHDPLb+DpwlPNzMREGIsrs+TIwPk+f0=
3737
github.com/hedhyw/jsoncjson v1.1.0/go.mod h1:++nXlbEXzRMcqkoDLvH5I/z5qBkacAWSZDt1u6osUPc=
3838
github.com/hedhyw/semerr v0.6.7 h1:C9TaGpxJfbiiyyja+kFSZB9QK7vSNKc1RZPmWbXBmPI=
@@ -52,8 +52,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
5252
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
5353
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
5454
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
55-
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
56-
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
55+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
56+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
5757
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
5858
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
5959
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
@@ -76,18 +76,18 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
7676
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7777
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY=
7878
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI=
79-
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
80-
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
81-
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
82-
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
79+
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
80+
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
81+
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
82+
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
8383
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
8484
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
8585
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8686
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
87-
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
88-
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
89-
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
90-
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
87+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
88+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
89+
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
90+
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
9191
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9292
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
9393
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

internal/app/keymap.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type KeyMap struct {
1414
ToggleFullHelp key.Binding
1515
GotoTop key.Binding
1616
GotoBottom key.Binding
17+
ShowPreview key.Binding
1718
}
1819

1920
var defaultKeys = KeyMap{
@@ -60,6 +61,10 @@ var defaultKeys = KeyMap{
6061
key.WithKeys("end", "G"),
6162
key.WithHelp("end", "go to end"),
6263
),
64+
ShowPreview: key.NewBinding(
65+
key.WithKeys("p", "enter"),
66+
key.WithHelp("enter", "show preview"),
67+
),
6368
}
6469

6570
func (k KeyMap) ShortHelp() []key.Binding {

internal/app/stateviewrow.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package app
22

33
import (
4-
"github.com/charmbracelet/bubbles/key"
54
tea "github.com/charmbracelet/bubbletea"
65

76
"github.com/hedhyw/json-log-viewer/internal/pkg/events"
@@ -57,17 +56,25 @@ func (s StateViewRowModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5756

5857
s.Application.Update(msg)
5958

60-
switch msg := msg.(type) {
61-
case events.ErrorOccuredMsg:
59+
if msg, ok := msg.(events.ErrorOccuredMsg); ok {
6260
return s.handleErrorOccuredMsg(msg)
63-
case tea.KeyMsg:
64-
if key.Matches(msg, s.keys.Back) {
65-
return s.previousState.refresh()
66-
}
6761
}
6862

6963
s.jsonView, cmd = s.jsonView.Update(msg)
7064

65+
// Intercept the quit message, but keep the command.
66+
if cmd != nil {
67+
msg = cmd()
68+
69+
cmd = func() tea.Msg {
70+
return msg
71+
}
72+
73+
if msg == tea.Quit() {
74+
return s.previousState.refresh()
75+
}
76+
}
77+
7178
return s, cmd
7279
}
7380

internal/app/stateviewrow_test.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ import (
1414
)
1515

1616
func TestStateViewRow(t *testing.T) {
17-
setup := func(t *testing.T) tea.Model {
18-
t.Parallel()
17+
t.Parallel()
1918

19+
setup := func(t *testing.T) tea.Model {
2020
model := newTestModel(t, assets.ExampleJSONLog())
2121
model = handleUpdate(model, tea.KeyMsg{Type: tea.KeyEnter})
2222
_, ok := model.(app.StateViewRowModel)
2323

2424
require.Truef(t, ok, "%s", model)
25+
2526
return model
2627
}
2728

2829
t.Run("close", func(t *testing.T) {
30+
t.Parallel()
31+
2932
model := setup(t)
3033

3134
model = handleUpdate(model, tea.KeyMsg{Type: tea.KeyEsc})
@@ -34,6 +37,8 @@ func TestStateViewRow(t *testing.T) {
3437
})
3538

3639
t.Run("stringer", func(t *testing.T) {
40+
t.Parallel()
41+
3742
model := setup(t)
3843

3944
stringer, ok := model.(fmt.Stringer)
@@ -43,15 +48,18 @@ func TestStateViewRow(t *testing.T) {
4348
})
4449

4550
t.Run("error", func(t *testing.T) {
51+
t.Parallel()
52+
4653
model := setup(t)
4754
model = handleUpdate(model, events.ErrorOccuredMsg{Err: getTestError()})
4855

4956
_, ok := model.(app.StateErrorModel)
5057
assert.Truef(t, ok, "%s", model)
5158
})
5259

53-
// nolint: tparallel // antonmedv/fx uses mutable model.
5460
t.Run("navigation", func(t *testing.T) {
61+
t.Parallel()
62+
5563
model := setup(t)
5664
model = handleUpdate(model, tea.KeyMsg{
5765
Type: tea.KeyRight,
@@ -60,4 +68,27 @@ func TestStateViewRow(t *testing.T) {
6068
_, ok := model.(app.StateViewRowModel)
6169
assert.Truef(t, ok, "%s", model)
6270
})
71+
72+
t.Run("preview", func(t *testing.T) {
73+
t.Parallel()
74+
75+
model := setup(t)
76+
model = handleUpdate(model, tea.KeyMsg{
77+
Type: tea.KeyDown,
78+
})
79+
80+
// Open the preview mode.
81+
model = handleUpdate(model, tea.KeyMsg{
82+
Type: tea.KeyRunes,
83+
Runes: []rune{'p'},
84+
})
85+
assert.NotContains(t, model.View(), "message")
86+
87+
// Hide the preview mode.
88+
model = handleUpdate(model, tea.KeyMsg{
89+
Type: tea.KeyEsc,
90+
Runes: []rune{'p'},
91+
})
92+
assert.Contains(t, model.View(), "message")
93+
})
6394
}

0 commit comments

Comments
 (0)