Browse Source

refactor: TODO wording & simpler filtering

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

40
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,32 +162,36 @@ func (m model) Init() tea.Cmd {
return textinput.Blink
}
// Update updates the program state.
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var (
cmd tea.Cmd
cmds []tea.Cmd
)
// filterDatasheetNames filters datasheet names based on user input.
func filterDatasheetNames(m model) []string {
search := m.input.Value()
if !(len(search) >= minCharsUntilFilter) {
return m.datasheetNames
}
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
return matchedDatasheets
}
return m.datasheetNames
}
// Update updates the program state.
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var (
cmd tea.Cmd
cmds []tea.Cmd
)
if m.input.Focused() {
m.filteredDatasheets = filterDatasheetNames(m)
// TODO: implement cursor for scrolling up/down filtered
// results so we can view the PDF contents as desired
// it's currently just the last one (closest to input)

Loading…
Cancel
Save