wip: show filtered pdf contents

This commit is contained in:
decentral1se 2023-05-10 14:35:13 +02:00
parent 73bd0d74f1
commit 54425e1ee0
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410

View File

@ -3,7 +3,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -69,6 +68,15 @@ func (m model) dataSheetNames() []string {
return names 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 { type datasheet struct {
filename string filename string
absPath string absPath string
@ -89,6 +97,9 @@ func initialModel() model {
name := info.Name() name := info.Name()
if strings.HasSuffix(name, "pdf") { if strings.HasSuffix(name, "pdf") {
// TODO: handle error in interface? // 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) contents, _ := readPDF(path)
d := datasheet{ d := datasheet{
filename: name, filename: name,
@ -96,7 +107,6 @@ func initialModel() model {
contents: contents, contents: contents,
} }
ds = append(ds, d) ds = append(ds, d)
log.Print(d)
} }
return nil return nil
@ -144,6 +154,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} else { } else {
m.dataSheetsView = m.dataSheetNames() m.dataSheetsView = m.dataSheetNames()
} }
lastDatasheet := m.dataSheetsView[len(m.dataSheetsView)-1]
viewportText := m.datasheetFromName(lastDatasheet)
m.dataSheetViewport.SetContent(viewportText)
} }
switch msg := msg.(type) { switch msg := msg.(type) {