1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03: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
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"), "e": gui.Tr.SLocalize("edit"),
"a": gui.Tr.SLocalize("toggleStagedAll"), "a": gui.Tr.SLocalize("toggleStagedAll"),
"PgUp/PgDn": gui.Tr.SLocalize("scroll"), "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 { if gui.State.HasMergeConflicts {
optionsMap["a"] = gui.Tr.SLocalize("abortMerge") optionsMap["a"] = gui.Tr.SLocalize("abortMerge")

View File

@ -2,62 +2,74 @@ package gui
import ( import (
"fmt" "fmt"
"github.com/jesseduffield/gocui"
"strings" "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 { func (gui *Gui) renderHelpOptions(g *gocui.Gui) error {
optionsMap := map[string]string{ optionsMap := map[string]string{
"esc/q": gui.Tr.SLocalize("close"), "esc/q": gui.Tr.SLocalize("close"),
"PgUp/PgDn": gui.Tr.SLocalize("scroll"), "↑ ↓": gui.Tr.SLocalize("navigate"),
"space": gui.Tr.SLocalize("execute"),
} }
return gui.renderOptionsMap(g, optionsMap) 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 { func (gui *Gui) handleHelpClose(g *gocui.Gui, v *gocui.View) error {
g.SetViewOnBottom(v.Name()) // better to delete because for example after closing update confirmation panel,
return gui.switchFocus(g, v, gui.getFilesView(g)) // 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 { 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 := "" content := ""
curr := ""
bindings := gui.getKeybindings() bindings := gui.getKeybindings()
maxX, maxY := g.Size() 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")) helpView.Title = strings.Title(gui.Tr.SLocalize("help"))
gui.renderHelpOptions(g) gui.renderHelpOptions(g)
for _, binding := range bindings { for _, binding := range bindings {
if binding.Description != "" { if binding.ViewName == v.Name() && binding.Description != "" && binding.KeyReadable != "" {
if curr != binding.ViewName { content += fmt.Sprintf(" %s - %s\n", binding.KeyReadable, binding.Description)
curr = binding.ViewName keys = append(keys, binding)
content += fmt.Sprintf("\n%s:\n", strings.Title(curr))
}
content += fmt.Sprintf(" %s - %s\n", binding.KeyReadable, binding.Description)
} }
} }
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.Update(func(g *gocui.Gui) error {
g.SetViewOnTop("help") 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: 'p', Modifier: gocui.ModNone, Handler: gui.pullFiles},
{ViewName: "", Key: 'R', Modifier: gocui.ModNone, Handler: gui.handleRefresh}, {ViewName: "", Key: 'R', Modifier: gocui.ModNone, Handler: gui.handleRefresh},
{ViewName: "", Key: '?', Modifier: gocui.ModNone, Handler: gui.handleHelp}, {ViewName: "", Key: '?', Modifier: gocui.ModNone, Handler: gui.handleHelp},
{ViewName: "status", Key: 'e', Modifier: gocui.ModNone, Handler: gui.handleEditConfig}, {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}, {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}, {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.handleCommitPress},
{ViewName: "files", Key: 'C', Modifier: gocui.ModNone, Handler: gui.handleCommitEditorPress}, {ViewName: "files", Key: 'C', Modifier: gocui.ModNone, Handler: gui.handleCommitEditorPress},
{ViewName: "files", Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleFilePress}, {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: "commitMessage", Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.handleNewlineCommitMessage},
{ViewName: "help", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.handleHelpClose}, {ViewName: "help", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.handleHelpClose},
{ViewName: "help", Key: 'q', 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.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleHelpPress},
{ViewName: "help", Key: gocui.KeyPgdn, Modifier: gocui.ModNone, Handler: gui.scrollDownHelp},
} }
// Would make these keybindings global but that interferes with editing // Would make these keybindings global but that interferes with editing
// input in the confirmation panel // 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{ bindings = append(bindings, []Binding{
{ViewName: viewName, Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.nextView}, {ViewName: viewName, Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.nextView},
{ViewName: viewName, Key: gocui.KeyArrowLeft, Modifier: gocui.ModNone, Handler: gui.previousView}, {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) mainView.SetOrigin(0, 0)
switch v.Name() { switch v.Name() {
case "help":
return gui.handleHelpSelect(g, v)
case "status": case "status":
return gui.handleStatusSelect(g, v) return gui.handleStatusSelect(g, v)
case "files": case "files":
@ -146,10 +148,7 @@ func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View) error {
} }
g.Cursor = newView.Editable g.Cursor = newView.Editable
if newView.Name() != "help" { return gui.newLineFocused(g, newView)
return gui.newLineFocused(g, newView)
}
return nil
} }
func (gui *Gui) getItemPosition(v *gocui.View) int { func (gui *Gui) getItemPosition(v *gocui.View) int {

View File

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