forked from varia/go-sh-manymanuals
feat: filter mode switcher
This commit is contained in:
parent
4307d4e117
commit
3628337a9a
32
gshmm.go
32
gshmm.go
@ -16,6 +16,12 @@ import (
|
|||||||
"github.com/sahilm/fuzzy"
|
"github.com/sahilm/fuzzy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// filenameFilterMode searches by PDF file name.
|
||||||
|
const filenameFilterMode = "filename"
|
||||||
|
|
||||||
|
// contentFilterMode searches by PDF contents.
|
||||||
|
const contentFilterMode = "content"
|
||||||
|
|
||||||
// help is the command-line interface help output.
|
// help is the command-line interface help output.
|
||||||
const help = `go-sh-manymanuals: TODO
|
const help = `go-sh-manymanuals: TODO
|
||||||
|
|
||||||
@ -67,6 +73,8 @@ type model struct {
|
|||||||
filteredDatasheets []string // Filtered view on all datasheets
|
filteredDatasheets []string // Filtered view on all datasheets
|
||||||
|
|
||||||
datasheetViewport viewport.Model // Viewport for the PDF content
|
datasheetViewport viewport.Model // Viewport for the PDF content
|
||||||
|
|
||||||
|
filterMode string // The filtering mode ("filename", "content")
|
||||||
}
|
}
|
||||||
|
|
||||||
// datasheetFromName retrieves a datasheet via a name.
|
// datasheetFromName retrieves a datasheet via a name.
|
||||||
@ -79,6 +87,15 @@ func (m model) datasheetFromName(name string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toggleFilterMode toggles the filter mode.
|
||||||
|
func (m *model) toggleFilterMode() {
|
||||||
|
if m.filterMode == filenameFilterMode {
|
||||||
|
m.filterMode = contentFilterMode
|
||||||
|
} else {
|
||||||
|
m.filterMode = filenameFilterMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// datasheet represents a datasheet on disk.
|
// datasheet represents a datasheet on disk.
|
||||||
type datasheet struct {
|
type datasheet struct {
|
||||||
filename string // The name of the file
|
filename string // The name of the file
|
||||||
@ -132,6 +149,7 @@ func initialModel() model {
|
|||||||
datasheetNames: datasheetNames,
|
datasheetNames: datasheetNames,
|
||||||
filteredDatasheets: datasheetNames,
|
filteredDatasheets: datasheetNames,
|
||||||
datasheetViewport: viewp,
|
datasheetViewport: viewp,
|
||||||
|
filterMode: filenameFilterMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
@ -182,6 +200,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "ctrl+c":
|
case "ctrl+c":
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
case "tab":
|
||||||
|
m.toggleFilterMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +228,18 @@ func (m model) View() string {
|
|||||||
|
|
||||||
body.WriteString("\n" + m.input.View())
|
body.WriteString("\n" + m.input.View())
|
||||||
|
|
||||||
|
mode := "filter: "
|
||||||
|
if m.filterMode == filenameFilterMode {
|
||||||
|
mode += "filename"
|
||||||
|
} else {
|
||||||
|
// TODO make this mode actually work once we figure out bleve
|
||||||
|
mode += "content (FIXME)"
|
||||||
|
}
|
||||||
|
body.WriteString("\n" + mode)
|
||||||
|
|
||||||
|
help := "[ctrl-c]: quit | [tab]: filter mode"
|
||||||
|
body.WriteString("\n" + help)
|
||||||
|
|
||||||
return body.String()
|
return body.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user