1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-04 23:37:41 +02:00

update help panel

- delete scrolling ability
- lines are now selectable
- implemented handler execution when space is pressed
- add example descriptions for status panel keybindings
This commit is contained in:
Dawid Dziurla 2018-08-29 13:43:59 +02:00
parent 77623db1d0
commit 28a9594ef7
No known key found for this signature in database
GPG Key ID: 7B6D8368172E9B0B
5 changed files with 56 additions and 43 deletions

View File

@ -185,7 +185,7 @@ func (gui *Gui) renderfilesOptions(g *gocui.Gui, file *commands.File) error {
"e": gui.Tr.SLocalize("edit"),
"a": gui.Tr.SLocalize("toggleStagedAll"),
"PgUp/PgDn": gui.Tr.SLocalize("scroll"),
"?": gui.Tr.SLocalize("help"),
"?": gui.Tr.SLocalize("help"), //TODO make it visible for all panels, not only files
}
if gui.State.HasMergeConflicts {
optionsMap["a"] = gui.Tr.SLocalize("abortMerge")

View File

@ -2,62 +2,74 @@ package gui
import (
"fmt"
"github.com/jesseduffield/gocui"
"strings"
"github.com/jesseduffield/gocui"
)
var keys []Binding
func (gui *Gui) handleHelpPress(g *gocui.Gui, v *gocui.View) error {
lineNumber := gui.getItemPosition(v)
err := gui.handleHelpClose(g, v)
if err != nil {
return err
}
return keys[lineNumber].Handler(g, v)
}
func (gui *Gui) handleHelpSelect(g *gocui.Gui, v *gocui.View) error {
// doing nothing for now
// but it is needed for switch in newLineFocused
return nil
}
func (gui *Gui) renderHelpOptions(g *gocui.Gui) error {
optionsMap := map[string]string{
"esc/q": gui.Tr.SLocalize("close"),
"PgUp/PgDn": gui.Tr.SLocalize("scroll"),
"esc/q": gui.Tr.SLocalize("close"),
"↑ ↓": gui.Tr.SLocalize("navigate"),
"space": gui.Tr.SLocalize("execute"),
}
return gui.renderOptionsMap(g, optionsMap)
}
func (gui *Gui) scrollUpHelp(g *gocui.Gui, v *gocui.View) error {
mainView, _ := g.View("help")
ox, oy := mainView.Origin()
if oy >= 1 {
return mainView.SetOrigin(ox, oy-gui.Config.GetUserConfig().GetInt("gui.scrollHeight"))
}
return nil
}
func (gui *Gui) scrollDownHelp(g *gocui.Gui, v *gocui.View) error {
mainView, _ := g.View("help")
ox, oy := mainView.Origin()
if oy < len(mainView.BufferLines()) {
return mainView.SetOrigin(ox, oy+gui.Config.GetUserConfig().GetInt("gui.scrollHeight"))
}
return nil
}
func (gui *Gui) handleHelpClose(g *gocui.Gui, v *gocui.View) error {
g.SetViewOnBottom(v.Name())
return gui.switchFocus(g, v, gui.getFilesView(g))
// better to delete because for example after closing update confirmation panel,
// the focus isn't set back to any of panels and one is unable to even quit
//_, err := g.SetViewOnBottom(v.Name())
err := g.DeleteView(v.Name())
if err != nil {
return err
}
return gui.returnFocus(g, v)
}
func (gui *Gui) handleHelp(g *gocui.Gui, v *gocui.View) error {
// clear keys slice, so we don't have ghost elements
keys = keys[:0]
content := ""
curr := ""
bindings := gui.getKeybindings()
maxX, maxY := g.Size()
helpView, _ := g.SetView("help", 0, 0, maxX-1, maxY-2, 0)
x := maxX * 3 / 4
y := 5
helpView, _ := g.SetView("help", maxX-x, y, x, maxY-y, 0)
helpView.Title = strings.Title(gui.Tr.SLocalize("help"))
gui.renderHelpOptions(g)
for _, binding := range bindings {
if binding.Description != "" {
if curr != binding.ViewName {
curr = binding.ViewName
content += fmt.Sprintf("\n%s:\n", strings.Title(curr))
}
content += fmt.Sprintf(" %s - %s\n", binding.KeyReadable, binding.Description)
if binding.ViewName == v.Name() && binding.Description != "" && binding.KeyReadable != "" {
content += fmt.Sprintf(" %s - %s\n", binding.KeyReadable, binding.Description)
keys = append(keys, binding)
}
}
helpView.Write([]byte(content))
// for testing
/*content += "first\n"
content += "second\n"
content += "third\n"
*/
gui.renderString(g, "help", content)
g.Update(func(g *gocui.Gui) error {
g.SetViewOnTop("help")

View File

@ -27,9 +27,9 @@ func (gui *Gui) getKeybindings() []Binding {
{ViewName: "", Key: 'p', Modifier: gocui.ModNone, Handler: gui.pullFiles},
{ViewName: "", Key: 'R', Modifier: gocui.ModNone, Handler: gui.handleRefresh},
{ViewName: "", Key: '?', Modifier: gocui.ModNone, Handler: gui.handleHelp},
{ViewName: "status", Key: 'e', Modifier: gocui.ModNone, Handler: gui.handleEditConfig},
{ViewName: "status", Key: 'o', Modifier: gocui.ModNone, Handler: gui.handleOpenConfig},
{ViewName: "status", Key: 'u', Modifier: gocui.ModNone, Handler: gui.handleCheckForUpdate},
{ViewName: "status", Key: 'e', Modifier: gocui.ModNone, Handler: gui.handleEditConfig, KeyReadable: "e", Description: "edit config"},
{ViewName: "status", Key: 'o', Modifier: gocui.ModNone, Handler: gui.handleOpenConfig, KeyReadable: "o", Description: "open config"},
{ViewName: "status", Key: 'u', Modifier: gocui.ModNone, Handler: gui.handleCheckForUpdate, KeyReadable: "u", Description: "check for update"},
{ViewName: "files", Key: 'c', Modifier: gocui.ModNone, Handler: gui.handleCommitPress},
{ViewName: "files", Key: 'C', Modifier: gocui.ModNone, Handler: gui.handleCommitEditorPress},
{ViewName: "files", Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleFilePress},
@ -76,13 +76,12 @@ func (gui *Gui) getKeybindings() []Binding {
{ViewName: "commitMessage", Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.handleNewlineCommitMessage},
{ViewName: "help", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.handleHelpClose},
{ViewName: "help", Key: 'q', Modifier: gocui.ModNone, Handler: gui.handleHelpClose},
{ViewName: "help", Key: gocui.KeyPgup, Modifier: gocui.ModNone, Handler: gui.scrollUpHelp},
{ViewName: "help", Key: gocui.KeyPgdn, Modifier: gocui.ModNone, Handler: gui.scrollDownHelp},
{ViewName: "help", Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleHelpPress},
}
// Would make these keybindings global but that interferes with editing
// input in the confirmation panel
for _, viewName := range []string{"status", "files", "branches", "commits", "stash"} {
for _, viewName := range []string{"status", "files", "branches", "commits", "stash", "help"} {
bindings = append(bindings, []Binding{
{ViewName: viewName, Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.nextView},
{ViewName: viewName, Key: gocui.KeyArrowLeft, Modifier: gocui.ModNone, Handler: gui.previousView},

View File

@ -82,6 +82,8 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
mainView.SetOrigin(0, 0)
switch v.Name() {
case "help":
return gui.handleHelpSelect(g, v)
case "status":
return gui.handleStatusSelect(g, v)
case "files":
@ -146,10 +148,7 @@ func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View) error {
}
g.Cursor = newView.Editable
if newView.Name() != "help" {
return gui.newLineFocused(g, newView)
}
return nil
return gui.newLineFocused(g, newView)
}
func (gui *Gui) getItemPosition(v *gocui.View) int {

View File

@ -51,6 +51,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "help",
Other: "help",
}, &i18n.Message{
ID: "execute",
Other: "execute",
}, &i18n.Message{
ID: "stashFiles",
Other: "stash files",