refactor: use same naming scheme

This commit is contained in:
decentral1se 2023-05-10 18:36:13 +02:00
parent 43a4f9b483
commit b93af3a6b9
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410

View File

@ -62,12 +62,12 @@ func readPDF(name string) (string, error) {
type model struct {
filterInput textinput.Model // Fuzzy search interface
datasheets []datasheet // All datasheets under cwd
dataSheetsView []string // Filtered view on all datasheets
dataSheetViewport viewport.Model // Viewport for the PDF content
datasheetsView []string // Filtered view on all datasheets
datasheetViewport viewport.Model // Viewport for the PDF content
}
// dataSheetNames lists all datasheet names.
func (m model) dataSheetNames() []string {
// datasheetNames lists all datasheet names.
func (m model) datasheetNames() []string {
// TODO: cache this somewhere, it's called several times... in the model?
var names []string
for _, datasheet := range m.datasheets {
@ -130,9 +130,9 @@ func initialModel() model {
m := model{
filterInput: input,
datasheets: ds,
dataSheetViewport: viewp,
datasheetViewport: viewp,
}
m.dataSheetsView = m.dataSheetNames()
m.datasheetsView = m.datasheetNames()
return m
}
@ -154,26 +154,26 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
search := m.filterInput.Value()
if len(search) >= minCharsUntilFilter {
matches := fuzzy.Find(search, m.dataSheetNames())
matches := fuzzy.Find(search, m.datasheetNames())
for _, match := range matches {
matched = append(matched, match.Str)
}
if len(matches) > 0 {
m.dataSheetsView = matched
m.datasheetsView = matched
} else {
m.dataSheetsView = m.dataSheetNames()
m.datasheetsView = m.datasheetNames()
}
} else {
m.dataSheetsView = m.dataSheetNames()
m.datasheetsView = m.datasheetNames()
}
// 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)
lastDatasheet := m.dataSheetsView[len(m.dataSheetsView)-1]
viewportText := m.datasheetFromName(lastDatasheet)
m.dataSheetViewport.SetContent(viewportText)
lastdatasheet := m.datasheetsView[len(m.datasheetsView)-1]
viewportText := m.datasheetFromName(lastdatasheet)
m.datasheetViewport.SetContent(viewportText)
}
// TODO: handle terminal resizing
@ -188,7 +188,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.filterInput, cmd = m.filterInput.Update(msg)
cmds = append(cmds, cmd)
m.dataSheetViewport, cmd = m.dataSheetViewport.Update(msg)
m.datasheetViewport, cmd = m.datasheetViewport.Update(msg)
cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
@ -199,10 +199,10 @@ func (m model) View() string {
body := strings.Builder{}
// TODO: paginate / trim view to last 10 or something?
sheets := strings.Join(m.dataSheetsView, "\n")
sheets := strings.Join(m.datasheetsView, "\n")
// TODO: style further with lipgloss, e.g. borders, margins, etc.
panes := lipgloss.JoinHorizontal(lipgloss.Left, sheets, m.dataSheetViewport.View())
panes := lipgloss.JoinHorizontal(lipgloss.Left, sheets, m.datasheetViewport.View())
body.WriteString(panes)