mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Split help into multiple files and add help command
This commit is contained in:
@@ -1087,11 +1087,9 @@ func (v *View) ToggleHelp() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !CurView().Help {
|
||||
helpBuffer := NewBuffer([]byte(helpTxt), "help.md")
|
||||
helpBuffer.Name = "Help"
|
||||
v.HSplit(helpBuffer)
|
||||
CurView().Help = true
|
||||
if !v.Help {
|
||||
// Open the default help
|
||||
v.openHelp("help")
|
||||
} else {
|
||||
v.Quit()
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ var commandActions = map[string]func([]string){
|
||||
"VSplit": VSplit,
|
||||
"HSplit": HSplit,
|
||||
"Tab": NewTab,
|
||||
"Help": Help,
|
||||
}
|
||||
|
||||
// InitCommands initializes the default commands
|
||||
@@ -65,6 +66,22 @@ func DefaultCommands() map[string]string {
|
||||
"vsplit": "VSplit",
|
||||
"hsplit": "HSplit",
|
||||
"tab": "Tab",
|
||||
"help": "Help",
|
||||
}
|
||||
}
|
||||
|
||||
// Help tries to open the given help page in a horizontal split
|
||||
func Help(args []string) {
|
||||
if len(args) < 1 {
|
||||
// Open the default help if the user just typed "> help"
|
||||
CurView().openHelp("help")
|
||||
} else {
|
||||
helpPage := args[0]
|
||||
if _, ok := helpPages[helpPage]; ok {
|
||||
CurView().openHelp(helpPage)
|
||||
} else {
|
||||
messenger.Error("Sorry, no help for ", helpPage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package main
|
||||
|
||||
var helpTxt string
|
||||
var helpPages map[string]string
|
||||
|
||||
var helpFiles = []string{
|
||||
"help",
|
||||
"keybindings",
|
||||
"plugins",
|
||||
"colors",
|
||||
"options",
|
||||
"commands",
|
||||
}
|
||||
|
||||
// LoadHelp loads the help text from inside the binary
|
||||
func LoadHelp() {
|
||||
data, err := Asset("runtime/help/help.md")
|
||||
if err != nil {
|
||||
TermMessage("Unable to load help text")
|
||||
return
|
||||
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)
|
||||
}
|
||||
helpTxt = string(data)
|
||||
}
|
||||
|
||||
@@ -464,6 +464,14 @@ func (v *View) ClearAllGutterMessages() {
|
||||
}
|
||||
}
|
||||
|
||||
// Opens the given help page in a new horizontal split
|
||||
func (v *View) openHelp(helpPage string) {
|
||||
helpBuffer := NewBuffer([]byte(helpPages[helpPage]), helpPage+".md")
|
||||
helpBuffer.Name = "Help"
|
||||
v.HSplit(helpBuffer)
|
||||
CurView().Help = true
|
||||
}
|
||||
|
||||
func (v *View) drawCell(x, y int, ch rune, combc []rune, style tcell.Style) {
|
||||
if x >= v.x && x < v.x+v.width && y >= v.y && y < v.y+v.height {
|
||||
screen.SetContent(x, y, ch, combc, style)
|
||||
|
||||
Reference in New Issue
Block a user