forked from varia/go-sh-manymanuals
wip: show filtered pdf contents
This commit is contained in:
parent
73bd0d74f1
commit
54425e1ee0
18
gshmm.go
18
gshmm.go
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -69,6 +68,15 @@ func (m model) dataSheetNames() []string {
|
||||
return names
|
||||
}
|
||||
|
||||
func (m model) datasheetFromName(name string) string {
|
||||
for _, d := range m.datasheets {
|
||||
if d.filename == name {
|
||||
return d.contents
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type datasheet struct {
|
||||
filename string
|
||||
absPath string
|
||||
@ -89,6 +97,9 @@ func initialModel() model {
|
||||
name := info.Name()
|
||||
if strings.HasSuffix(name, "pdf") {
|
||||
// TODO: handle error in interface?
|
||||
// TODO: don't read them all up front while blocking?
|
||||
// we could run this in a goroutine somewhere
|
||||
// this currently slows down startup time
|
||||
contents, _ := readPDF(path)
|
||||
d := datasheet{
|
||||
filename: name,
|
||||
@ -96,7 +107,6 @@ func initialModel() model {
|
||||
contents: contents,
|
||||
}
|
||||
ds = append(ds, d)
|
||||
log.Print(d)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -144,6 +154,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
} else {
|
||||
m.dataSheetsView = m.dataSheetNames()
|
||||
}
|
||||
|
||||
lastDatasheet := m.dataSheetsView[len(m.dataSheetsView)-1]
|
||||
viewportText := m.datasheetFromName(lastDatasheet)
|
||||
m.dataSheetViewport.SetContent(viewportText)
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
|
Loading…
Reference in New Issue
Block a user