Load help files when needed

This commit is contained in:
boombuler 2016-09-13 08:53:20 +02:00
parent d0fa467a3c
commit a7f159bddc
4 changed files with 27 additions and 32 deletions

View file

@ -81,9 +81,8 @@ func CommandComplete(input string) (string, []string) {
func HelpComplete(input string) (string, []string) { func HelpComplete(input string) (string, []string) {
var suggestions []string var suggestions []string
for _, topic := range helpFiles { for topic, _ := range helpPages {
if strings.HasPrefix(topic, input) { if strings.HasPrefix(topic, input) {
suggestions = append(suggestions, topic) suggestions = append(suggestions, topic)
} }
} }

View file

@ -1,25 +1,21 @@
package main package main
var helpPages map[string]string type HelpPage interface {
HelpFile() ([]byte, error)
var helpFiles = []string{
"help",
"keybindings",
"plugins",
"colors",
"options",
"commands",
"tutorial",
} }
// LoadHelp loads the help text from inside the binary var helpPages map[string]HelpPage = map[string]HelpPage{
func LoadHelp() { "help": assetHelpPage("help"),
helpPages = make(map[string]string) "keybindings": assetHelpPage("keybindings"),
for _, file := range helpFiles { "plugins": assetHelpPage("plugins"),
data, err := Asset("runtime/help/" + file + ".md") "colors": assetHelpPage("colors"),
if err != nil { "options": assetHelpPage("options"),
TermMessage("Unable to load help text", file) "commands": assetHelpPage("commands"),
} "tutorial": assetHelpPage("tutorial"),
helpPages[file] = string(data) }
}
type assetHelpPage string
func (file assetHelpPage) HelpFile() ([]byte, error) {
return Asset("runtime/help/" + string(file) + ".md")
} }

View file

@ -242,9 +242,6 @@ func main() {
// Load the syntax files, including the colorscheme // Load the syntax files, including the colorscheme
LoadSyntaxFiles() LoadSyntaxFiles()
// Load the help files
LoadHelp()
// Start the screen // Start the screen
InitScreen() InitScreen()

View file

@ -529,15 +529,18 @@ func (v *View) ClearAllGutterMessages() {
// Opens the given help page in a new horizontal split // Opens the given help page in a new horizontal split
func (v *View) openHelp(helpPage string) { func (v *View) openHelp(helpPage string) {
if v.Help { if data, err := helpPages[helpPage].HelpFile(); err != nil {
helpBuffer := NewBuffer([]byte(helpPages[helpPage]), helpPage+".md") TermMessage("Unable to load help text", helpPage, "\n", err)
helpBuffer.Name = "Help"
v.OpenBuffer(helpBuffer)
} else { } else {
helpBuffer := NewBuffer([]byte(helpPages[helpPage]), helpPage+".md") helpBuffer := NewBuffer(data, helpPage+".md")
helpBuffer.Name = "Help" helpBuffer.Name = "Help"
v.HSplit(helpBuffer)
CurView().Help = true if v.Help {
v.OpenBuffer(helpBuffer)
} else {
v.HSplit(helpBuffer)
CurView().Help = true
}
} }
} }