diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-11 23:32:20 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-12 21:48:08 +1000 |
commit | 3b7e7a7f56f3e89b7a0bc9b7674901b1b672d213 (patch) | |
tree | c5e3ed71386afe503997a17e0abb28058caf083b /pkg/gui | |
parent | 06a8eb115c100816e3ceccff875010a84416beee (diff) |
add random tip to command log
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/command_log_panel.go | 148 | ||||
-rw-r--r-- | pkg/gui/information_panel.go | 5 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 11 | ||||
-rw-r--r-- | pkg/gui/layout.go | 13 | ||||
-rw-r--r-- | pkg/gui/status_panel.go | 11 |
5 files changed, 165 insertions, 23 deletions
diff --git a/pkg/gui/command_log_panel.go b/pkg/gui/command_log_panel.go index bd037aa7d..2f9abff3b 100644 --- a/pkg/gui/command_log_panel.go +++ b/pkg/gui/command_log_panel.go @@ -2,10 +2,13 @@ package gui import ( "fmt" + "math/rand" "strings" + "time" "github.com/fatih/color" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -35,3 +38,148 @@ func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) { fmt.Fprint(gui.Views.Extras, "\n"+utils.ColoredString(indentedCmdStr, clrAttr)) } } + +func (gui *Gui) printCommandLogHeader() { + introStr := fmt.Sprintf( + gui.Tr.CommandLogHeader, + gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.ExtrasMenu), + ) + fmt.Fprintln(gui.Views.Extras, utils.ColoredString(introStr, color.FgCyan)) + + fmt.Fprint( + gui.Views.Extras, + fmt.Sprintf( + "%s: %s", + utils.ColoredString(gui.Tr.RandomTip, color.FgYellow), + utils.ColoredString(gui.getRandomTip(), color.FgGreen), + ), + ) +} + +func (gui *Gui) getRandomTip() string { + config := gui.Config.GetUserConfig().Keybinding + + formattedKey := func(key string) string { + return gui.getKeyDisplay(key) + } + + tips := []string{ + // keybindings and lazygit-specific advice + fmt.Sprintf( + "To force push, press '%s' and then if the push is rejected you will be asked if you want to force push", + formattedKey(config.Universal.PushFiles), + ), + fmt.Sprintf( + "To filter commits by path, press '%s'", + formattedKey(config.Universal.FilteringMenu), + ), + fmt.Sprintf( + "To start an interactive rebase, press '%s' on a commit. You can always abort the rebase by pressing '%s' and selecting 'abort'", + formattedKey(config.Universal.Edit), + formattedKey(config.Universal.CreateRebaseOptionsMenu), + ), + fmt.Sprintf( + "In flat file view, merge conflicts are sorted to the top. To switch to flat file view press '%s'", + formattedKey(config.Files.ToggleTreeView), + ), + "If you want to learn Go and can think of ways to improve lazygit, join the team! Click 'Ask Question' and express your interest", + fmt.Sprintf( + "If you press '%s'/'%s' you can undo/redo your changes. Be wary though, this only applies to branches/commits, so only do this if your worktree is clear.\nDocs: %s", + formattedKey(config.Universal.Undo), + formattedKey(config.Universal.Redo), + constants.Links.Docs.Undoing, + ), + fmt.Sprintf( + "to hard reset onto your current upstream branch, press '%s' in the files panel", + formattedKey(config.Files.ViewResetOptions), + ), + fmt.Sprintf( + "To push a tag, navigate to the tag in the tags tab and press '%s'", + formattedKey(config.Branches.PushTag), + ), + fmt.Sprintf( + "You can view the individual files of a stash entry by pressing '%s'", + formattedKey(config.Universal.GoInto), + ), + fmt.Sprintf( + "You can diff two commits by pressing '%s' one one commit and then navigating to the other. You can then press '%s' to view the files of the diff", + formattedKey(config.Universal.DiffingMenu), + formattedKey(config.Universal.GoInto), + ), + fmt.Sprintf( + "press '%s' on a commit to drop it (delete it)", + formattedKey(config.Universal.Remove), + ), + fmt.Sprintf( + "If you need to pull out the big guns to resolve merge conflicts, you can press '%s' in the files panel to open 'git mergetool'", + formattedKey(config.Files.OpenMergeTool), + ), + fmt.Sprintf( + "To revert a commit, press '%s' on that commit", + formattedKey(config.Commits.RevertCommit), + ), + fmt.Sprintf( + "To escape a mode, for example cherry-picking, patch-building, diffing, or filtering mode, you can just spam the '%s' button. Unless of course you have `quitOnTopLevelReturn` enabled in your config", + formattedKey(config.Universal.Return), + ), + fmt.Sprintf( + "To search for a string in your panel, press '%s'", + formattedKey(config.Universal.StartSearch), + ), + fmt.Sprintf( + "You can page through the items of a panel using '%s' and '%s'", + formattedKey(config.Universal.PrevPage), + formattedKey(config.Universal.NextPage), + ), + fmt.Sprintf( + "You can jump to the top/bottom of a panel using '%s' and '%s'", + formattedKey(config.Universal.GotoTop), + formattedKey(config.Universal.GotoBottom), + ), + fmt.Sprintf( + "To collapse/expand a directory, press '%s'", + formattedKey(config.Universal.GoInto), + ), + fmt.Sprintf( + "You can append your staged changes to an older commit by pressing '%s' on that commit", + formattedKey(config.Commits.AmendToCommit), + ), + fmt.Sprintf( + "You can amend the last commit with your new file changes by pressing '%s' in the files panel", + formattedKey(config.Files.AmendLastCommit), + ), + fmt.Sprintf( + "You can now navigate the side panels with '%s' and '%s'", + formattedKey(config.Universal.NextBlockAlt2), + formattedKey(config.Universal.PrevBlockAlt2), + ), + + "You can use lazygit with a bare repo by passing the --git-dir and --work-tree arguments as you would for the git CLI", + + // general advice + "`git commit` is really just the programmer equivalent of saving your game. Always do it before embarking on an ambitious change!", + "Try to separate commits that refactor code from commits that add new functionality: if they're squashed into the one commit, it can be hard to spot what's new.", + "If you ever want to experiment, it's easy to create a new branch off your current one and go nuts, then delete it afterwards", + "Always read through the diff of your changes before assigning somebody to review your code. Better for you to catch any silly mistakes than your colleagues!", + "If something goes wrong, you can always checkout a commit from your reflog to return to an earlier state", + "The stash is a good place to save snippets of code that you always find yourself adding when debugging.", + + // links + fmt.Sprintf( + "If you want a git diff with syntax colouring, check out lazygit's integration with delta:\n%s", + constants.Links.Docs.CustomPagers, + ), + fmt.Sprintf( + "You can build your own custom menus and commands to run from within lazygit. For examples see:\n%s", + constants.Links.Docs.CustomCommands, + ), + fmt.Sprintf( + "If you ever find a bug, do not hesistate to raise an issue on the repo:\n%s", + constants.Links.Issues, + ), + } + + rand.Seed(time.Now().UnixNano()) + randomIndex := rand.Intn(len(tips)) + return tips[randomIndex] +} diff --git a/pkg/gui/information_panel.go b/pkg/gui/information_panel.go index 10292026d..ac46cdaf1 100644 --- a/pkg/gui/information_panel.go +++ b/pkg/gui/information_panel.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/fatih/color" + "github.com/jesseduffield/lazygit/pkg/constants" ) func (gui *Gui) informationStr() string { @@ -43,9 +44,9 @@ func (gui *Gui) handleInfoClick() error { // if we're not in an active mode we show the donate button if cx <= len(gui.Tr.Donate) { - return gui.OSCommand.OpenLink("https://github.com/sponsors/jesseduffield") + return gui.OSCommand.OpenLink(constants.Links.Donate) } else if cx <= len(gui.Tr.Donate)+1+len(gui.Tr.AskQuestion) { - return gui.OSCommand.OpenLink("https://github.com/jesseduffield/lazygit/discussions") + return gui.OSCommand.OpenLink(constants.Links.Discussions) } return nil } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 4e2f8b26e..a9e161b0f 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -8,6 +8,7 @@ import ( "unicode/utf8" "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/constants" ) // Binding - a keybinding mapping a key and modifier to a handler. The keypress @@ -53,7 +54,8 @@ var keyMapReversed = map[gocui.Key]string{ gocui.KeyArrowDown: "▼", gocui.KeyArrowLeft: "◄", gocui.KeyArrowRight: "►", - gocui.KeyTab: "tab", // ctrl+i + gocui.KeyTab: "tab", // ctrl+i + gocui.KeyBacktab: "shift+tab", gocui.KeyEnter: "enter", // ctrl+m gocui.KeyAltEnter: "alt+enter", gocui.KeyEsc: "esc", // ctrl+[, ctrl+3 @@ -133,6 +135,7 @@ var keymap = map[string]interface{}{ "<c-_>": gocui.KeyCtrlUnderscore, "<backspace>": gocui.KeyBackspace, "<tab>": gocui.KeyTab, + "<backtab>": gocui.KeyBacktab, "<enter>": gocui.KeyEnter, "<a-enter>": gocui.KeyAltEnter, "<esc>": gocui.KeyEsc, @@ -188,7 +191,7 @@ func (gui *Gui) getKey(key string) interface{} { if runeCount > 1 { binding := keymap[strings.ToLower(key)] if binding == nil { - log.Fatalf("Unrecognized key %s for keybinding. For permitted values see https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md", strings.ToLower(key)) + log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings) } else { return binding } @@ -1773,8 +1776,8 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { {ViewName: viewName, Key: gui.getKey(config.Universal.NextBlock), Modifier: gocui.ModNone, Handler: gui.nextSideWindow}, {ViewName: viewName, Key: gui.getKey(config.Universal.PrevBlockAlt), Modifier: gocui.ModNone, Handler: gui.previousSideWindow}, {ViewName: viewName, Key: gui.getKey(config.Universal.NextBlockAlt), Modifier: gocui.ModNone, Handler: gui.nextSideWindow}, - {ViewName: viewName, Key: gocui.KeyBacktab, Modifier: gocui.ModNone, Handler: gui.previousSideWindow}, - {ViewName: viewName, Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.nextSideWindow}, + {ViewName: viewName, Key: gui.getKey(config.Universal.PrevBlockAlt2), Modifier: gocui.ModNone, Handler: gui.previousSideWindow}, + {ViewName: viewName, Key: gui.getKey(config.Universal.NextBlockAlt2), Modifier: gocui.ModNone, Handler: gui.nextSideWindow}, }...) } diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 57759dc85..c15ba340e 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -1,12 +1,8 @@ package gui import ( - "fmt" - - "github.com/fatih/color" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/theme" - "github.com/jesseduffield/lazygit/pkg/utils" ) const SEARCH_PREFIX = "search: " @@ -125,6 +121,7 @@ func (gui *Gui) createAllViews() error { gui.Views.Extras.Title = gui.Tr.CommandLog gui.Views.Extras.FgColor = theme.GocuiDefaultTextColor gui.Views.Extras.Autoscroll = true + gui.Views.Extras.Wrap = true gui.printCommandLogHeader() if _, err := gui.g.SetCurrentView(gui.defaultSideContext().GetViewName()); err != nil { @@ -134,14 +131,6 @@ func (gui *Gui) createAllViews() error { return nil } -func (gui *Gui) printCommandLogHeader() { - introStr := fmt.Sprintf( - gui.Tr.CommandLogHeader, - gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.ExtrasMenu), - ) - fmt.Fprintln(gui.Views.Extras, utils.ColoredString(introStr, color.FgCyan)) -} - // layout is called for every screen re-render e.g. when the screen is resized func (gui *Gui) layout(g *gocui.Gui) error { if !gui.ViewsSetup { diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index c3306e0f2..1c28eb456 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -6,6 +6,7 @@ import ( "github.com/fatih/color" "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -106,11 +107,11 @@ func (gui *Gui) handleStatusSelect() error { []string{ lazygitTitle(), "Copyright (c) 2018 Jesse Duffield", - "Keybindings: https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings", - "Config Options: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md", - "Tutorial: https://youtu.be/VDXvbHZYeKY", - "Raise an Issue: https://github.com/jesseduffield/lazygit/issues", - magenta.Sprint("Become a sponsor (github is matching all donations for 12 months): https://github.com/sponsors/jesseduffield"), // caffeine ain't free + fmt.Sprintf("Keybindings: %s", constants.Links.Docs.Keybindings), + fmt.Sprintf("Config Options: %s", constants.Links.Docs.Config), + fmt.Sprintf("Tutorial: %s", constants.Links.Docs.Tutorial), + fmt.Sprintf("Raise an Issue: %s", constants.Links.Issues), + magenta.Sprintf("Become a sponsor (github is matching all donations for 12 months): %s", constants.Links.Donate), // caffeine ain't free gui.Tr.ReleaseNotes, }, "\n\n") |