-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.go
42 lines (38 loc) · 724 Bytes
/
edit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"io/ioutil"
"log"
"strings"
"github.com/ktr0731/go-fuzzyfinder"
)
func selectFile() string {
path := ""
return path
}
func selectPage(pages []Page) string {
idx, err := fuzzyfinder.FindMulti(
pages,
func(i int) string {
return pages[i].name
},
fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
if i == -1 {
return ""
}
return fmt.Sprintf("%s:\n%s\n %s",
pages[i].name,
strings.Repeat("-", w),
func() string {
text, err := ioutil.ReadFile(pages[i].path)
if err != nil {
return "ファイルが開けません。"
}
return string(text)
}())
}))
if err != nil {
log.Fatal(err)
}
return pages[idx[0]].path
}