forked from varia/go-sh-manymanuals
refactor: use same naming scheme
This commit is contained in:
parent
43a4f9b483
commit
b93af3a6b9
32
gshmm.go
32
gshmm.go
@ -62,12 +62,12 @@ func readPDF(name string) (string, error) {
|
|||||||
type model struct {
|
type model struct {
|
||||||
filterInput textinput.Model // Fuzzy search interface
|
filterInput textinput.Model // Fuzzy search interface
|
||||||
datasheets []datasheet // All datasheets under cwd
|
datasheets []datasheet // All datasheets under cwd
|
||||||
dataSheetsView []string // Filtered view on all datasheets
|
datasheetsView []string // Filtered view on all datasheets
|
||||||
dataSheetViewport viewport.Model // Viewport for the PDF content
|
datasheetViewport viewport.Model // Viewport for the PDF content
|
||||||
}
|
}
|
||||||
|
|
||||||
// dataSheetNames lists all datasheet names.
|
// datasheetNames lists all datasheet names.
|
||||||
func (m model) dataSheetNames() []string {
|
func (m model) datasheetNames() []string {
|
||||||
// TODO: cache this somewhere, it's called several times... in the model?
|
// TODO: cache this somewhere, it's called several times... in the model?
|
||||||
var names []string
|
var names []string
|
||||||
for _, datasheet := range m.datasheets {
|
for _, datasheet := range m.datasheets {
|
||||||
@ -130,9 +130,9 @@ func initialModel() model {
|
|||||||
m := model{
|
m := model{
|
||||||
filterInput: input,
|
filterInput: input,
|
||||||
datasheets: ds,
|
datasheets: ds,
|
||||||
dataSheetViewport: viewp,
|
datasheetViewport: viewp,
|
||||||
}
|
}
|
||||||
m.dataSheetsView = m.dataSheetNames()
|
m.datasheetsView = m.datasheetNames()
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
@ -154,26 +154,26 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
|
|
||||||
search := m.filterInput.Value()
|
search := m.filterInput.Value()
|
||||||
if len(search) >= minCharsUntilFilter {
|
if len(search) >= minCharsUntilFilter {
|
||||||
matches := fuzzy.Find(search, m.dataSheetNames())
|
matches := fuzzy.Find(search, m.datasheetNames())
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
matched = append(matched, match.Str)
|
matched = append(matched, match.Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(matches) > 0 {
|
if len(matches) > 0 {
|
||||||
m.dataSheetsView = matched
|
m.datasheetsView = matched
|
||||||
} else {
|
} else {
|
||||||
m.dataSheetsView = m.dataSheetNames()
|
m.datasheetsView = m.datasheetNames()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m.dataSheetsView = m.dataSheetNames()
|
m.datasheetsView = 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
|
||||||
// it's currently just the last one (closest to input)
|
// it's currently just the last one (closest to input)
|
||||||
lastDatasheet := m.dataSheetsView[len(m.dataSheetsView)-1]
|
lastdatasheet := m.datasheetsView[len(m.datasheetsView)-1]
|
||||||
viewportText := m.datasheetFromName(lastDatasheet)
|
viewportText := m.datasheetFromName(lastdatasheet)
|
||||||
m.dataSheetViewport.SetContent(viewportText)
|
m.datasheetViewport.SetContent(viewportText)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle terminal resizing
|
// 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)
|
m.filterInput, cmd = m.filterInput.Update(msg)
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
m.dataSheetViewport, cmd = m.dataSheetViewport.Update(msg)
|
m.datasheetViewport, cmd = m.datasheetViewport.Update(msg)
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
return m, tea.Batch(cmds...)
|
return m, tea.Batch(cmds...)
|
||||||
@ -199,10 +199,10 @@ func (m model) View() string {
|
|||||||
body := strings.Builder{}
|
body := strings.Builder{}
|
||||||
|
|
||||||
// TODO: paginate / trim view to last 10 or something?
|
// 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.
|
// 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)
|
body.WriteString(panes)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user