Add keymenu

This commit is contained in:
Zachary Yedidia
2019-01-16 18:37:45 -05:00
parent 254b892a3b
commit 212b0f8c71
4 changed files with 41 additions and 17 deletions

View File

@@ -1012,6 +1012,8 @@ func (h *BufHandler) ToggleHelp() bool {
// ToggleKeyMenu toggles the keymenu option and resizes all tabs // ToggleKeyMenu toggles the keymenu option and resizes all tabs
func (h *BufHandler) ToggleKeyMenu() bool { func (h *BufHandler) ToggleKeyMenu() bool {
config.GlobalSettings["keymenu"] = !config.GetGlobalOption("keymenu").(bool)
Tabs.Resize()
return false return false
} }

View File

@@ -395,7 +395,6 @@ func SetGlobalOption(option, value string) error {
} }
} }
// TODO: info and keymenu option change
if option == "infobar" || option == "keymenu" { if option == "infobar" || option == "keymenu" {
Tabs.Resize() Tabs.Resize()
} }

View File

@@ -164,10 +164,14 @@ func DefaultCommonSettings() map[string]interface{} {
} }
func GetInfoBarOffset() int { func GetInfoBarOffset() int {
offset := 0
if GetGlobalOption("infobar").(bool) { 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 // DefaultGlobalSettings returns the default global settings for micro

View File

@@ -1,6 +1,7 @@
package display package display
import ( import (
"log"
"unicode/utf8" "unicode/utf8"
runewidth "github.com/mattn/go-runewidth" runewidth "github.com/mattn/go-runewidth"
@@ -18,9 +19,6 @@ type InfoWindow struct {
defStyle tcell.Style defStyle tcell.Style
errStyle tcell.Style errStyle tcell.Style
width int
y int
} }
func NewInfoWindow(b *info.InfoBuf) *InfoWindow { func NewInfoWindow(b *info.InfoBuf) *InfoWindow {
@@ -42,15 +40,15 @@ func NewInfoWindow(b *info.InfoBuf) *InfoWindow {
iw.errStyle = config.Colorscheme["error-message"] iw.errStyle = config.Colorscheme["error-message"]
} }
iw.width, iw.y = screen.Screen.Size() iw.Width, iw.Y = screen.Screen.Size()
iw.y-- iw.Y--
return iw return iw
} }
func (i *InfoWindow) Resize(w, h int) { func (i *InfoWindow) Resize(w, h int) {
i.width = w i.Width = w
i.y = h i.Y = h
} }
func (i *InfoWindow) SetBuffer(b *buffer.Buffer) { func (i *InfoWindow) SetBuffer(b *buffer.Buffer) {
@@ -70,8 +68,8 @@ func (i *InfoWindow) GetMouseLoc(vloc buffer.Loc) buffer.Loc {
} }
func (i *InfoWindow) Clear() { func (i *InfoWindow) Clear() {
for x := 0; x < i.width; x++ { for x := 0; x < i.Width; x++ {
screen.Screen.SetContent(x, i.y, ' ', nil, config.DefStyle) 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++ vlocX++
} }
nColsBeforeStart-- nColsBeforeStart--
@@ -111,7 +109,7 @@ func (i *InfoWindow) displayBuffer() {
totalwidth := blocX - nColsBeforeStart totalwidth := blocX - nColsBeforeStart
for len(line) > 0 { for len(line) > 0 {
if activeC.X == blocX { if activeC.X == blocX {
screen.Screen.ShowCursor(vlocX, i.y) screen.Screen.ShowCursor(vlocX, i.Y)
} }
r, size := utf8.DecodeRune(line) r, size := utf8.DecodeRune(line)
@@ -140,17 +138,38 @@ func (i *InfoWindow) displayBuffer() {
} }
} }
totalwidth += width totalwidth += width
if vlocX >= i.width { if vlocX >= i.Width {
break break
} }
} }
if activeC.X == blocX { 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() { func (i *InfoWindow) Display() {
x := 0 x := 0
if config.GetGlobalOption("keymenu").(bool) {
i.displayKeyMenu()
}
if i.HasPrompt || config.GlobalSettings["infobar"].(bool) { if i.HasPrompt || config.GlobalSettings["infobar"].(bool) {
if !i.HasPrompt && !i.HasMessage && !i.HasError { if !i.HasPrompt && !i.HasMessage && !i.HasError {
return return
@@ -164,7 +183,7 @@ func (i *InfoWindow) Display() {
display := i.Msg display := i.Msg
for _, c := range display { 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) x += runewidth.RuneWidth(c)
} }