Browse Source

refactor: TODO wording & simpler filtering

main
decentral1se 12 months ago
parent
commit
bec540d8e5
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 42
      gshmm.go

42
gshmm.go

@ -138,7 +138,9 @@ func initialModel() model {
return nil
})
// TODO: set width/heigh to match terminal
// TODO: set width/heigh to match terminal. this should also
// be set in relation to the list of filenames also. they
// should have some visually pleasing ratio set i imagine
viewp := viewport.New(60, 30)
selectedDatasheet := datasheets[len(datasheets)-1].contents
viewp.SetContent(selectedDatasheet)
@ -160,6 +162,26 @@ func (m model) Init() tea.Cmd {
return textinput.Blink
}
// filterDatasheetNames filters datasheet names based on user input.
func filterDatasheetNames(m model) []string {
search := m.input.Value()
if !(len(search) >= minCharsUntilFilter) {
return m.datasheetNames
}
var matchedDatasheets []string
matches := fuzzy.Find(search, m.datasheetNames)
for _, match := range matches {
matchedDatasheets = append(matchedDatasheets, match.Str)
}
if len(matches) > 0 {
return matchedDatasheets
}
return m.datasheetNames
}
// Update updates the program state.
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var (
@ -168,23 +190,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
if m.input.Focused() {
var matchedDatasheets []string
search := m.input.Value()
if len(search) >= minCharsUntilFilter {
matches := fuzzy.Find(search, m.datasheetNames)
for _, match := range matches {
matchedDatasheets = append(matchedDatasheets, match.Str)
}
if len(matches) > 0 {
m.filteredDatasheets = matchedDatasheets
} else {
m.filteredDatasheets = m.datasheetNames
}
} else {
m.filteredDatasheets = m.datasheetNames
}
m.filteredDatasheets = filterDatasheetNames(m)
// TODO: implement cursor for scrolling up/down filtered
// results so we can view the PDF contents as desired

Loading…
Cancel
Save