From 3b7e7a7f56f3e89b7a0bc9b7674901b1b672d213 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 11 Apr 2021 23:32:20 +1000 Subject: [PATCH] add random tip to command log --- main.go | 3 +- pkg/config/user_config.go | 5 ++ pkg/constants/links.go | 33 ++++++++ pkg/gui/command_log_panel.go | 148 +++++++++++++++++++++++++++++++++++ pkg/gui/information_panel.go | 5 +- pkg/gui/keybindings.go | 11 ++- pkg/gui/layout.go | 13 +-- pkg/gui/status_panel.go | 11 +-- pkg/i18n/dutch.go | 2 +- pkg/i18n/english.go | 4 +- pkg/i18n/polish.go | 2 +- pkg/updates/updates.go | 9 +-- 12 files changed, 213 insertions(+), 33 deletions(-) create mode 100644 pkg/constants/links.go diff --git a/main.go b/main.go index 131f1e6e3..67d6e8287 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "github.com/integrii/flaggy" "github.com/jesseduffield/lazygit/pkg/app" "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/env" yaml "github.com/jesseduffield/yaml" ) @@ -134,6 +135,6 @@ func main() { stackTrace := newErr.ErrorStack() app.Log.Error(stackTrace) - log.Fatal(fmt.Sprintf("%s\n\n%s", app.Tr.ErrorOccurred, stackTrace)) + log.Fatal(fmt.Sprintf("%s: %s\n\n%s", app.Tr.ErrorOccurred, constants.Links.Issues, stackTrace)) } } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 7fd26a708..1d1f42b68 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -103,6 +103,7 @@ type KeybindingConfig struct { Submodules KeybindingSubmodulesConfig `yaml:"submodules"` } +// damn looks like we have some inconsistencies here with -alt and -alt1 type KeybindingUniversalConfig struct { Quit string `yaml:"quit"` QuitAlt1 string `yaml:"quit-alt1"` @@ -121,6 +122,8 @@ type KeybindingUniversalConfig struct { NextBlock string `yaml:"nextBlock"` PrevBlockAlt string `yaml:"prevBlock-alt"` NextBlockAlt string `yaml:"nextBlock-alt"` + NextBlockAlt2 string `yaml:"nextBlock-alt2"` + PrevBlockAlt2 string `yaml:"prevBlock-alt2"` NextMatch string `yaml:"nextMatch"` PrevMatch string `yaml:"prevMatch"` StartSearch string `yaml:"startSearch"` @@ -352,6 +355,8 @@ func GetDefaultConfig() *UserConfig { NextBlock: "", PrevBlockAlt: "h", NextBlockAlt: "l", + PrevBlockAlt2: "", + NextBlockAlt2: "", NextMatch: "n", PrevMatch: "N", StartSearch: "/", diff --git a/pkg/constants/links.go b/pkg/constants/links.go new file mode 100644 index 000000000..fddfe06e2 --- /dev/null +++ b/pkg/constants/links.go @@ -0,0 +1,33 @@ +package constants + +type Docs struct { + CustomPagers string + CustomCommands string + CustomKeybindings string + Keybindings string + Undoing string + Config string + Tutorial string +} + +var Links = struct { + Docs Docs + Issues string + Donate string + Discussions string + RepoUrl string +}{ + RepoUrl: "https://github.com/jesseduffield/lazygit", + Issues: "https://github.com/jesseduffield/lazygit/issues", + Donate: "https://github.com/sponsors/jesseduffield", + Discussions: "https://github.com/jesseduffield/lazygit/discussions", + Docs: Docs{ + CustomPagers: "https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md", + CustomKeybindings: "https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md", + CustomCommands: "https://github.com/jesseduffield/lazygit/wiki/Custom-Commands-Compendium", + Keybindings: "https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings", + Undoing: "https://github.com/jesseduffield/lazygit/blob/master/docs/Undoing.md", + Config: "https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md", + Tutorial: "https://youtu.be/VDXvbHZYeKY", + }, +} 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{}{ "": gocui.KeyCtrlUnderscore, "": gocui.KeyBackspace, "": gocui.KeyTab, + "": gocui.KeyBacktab, "": gocui.KeyEnter, "": gocui.KeyAltEnter, "": 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") diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 47a0d1648..60268e24b 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -207,7 +207,7 @@ func dutchTranslationSet() TranslationSet { ConfirmMerge: "Weet je zeker dat je {{.selectedBranch}} in {{.checkedOutBranch}} wil mergen?", FwdNoUpstream: "Kan niet de branch vooruitspoelen zonder upstream", FwdCommitsToPush: "Je kan niet vooruitspoelen als de branch geen nieuwe commits heeft", - ErrorOccurred: "Er is iets fout gegaan! Zou je hier een issue aan willen maken: https://github.com/jesseduffield/lazygit/issues", + ErrorOccurred: "Er is iets fout gegaan! Zou je hier een issue aan willen maken", NoRoom: "Niet genoeg ruimte", YouAreHere: "JE BENT HIER", LcRewordNotSupported: "herformatteren van commits in interactief rebasen is nog niet ondersteund", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index b49459096..8036cd720 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -449,6 +449,7 @@ type TranslationSet struct { ToggleShowCommandLog string FocusCommandLog string CommandLogHeader string + RandomTip string Spans Spans } @@ -960,7 +961,7 @@ func englishTranslationSet() TranslationSet { ConfirmMerge: "Are you sure you want to merge {{.selectedBranch}} into {{.checkedOutBranch}}?", FwdNoUpstream: "Cannot fast-forward a branch with no upstream", FwdCommitsToPush: "Cannot fast-forward a branch with commits to push", - ErrorOccurred: "An error occurred! Please create an issue at https://github.com/jesseduffield/lazygit/issues", + ErrorOccurred: "An error occurred! Please create an issue at", NoRoom: "Not enough room", YouAreHere: "YOU ARE HERE", LcRewordNotSupported: "rewording commits while interactively rebasing is not currently supported", @@ -1189,6 +1190,7 @@ func englishTranslationSet() TranslationSet { ToggleShowCommandLog: "Toggle show/hide command log", FocusCommandLog: "Focus command log", CommandLogHeader: "You can hide/focus this panel by pressing '%s' or hide it permanently in your config with `gui.showCommandLog: false`\n", + RandomTip: "Random Tip", Spans: Spans{ // TODO: combine this with the original keybinding descriptions (those are all in lowercase atm) CheckoutCommit: "Checkout commit", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index f0805bb6c..a7ea87298 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -145,7 +145,7 @@ func polishTranslationSet() TranslationSet { ConfirmMerge: "Are you sure you want to merge {{.selectedBranch}} into {{.checkedOutBranch}}?", FwdNoUpstream: "Cannot fast-forward a branch with no upstream", FwdCommitsToPush: "Cannot fast-forward a branch with commits to push", - ErrorOccurred: "An error occurred! Please create an issue at https://github.com/jesseduffield/lazygit/issues", + ErrorOccurred: "An error occurred! Please create an issue at", MainTitle: "Main", NormalTitle: "Normal", LcSoftReset: "soft reset", diff --git a/pkg/updates/updates.go b/pkg/updates/updates.go index 6b570d837..cb5a64788 100644 --- a/pkg/updates/updates.go +++ b/pkg/updates/updates.go @@ -17,6 +17,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/sirupsen/logrus" @@ -36,10 +37,6 @@ type Updaterer interface { Update() } -const ( - PROJECT_URL = "https://github.com/jesseduffield/lazygit" -) - // NewUpdater creates a new updater func NewUpdater(log *logrus.Entry, config config.AppConfigurer, osCommand *oscommands.OSCommand, tr *i18n.TranslationSet) (*Updater, error) { contextLogger := log.WithField("context", "updates") @@ -53,7 +50,7 @@ func NewUpdater(log *logrus.Entry, config config.AppConfigurer, osCommand *oscom } func (u *Updater) getLatestVersionNumber() (string, error) { - req, err := http.NewRequest("GET", PROJECT_URL+"/releases/latest", nil) + req, err := http.NewRequest("GET", constants.Links.RepoUrl+"/releases/latest", nil) if err != nil { return "", err } @@ -235,7 +232,7 @@ func (u *Updater) zipExtension() string { func (u *Updater) getBinaryUrl(newVersion string) (string, error) { url := fmt.Sprintf( "%s/releases/download/%s/lazygit_%s_%s_%s.%s", - PROJECT_URL, + constants.Links.RepoUrl, newVersion, newVersion[1:], u.mappedOs(runtime.GOOS),