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 (
"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) {