|
@ -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,32 +162,36 @@ func (m model) Init() tea.Cmd { |
|
|
return textinput.Blink |
|
|
return textinput.Blink |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Update updates the program state.
|
|
|
// filterDatasheetNames filters datasheet names based on user input.
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
|
|
func filterDatasheetNames(m model) []string { |
|
|
var ( |
|
|
search := m.input.Value() |
|
|
cmd tea.Cmd |
|
|
if !(len(search) >= minCharsUntilFilter) { |
|
|
cmds []tea.Cmd |
|
|
return m.datasheetNames |
|
|
) |
|
|
} |
|
|
|
|
|
|
|
|
if m.input.Focused() { |
|
|
|
|
|
var matchedDatasheets []string |
|
|
var matchedDatasheets []string |
|
|
|
|
|
|
|
|
search := m.input.Value() |
|
|
|
|
|
if len(search) >= minCharsUntilFilter { |
|
|
|
|
|
matches := fuzzy.Find(search, m.datasheetNames) |
|
|
matches := fuzzy.Find(search, m.datasheetNames) |
|
|
for _, match := range matches { |
|
|
for _, match := range matches { |
|
|
matchedDatasheets = append(matchedDatasheets, match.Str) |
|
|
matchedDatasheets = append(matchedDatasheets, match.Str) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if len(matches) > 0 { |
|
|
if len(matches) > 0 { |
|
|
m.filteredDatasheets = matchedDatasheets |
|
|
return matchedDatasheets |
|
|
} else { |
|
|
|
|
|
m.filteredDatasheets = m.datasheetNames |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
m.filteredDatasheets = m.datasheetNames |
|
|
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
|
|
|
// 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
|
|
|
// it's currently just the last one (closest to input)
|
|
|
// it's currently just the last one (closest to input)
|
|
|