Add nano-style key menu option
Use the `keymenu` option (default `off`) to enable. ToggleKeyMenu is also bound to `Alt-g` and this info is now displayed in the status line. Closes #829
This commit is contained in:
parent
b3559df543
commit
8b8fffb98d
9 changed files with 81 additions and 7 deletions
|
@ -1551,6 +1551,25 @@ func (v *View) ToggleHelp(usePlugin bool) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// ToggleKeyMenu toggles the keymenu option and resizes all tabs
|
||||
func (v *View) ToggleKeyMenu(usePlugin bool) bool {
|
||||
if v.mainCursor() {
|
||||
if usePlugin && !PreActionCall("ToggleBindings", v) {
|
||||
return false
|
||||
}
|
||||
|
||||
globalSettings["keymenu"] = !globalSettings["keymenu"].(bool)
|
||||
for _, tab := range tabs {
|
||||
tab.Resize()
|
||||
}
|
||||
|
||||
if usePlugin {
|
||||
return PostActionCall("ToggleBindings", v)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ShellMode opens a terminal to run a shell command
|
||||
func (v *View) ShellMode(usePlugin bool) bool {
|
||||
if v.mainCursor() {
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
var bindings map[Key][]func(*View, bool) bool
|
||||
var mouseBindings map[Key][]func(*View, bool, *tcell.EventMouse) bool
|
||||
var helpBinding string
|
||||
var kmenuBinding string
|
||||
|
||||
var mouseBindingActions = map[string]func(*View, bool, *tcell.EventMouse) bool{
|
||||
"MousePress": (*View).MousePress,
|
||||
|
@ -78,6 +79,7 @@ var bindingActions = map[string]func(*View, bool) bool{
|
|||
"StartOfLine": (*View).StartOfLine,
|
||||
"EndOfLine": (*View).EndOfLine,
|
||||
"ToggleHelp": (*View).ToggleHelp,
|
||||
"ToggleKeyMenu": (*View).ToggleKeyMenu,
|
||||
"ToggleRuler": (*View).ToggleRuler,
|
||||
"JumpLine": (*View).JumpLine,
|
||||
"ClearStatus": (*View).ClearStatus,
|
||||
|
@ -397,9 +399,15 @@ func BindKey(k, v string) {
|
|||
if v == "ToggleHelp" {
|
||||
helpBinding = k
|
||||
}
|
||||
if v == "ToggleKeyMenu" {
|
||||
kmenuBinding = k
|
||||
}
|
||||
if helpBinding == k && v != "ToggleHelp" {
|
||||
helpBinding = ""
|
||||
}
|
||||
if kmenuBinding == k && v != "ToggleKeyMenu" {
|
||||
kmenuBinding = ""
|
||||
}
|
||||
|
||||
actionNames := strings.Split(v, ",")
|
||||
if actionNames[0] == "UnbindKey" {
|
||||
|
@ -490,6 +498,7 @@ func DefaultBindings() map[string]string {
|
|||
"CtrlPageUp": "PreviousTab",
|
||||
"CtrlPageDown": "NextTab",
|
||||
"CtrlG": "ToggleHelp",
|
||||
"Alt-g": "ToggleKeyMenu",
|
||||
"CtrlR": "ToggleRuler",
|
||||
"CtrlL": "JumpLine",
|
||||
"Delete": "Delete",
|
||||
|
@ -509,7 +518,6 @@ func DefaultBindings() map[string]string {
|
|||
// "Alt-n": "CursorDown",
|
||||
|
||||
// Integration with file managers
|
||||
"F1": "ToggleHelp",
|
||||
"F2": "Save",
|
||||
"F3": "Find",
|
||||
"F4": "Quit",
|
||||
|
|
20
cmd/micro/keymenu.go
Normal file
20
cmd/micro/keymenu.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
// DisplayKeyMenu displays the nano-style key menu at the bottom of the screen
|
||||
func DisplayKeyMenu() {
|
||||
w, h := screen.Size()
|
||||
|
||||
bot := h - 3
|
||||
|
||||
display := []string{"^Q Quit, ^S Save, ^O Open, ^G Help, ^E Command Bar, ^K Cut Line", "^F Find, ^Z Undo, ^Y Redo, ^A Select All, ^D Duplicate Line, ^T New Tab"}
|
||||
|
||||
for y := 0; y < len(display); y++ {
|
||||
for x := 0; x < w; x++ {
|
||||
if x < len(display[y]) {
|
||||
screen.SetContent(x, bot+y, rune(display[y][x]), nil, defStyle)
|
||||
} else {
|
||||
screen.SetContent(x, bot+y, ' ', nil, defStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -225,6 +225,9 @@ func RedrawAll() {
|
|||
}
|
||||
DisplayTabs()
|
||||
messenger.Display()
|
||||
if globalSettings["keymenu"].(bool) {
|
||||
DisplayKeyMenu()
|
||||
}
|
||||
screen.Show()
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -204,6 +204,7 @@ func DefaultGlobalSettings() map[string]interface{} {
|
|||
"ignorecase": false,
|
||||
"indentchar": " ",
|
||||
"infobar": true,
|
||||
"keymenu": false,
|
||||
"mouse": true,
|
||||
"rmtrailingws": false,
|
||||
"ruler": true,
|
||||
|
@ -312,7 +313,7 @@ func SetOption(option, value string) error {
|
|||
}
|
||||
}
|
||||
|
||||
if option == "infobar" {
|
||||
if option == "infobar" || option == "keymenu" {
|
||||
for _, tab := range tabs {
|
||||
tab.Resize()
|
||||
}
|
||||
|
|
|
@ -39,12 +39,24 @@ func (sline *Statusline) Display() {
|
|||
file += " " + sline.view.Buf.Settings["fileformat"].(string)
|
||||
|
||||
rightText := ""
|
||||
if len(helpBinding) > 0 {
|
||||
rightText = helpBinding + " for help "
|
||||
if sline.view.Type == vtHelp {
|
||||
rightText = helpBinding + " to close help "
|
||||
if len(kmenuBinding) > 0 {
|
||||
if globalSettings["keymenu"].(bool) {
|
||||
rightText += kmenuBinding + ": hide bindings"
|
||||
} else {
|
||||
rightText += kmenuBinding + ": show bindings"
|
||||
}
|
||||
}
|
||||
if len(helpBinding) > 0 {
|
||||
if len(kmenuBinding) > 0 {
|
||||
rightText += ", "
|
||||
}
|
||||
if sline.view.Type == vtHelp {
|
||||
rightText += helpBinding + ": close help"
|
||||
} else {
|
||||
rightText += helpBinding + ": open help"
|
||||
}
|
||||
}
|
||||
rightText += " "
|
||||
|
||||
statusLineStyle := defStyle.Reverse(true)
|
||||
if style, ok := colorscheme["statusline"]; ok {
|
||||
|
|
|
@ -36,6 +36,9 @@ func NewTabFromView(v *View) *Tab {
|
|||
if globalSettings["infobar"].(bool) {
|
||||
t.tree.height--
|
||||
}
|
||||
if globalSettings["keymenu"].(bool) {
|
||||
t.tree.height -= 2
|
||||
}
|
||||
|
||||
t.Resize()
|
||||
|
||||
|
@ -62,6 +65,9 @@ func (t *Tab) Resize() {
|
|||
if globalSettings["infobar"].(bool) {
|
||||
t.tree.height--
|
||||
}
|
||||
if globalSettings["keymenu"].(bool) {
|
||||
t.tree.height -= 2
|
||||
}
|
||||
|
||||
t.tree.ResizeSplits()
|
||||
|
||||
|
|
|
@ -182,6 +182,11 @@ Here are the options that you can set:
|
|||
|
||||
default value: `sudo`
|
||||
|
||||
* `keymenu`: display the nano-style key menu at the bottom of the screen. Note that ToggleKeyMenu is bound to
|
||||
`Alt-g` by default and this is displayed in the statusline. To disable this, simply by `Alt-g` to `UnbindKey`.
|
||||
|
||||
default value: `off`
|
||||
|
||||
---
|
||||
|
||||
Default plugin options:
|
||||
|
|
Loading…
Reference in a new issue