Load help files when needed
This commit is contained in:
parent
d0fa467a3c
commit
a7f159bddc
4 changed files with 27 additions and 32 deletions
|
@ -81,9 +81,8 @@ func CommandComplete(input string) (string, []string) {
|
|||
func HelpComplete(input string) (string, []string) {
|
||||
var suggestions []string
|
||||
|
||||
for _, topic := range helpFiles {
|
||||
for topic, _ := range helpPages {
|
||||
if strings.HasPrefix(topic, input) {
|
||||
|
||||
suggestions = append(suggestions, topic)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,21 @@
|
|||
package main
|
||||
|
||||
var helpPages map[string]string
|
||||
|
||||
var helpFiles = []string{
|
||||
"help",
|
||||
"keybindings",
|
||||
"plugins",
|
||||
"colors",
|
||||
"options",
|
||||
"commands",
|
||||
"tutorial",
|
||||
type HelpPage interface {
|
||||
HelpFile() ([]byte, error)
|
||||
}
|
||||
|
||||
// LoadHelp loads the help text from inside the binary
|
||||
func LoadHelp() {
|
||||
helpPages = make(map[string]string)
|
||||
for _, file := range helpFiles {
|
||||
data, err := Asset("runtime/help/" + file + ".md")
|
||||
if err != nil {
|
||||
TermMessage("Unable to load help text", file)
|
||||
}
|
||||
helpPages[file] = string(data)
|
||||
}
|
||||
var helpPages map[string]HelpPage = map[string]HelpPage{
|
||||
"help": assetHelpPage("help"),
|
||||
"keybindings": assetHelpPage("keybindings"),
|
||||
"plugins": assetHelpPage("plugins"),
|
||||
"colors": assetHelpPage("colors"),
|
||||
"options": assetHelpPage("options"),
|
||||
"commands": assetHelpPage("commands"),
|
||||
"tutorial": assetHelpPage("tutorial"),
|
||||
}
|
||||
|
||||
type assetHelpPage string
|
||||
|
||||
func (file assetHelpPage) HelpFile() ([]byte, error) {
|
||||
return Asset("runtime/help/" + string(file) + ".md")
|
||||
}
|
||||
|
|
|
@ -242,9 +242,6 @@ func main() {
|
|||
// Load the syntax files, including the colorscheme
|
||||
LoadSyntaxFiles()
|
||||
|
||||
// Load the help files
|
||||
LoadHelp()
|
||||
|
||||
// Start the screen
|
||||
InitScreen()
|
||||
|
||||
|
|
|
@ -529,15 +529,18 @@ func (v *View) ClearAllGutterMessages() {
|
|||
|
||||
// Opens the given help page in a new horizontal split
|
||||
func (v *View) openHelp(helpPage string) {
|
||||
if v.Help {
|
||||
helpBuffer := NewBuffer([]byte(helpPages[helpPage]), helpPage+".md")
|
||||
helpBuffer.Name = "Help"
|
||||
v.OpenBuffer(helpBuffer)
|
||||
if data, err := helpPages[helpPage].HelpFile(); err != nil {
|
||||
TermMessage("Unable to load help text", helpPage, "\n", err)
|
||||
} else {
|
||||
helpBuffer := NewBuffer([]byte(helpPages[helpPage]), helpPage+".md")
|
||||
helpBuffer := NewBuffer(data, helpPage+".md")
|
||||
helpBuffer.Name = "Help"
|
||||
v.HSplit(helpBuffer)
|
||||
CurView().Help = true
|
||||
|
||||
if v.Help {
|
||||
v.OpenBuffer(helpBuffer)
|
||||
} else {
|
||||
v.HSplit(helpBuffer)
|
||||
CurView().Help = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue