forked from varia/go-sh-manymanuals
refactor: TODO wording & simpler filtering
This commit is contained in:
parent
3628337a9a
commit
bec540d8e5
42
gshmm.go
42
gshmm.go
@ -138,7 +138,9 @@ func initialModel() model {
|
|||||||
return nil
|
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)
|
viewp := viewport.New(60, 30)
|
||||||
selectedDatasheet := datasheets[len(datasheets)-1].contents
|
selectedDatasheet := datasheets[len(datasheets)-1].contents
|
||||||
viewp.SetContent(selectedDatasheet)
|
viewp.SetContent(selectedDatasheet)
|
||||||
@ -160,6 +162,26 @@ func (m model) Init() tea.Cmd {
|
|||||||
return textinput.Blink
|
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.
|
// Update updates the program state.
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var (
|
var (
|
||||||
@ -168,23 +190,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if m.input.Focused() {
|
if m.input.Focused() {
|
||||||
var matchedDatasheets []string
|
m.filteredDatasheets = filterDatasheetNames(m)
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: implement cursor for scrolling up/down filtered
|
// TODO: implement cursor for scrolling up/down filtered
|
||||||
// results so we can view the PDF contents as desired
|
// results so we can view the PDF contents as desired
|
||||||
|
Loading…
Reference in New Issue
Block a user