Initial fork of github.com/alonswartz/notesium into librenotes: - Source moved to internal/notesium/ (package notesium) - Thin entry point at cmd/librenotes/main.go - Module renamed to git.librete.ch/public/librenotes - main() exposed as notesium.Run() - LICENSE preserved (MIT), NOTICE added with attribution - Web assets and completion.bash co-located with embedding code to satisfy go:embed path constraints Closes #3, #34, #35. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
956 B
Go
55 lines
956 B
Go
package notesium
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
fzf "github.com/junegunn/fzf/src"
|
|
)
|
|
|
|
type channelWriter struct {
|
|
ch chan string
|
|
}
|
|
|
|
func (cw *channelWriter) Write(p []byte) (n int, err error) {
|
|
str := string(p) // Convert bytes to string
|
|
cw.ch <- str // Send to channel
|
|
return len(p), nil
|
|
}
|
|
|
|
func runFinder(inputChan chan string, opts []string) ([]string, int, error) {
|
|
options, err := fzf.ParseOptions(false, opts)
|
|
if err != nil {
|
|
return nil, 2, fmt.Errorf("fzf error: %w", err)
|
|
}
|
|
|
|
outputChan := make(chan string)
|
|
resultChan := make(chan struct {
|
|
code int
|
|
err error
|
|
}, 1)
|
|
|
|
options.Input = inputChan
|
|
options.Output = outputChan
|
|
|
|
go func() {
|
|
code, runErr := fzf.Run(options)
|
|
close(outputChan)
|
|
|
|
resultChan <- struct {
|
|
code int
|
|
err error
|
|
}{code, runErr}
|
|
|
|
close(resultChan)
|
|
}()
|
|
|
|
var lines []string
|
|
for line := range outputChan {
|
|
lines = append(lines, line)
|
|
}
|
|
|
|
result := <-resultChan
|
|
return lines, result.code, result.err
|
|
}
|
|
|