-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.go
49 lines (43 loc) · 978 Bytes
/
new.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
43
44
45
46
47
48
49
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"github.com/ktr0731/go-fuzzyfinder"
)
func selectCategory(categories []Category) string {
cwd, _ := os.Getwd()
idx, err := fuzzyfinder.FindMulti(
categories,
func(i int) string {
return categories[i].name
},
fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
if i == -1 {
return ""
}
return fmt.Sprintf("カテゴリー: %s\n%s\n%s",
categories[i].name,
strings.Repeat("-", w),
func() string {
// pages[i].path
text, err := ioutil.ReadFile(
filepath.Join(
cwd,
categories[i].name,
"README.md"))
if err != nil {
return "ディレクトリ内にREADME.mdが見つかりません。"
}
return string(text)
}())
}))
if err != nil {
log.Fatal(err)
}
// HACK: 本来pathを使うべきだが絶対パスの処理の関係でnameになっている
return categories[idx[0]].name
}