diff options
author | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-02 17:08:59 +0200 |
---|---|---|
committer | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-05 11:26:54 +0200 |
commit | 98763e98cb4c0af033b5276423e451f1f8cd11ee (patch) | |
tree | e738b033e4c8e70b7614c893c6472eaf308e7d36 /pkg | |
parent | f777c60ea4f014e93d31914d4e0a9b5ba1165382 (diff) |
initial commit message counter
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/commit_message_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 57 | ||||
-rw-r--r-- | pkg/gui/gui.go | 10 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 1 |
4 files changed, 68 insertions, 6 deletions
diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 36718680f..88a011c76 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -30,14 +30,10 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error { g.SetViewOnBottom("commitMessage") + g.SetViewOnBottom("commitMessageCount") return gui.switchFocus(g, v, gui.getFilesView(g)) } -func (gui *Gui) handleNewlineCommitMessage(g *gocui.Gui, v *gocui.View) error { - v.EditNewLine() - return nil -} - func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { message := gui.Tr.TemplateLocalize( "CloseConfirm", diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index a4c187c9c..43f7e5831 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -12,6 +12,7 @@ import ( "github.com/fatih/color" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" + "strconv" ) func (gui *Gui) stagedFiles() []commands.File { @@ -218,6 +219,60 @@ func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View) error { return gui.renderString(g, "main", content) } +func (gui *Gui) simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) { + switch { + case key == gocui.KeyBackspace || key == gocui.KeyBackspace2: + v.EditDelete(true) + case key == gocui.KeyDelete: + v.EditDelete(false) + case key == gocui.KeyArrowDown: + v.MoveCursor(0, 1, false) + case key == gocui.KeyArrowUp: + v.MoveCursor(0, -1, false) + case key == gocui.KeyArrowLeft: + v.MoveCursor(-1, 0, false) + case key == gocui.KeyArrowRight: + v.MoveCursor(1, 0, false) + case key == gocui.KeyTab: + v.EditNewLine() + case key == gocui.KeySpace: + v.EditWrite(' ') + case key == gocui.KeyInsert: + v.Overwrite = !v.Overwrite + default: + v.EditWrite(ch) + } + + gui.renderCommitCount(v) +} + +func (gui *Gui) getCommitCount(view *gocui.View) int { + return strings.Count(view.Buffer(), "") - 1 +} + +func (gui *Gui) renderCommitCount(view *gocui.View) error { + num := 0 + offset := 5 + count := gui.getCommitCount(view) + _, y0, x1, _ := gui.getConfirmationPanelDimensions(gui.g, view.Buffer()) + + if count > 99 { + num = 3 + } else if count > 9 { + num = 2 + } else { + num = 1 + } + + if _, err := gui.g.SetView("commitMessageCount", x1-num-offset, y0-1, x1-offset+1, y0+1, 0); err != nil { + if err != gocui.ErrUnknownView { + return err + } + } + + return gui.renderString(gui.g, "commitMessageCount", strconv.Itoa(count)) +} + func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts { return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) @@ -225,7 +280,9 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { commitMessageView := gui.getCommitMessageView(g) g.Update(func(g *gocui.Gui) error { g.SetViewOnTop("commitMessage") + g.SetViewOnTop("commitMessageCount") gui.switchFocus(g, filesView, commitMessageView) + gui.renderCommitCount(commitMessageView) return nil }) return nil diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index bb2ed752b..6c35f9dca 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -262,6 +262,16 @@ func (gui *Gui) layout(g *gocui.Gui) error { commitMessageView.Title = gui.Tr.SLocalize("CommitMessage") commitMessageView.FgColor = gocui.ColorWhite commitMessageView.Editable = true + commitMessageView.Editor = gocui.EditorFunc(gui.simpleEditor) + } + if commitMessageCountView, err := g.SetView("commitMessageCount", 0, 0, width/2, height/2, 0); err != nil { + if err != gocui.ErrUnknownView { + return err + } + g.SetViewOnBottom("commitMessageCount") + commitMessageCountView.Frame = false + commitMessageCountView.BgColor = gocui.ColorDefault + commitMessageCountView.FgColor = gocui.ColorWhite } } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index c6decc24f..494381749 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -70,7 +70,6 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { {ViewName: "stash", Key: 'd', Modifier: gocui.ModNone, Handler: gui.handleStashDrop}, {ViewName: "commitMessage", Key: gocui.KeyEnter, Modifier: gocui.ModNone, Handler: gui.handleCommitConfirm}, {ViewName: "commitMessage", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.handleCommitClose}, - {ViewName: "commitMessage", Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.handleNewlineCommitMessage}, } // Would make these keybindings global but that interferes with editing |