diff --git a/gshmm.go b/gshmm.go index 8a0360d..ec4e52f 100644 --- a/gshmm.go +++ b/gshmm.go @@ -16,6 +16,12 @@ import ( "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. const help = `go-sh-manymanuals: TODO @@ -67,6 +73,8 @@ type model struct { filteredDatasheets []string // Filtered view on all datasheets datasheetViewport viewport.Model // Viewport for the PDF content + + filterMode string // The filtering mode ("filename", "content") } // datasheetFromName retrieves a datasheet via a name. @@ -79,6 +87,15 @@ func (m model) datasheetFromName(name string) string { 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. type datasheet struct { filename string // The name of the file @@ -132,6 +149,7 @@ func initialModel() model { datasheetNames: datasheetNames, filteredDatasheets: datasheetNames, datasheetViewport: viewp, + filterMode: filenameFilterMode, } return m @@ -182,6 +200,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg.String() { case "ctrl+c": return m, tea.Quit + case "tab": + m.toggleFilterMode() } } @@ -208,6 +228,18 @@ func (m model) View() string { 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() }