forked from varia/go-sh-manymanuals
feat: xdg-open pdfs with enter
This commit is contained in:
parent
6bbd94cba6
commit
38b604dde3
3
go.mod
3
go.mod
@ -7,7 +7,9 @@ require (
|
||||
github.com/charmbracelet/bubbletea v0.23.1
|
||||
github.com/charmbracelet/lipgloss v0.6.0
|
||||
github.com/johbar/go-poppler v0.0.0-20221016201615-2d089fcde50c
|
||||
github.com/rkoesters/xdg v0.0.1
|
||||
github.com/sahilm/fuzzy v0.1.0
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||
)
|
||||
|
||||
require (
|
||||
@ -25,6 +27,5 @@ require (
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/ungerik/go-cairo v0.0.0-20220815093914-e24bd4259cef // indirect
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -40,6 +40,8 @@ github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4Y
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rkoesters/xdg v0.0.1 h1:RmfYxghVvIsb4d51u5LtNOcwqY5r3P44u6o86qqvBMA=
|
||||
github.com/rkoesters/xdg v0.0.1/go.mod h1:5DcbjvJkY00fIOKkaBnylbC/rmc1NNJP5dmUcnlcm7U=
|
||||
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
|
||||
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||
github.com/ungerik/go-cairo v0.0.0-20220815093914-e24bd4259cef h1:zpOobzu7pmkVFs/XNuhJvxHCdQrGWxybcfVDabi//B4=
|
||||
|
11
gshmm.go
11
gshmm.go
@ -15,6 +15,7 @@ import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
pdf "github.com/johbar/go-poppler"
|
||||
"github.com/rkoesters/xdg"
|
||||
"github.com/sahilm/fuzzy"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
@ -256,8 +257,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.datasheetNames = msg.datasheetNames
|
||||
m.filteredDatasheets = msg.datasheetNames
|
||||
|
||||
selectedDatasheet := msg.datasheets[len(msg.datasheets)-1].contents
|
||||
m.datasheetViewport.SetContent(selectedDatasheet)
|
||||
selectedDatasheet := msg.datasheets[len(msg.datasheets)-1]
|
||||
m.datasheetViewport.SetContent(selectedDatasheet.contents)
|
||||
|
||||
m.datasheetsLoaded = true
|
||||
case tea.WindowSizeMsg:
|
||||
@ -269,6 +270,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, tea.Quit
|
||||
case "tab":
|
||||
m.toggleFilterMode()
|
||||
case "enter":
|
||||
selectedDatasheet := m.datasheets[len(m.datasheets)-1]
|
||||
// TODO: handle error
|
||||
_ = xdg.Open(selectedDatasheet.absPath)
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +312,7 @@ func (m model) View() string {
|
||||
}
|
||||
body.WriteString("\n" + mode)
|
||||
|
||||
help := "[ctrl-c]: quit | [tab]: filter mode"
|
||||
help := "[ctrl-c]: quit | [tab]: filter mode | [enter]: open"
|
||||
body.WriteString("\n" + help)
|
||||
|
||||
return body.String()
|
||||
|
Loading…
Reference in New Issue
Block a user