From 212b0f8c71edd37a8ca7ed76958b195c46186f84 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Wed, 16 Jan 2019 18:37:45 -0500 Subject: [PATCH] Add keymenu --- cmd/micro/action/actions.go | 2 ++ cmd/micro/action/command.go | 1 - cmd/micro/config/settings.go | 8 ++++-- cmd/micro/display/infowindow.go | 47 +++++++++++++++++++++++---------- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/cmd/micro/action/actions.go b/cmd/micro/action/actions.go index 1c68d17e..9be172c4 100644 --- a/cmd/micro/action/actions.go +++ b/cmd/micro/action/actions.go @@ -1012,6 +1012,8 @@ func (h *BufHandler) ToggleHelp() bool { // ToggleKeyMenu toggles the keymenu option and resizes all tabs func (h *BufHandler) ToggleKeyMenu() bool { + config.GlobalSettings["keymenu"] = !config.GetGlobalOption("keymenu").(bool) + Tabs.Resize() return false } diff --git a/cmd/micro/action/command.go b/cmd/micro/action/command.go index 196cdf08..6f85c70c 100644 --- a/cmd/micro/action/command.go +++ b/cmd/micro/action/command.go @@ -395,7 +395,6 @@ func SetGlobalOption(option, value string) error { } } - // TODO: info and keymenu option change if option == "infobar" || option == "keymenu" { Tabs.Resize() } diff --git a/cmd/micro/config/settings.go b/cmd/micro/config/settings.go index c9f7f215..01126d17 100644 --- a/cmd/micro/config/settings.go +++ b/cmd/micro/config/settings.go @@ -164,10 +164,14 @@ func DefaultCommonSettings() map[string]interface{} { } func GetInfoBarOffset() int { + offset := 0 if GetGlobalOption("infobar").(bool) { - return 1 + offset++ } - return 0 + if GetGlobalOption("keymenu").(bool) { + offset += 2 + } + return offset } // DefaultGlobalSettings returns the default global settings for micro diff --git a/cmd/micro/display/infowindow.go b/cmd/micro/display/infowindow.go index fe7b1ea4..8b74f5f1 100644 --- a/cmd/micro/display/infowindow.go +++ b/cmd/micro/display/infowindow.go @@ -1,6 +1,7 @@ package display import ( + "log" "unicode/utf8" runewidth "github.com/mattn/go-runewidth" @@ -18,9 +19,6 @@ type InfoWindow struct { defStyle tcell.Style errStyle tcell.Style - - width int - y int } func NewInfoWindow(b *info.InfoBuf) *InfoWindow { @@ -42,15 +40,15 @@ func NewInfoWindow(b *info.InfoBuf) *InfoWindow { iw.errStyle = config.Colorscheme["error-message"] } - iw.width, iw.y = screen.Screen.Size() - iw.y-- + iw.Width, iw.Y = screen.Screen.Size() + iw.Y-- return iw } func (i *InfoWindow) Resize(w, h int) { - i.width = w - i.y = h + i.Width = w + i.Y = h } func (i *InfoWindow) SetBuffer(b *buffer.Buffer) { @@ -70,8 +68,8 @@ func (i *InfoWindow) GetMouseLoc(vloc buffer.Loc) buffer.Loc { } func (i *InfoWindow) Clear() { - for x := 0; x < i.width; x++ { - screen.Screen.SetContent(x, i.y, ' ', nil, config.DefStyle) + for x := 0; x < i.Width; x++ { + screen.Screen.SetContent(x, i.Y, ' ', nil, config.DefStyle) } } @@ -102,7 +100,7 @@ func (i *InfoWindow) displayBuffer() { } - screen.Screen.SetContent(vlocX, i.y, r, nil, style) + screen.Screen.SetContent(vlocX, i.Y, r, nil, style) vlocX++ } nColsBeforeStart-- @@ -111,7 +109,7 @@ func (i *InfoWindow) displayBuffer() { totalwidth := blocX - nColsBeforeStart for len(line) > 0 { if activeC.X == blocX { - screen.Screen.ShowCursor(vlocX, i.y) + screen.Screen.ShowCursor(vlocX, i.Y) } r, size := utf8.DecodeRune(line) @@ -140,17 +138,38 @@ func (i *InfoWindow) displayBuffer() { } } totalwidth += width - if vlocX >= i.width { + if vlocX >= i.Width { break } } if activeC.X == blocX { - screen.Screen.ShowCursor(vlocX, i.y) + screen.Screen.ShowCursor(vlocX, i.Y) + } +} + +func (i *InfoWindow) displayKeyMenu() { + // TODO: maybe make this based on the actual keybindings + 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"} + + log.Println("hi", len(display), i.Width) + for y := 0; y < len(display); y++ { + for x := 0; x < i.Width; x++ { + log.Println(x, i.Y-len(display)+y) + if x < len(display[y]) { + screen.Screen.SetContent(x, i.Y-len(display)+y, rune(display[y][x]), nil, config.DefStyle) + } else { + screen.Screen.SetContent(x, i.Y-len(display)+y, ' ', nil, config.DefStyle) + } + } } } func (i *InfoWindow) Display() { x := 0 + if config.GetGlobalOption("keymenu").(bool) { + i.displayKeyMenu() + } + if i.HasPrompt || config.GlobalSettings["infobar"].(bool) { if !i.HasPrompt && !i.HasMessage && !i.HasError { return @@ -164,7 +183,7 @@ func (i *InfoWindow) Display() { display := i.Msg for _, c := range display { - screen.Screen.SetContent(x, i.y, c, nil, style) + screen.Screen.SetContent(x, i.Y, c, nil, style) x += runewidth.RuneWidth(c) }