-
Notifications
You must be signed in to change notification settings - Fork 2
/
verses.go
48 lines (44 loc) · 1.17 KB
/
verses.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
package terminal
import (
"fmt"
"regexp"
"strings"
"github.com/AlecAivazis/survey/v2"
"github.com/eliranwong/gobible/internal/bible"
"github.com/eliranwong/gobible/internal/share"
)
func promptVerses(message, selected string, options, descriptions []string, run func(string)) {
var qs = []*survey.Question{
{
Name: "Verse",
Prompt: &survey.Select{
Message: message,
Options: options,
Description: func(value string, index int) string { return descriptions[index] },
Help: "Select to open",
Default: selected,
},
},
}
answers := struct {
Verse string
}{}
// perform the questions
err := survey.Ask(qs, &answers, pageSize)
if err != nil {
fmt.Println(err.Error())
return
}
run(answers.Verse)
}
func crossreference() {
run := func(s string) {
l := strings.Split(s, " [")
reference, module := l[0], l[1]
reference = regexp.MustCompile(`-.*?$`).ReplaceAllString(reference, "")
RunCommand(reference, module[:len(module)-1])
}
message := fmt.Sprintf("Cross-reference: %v", share.Reference)
options, descriptions := bible.GetXrefs2(share.Reference)
promptVerses(message, options[0], options, descriptions, run)
}