diff options
| author | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2018-12-11 18:20:01 +0300 |
|---|---|---|
| committer | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2018-12-11 18:20:01 +0300 |
| commit | 9d7b6fcc32a07d16826ac92fbde69b8ae3234882 (patch) | |
| tree | 0f9b8d41d5b035b6212650c8d80633005a21cd5a | |
| parent | added show diff on status view and polish readme (diff) | |
| download | gitbatch-9d7b6fcc32a07d16826ac92fbde69b8ae3234882.tar.gz | |
added initial commit implementation.
| -rw-r--r-- | pkg/gui/gui.go | 4 | ||||
| -rw-r--r-- | pkg/gui/keybindings.go | 26 | ||||
| -rw-r--r-- | pkg/gui/statusview.go | 83 |
3 files changed, 109 insertions, 4 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 290cb88..1eb7969 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -129,6 +129,10 @@ func (gui *Gui) Run() error { gui.g = g g.Highlight = true g.SelFgColor = gocui.ColorGreen + + // If InputEsc is true, when ESC sequence is in the buffer and it doesn't + // match any known sequence, ESC means KeyEsc. + g.InputEsc = true g.SetManagerFunc(gui.layout) if err := gui.generateKeybindings(); err != nil { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index a9cfe63..77bd0a2 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -160,6 +160,14 @@ func (gui *Gui) generateKeybindings() error { Display: "t", Description: "Save to Stash", Vital: true, + }, { + View: view.Name, + Key: 'm', + Modifier: gocui.ModNone, + Handler: gui.openCommitMessageView, + Display: "m", + Description: "Commit Changes", + Vital: true, }, } for _, binding := range statusKeybindings { @@ -237,6 +245,24 @@ func (gui *Gui) generateKeybindings() error { Description: "Show diff", Vital: true, }, + // commit message view + { + View: commitMessageViewFeature.Name, + Key: gocui.KeyEsc, + Modifier: gocui.ModNone, + Handler: gui.closeCommitMessageView, + Display: "esc", + Description: "Close / Cancel", + Vital: true, + }, { + View: commitMessageViewFeature.Name, + Key: gocui.KeyEnter, //TODO: enter should be replaced with a better option + Modifier: gocui.ModNone, + Handler: gui.submitCommitMessageView, + Display: "ctrl + enter", + Description: "Submit", + Vital: true, + }, // Main view controls { View: mainViewFeature.Name, diff --git a/pkg/gui/statusview.go b/pkg/gui/statusview.go index d6f0be1..494e07a 100644 --- a/pkg/gui/statusview.go +++ b/pkg/gui/statusview.go @@ -2,19 +2,24 @@ package gui import ( "fmt" + "time" "github.com/isacikgoz/gitbatch/pkg/git" "github.com/jroimartin/gocui" + ggt "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/plumbing/object" ) var ( statusHeaderViewFeature = viewFeature{Name: "status-header", Title: " Status Header "} // statusViewFeature = viewFeature{Name: "status", Title: " Status "} - stageViewFeature = viewFeature{Name: "staged", Title: " Staged "} - unstageViewFeature = viewFeature{Name: "unstaged", Title: " Not Staged "} - stashViewFeature = viewFeature{Name: "stash", Title: " Stash "} + stageViewFeature = viewFeature{Name: "staged", Title: " Staged "} + unstageViewFeature = viewFeature{Name: "unstaged", Title: " Not Staged "} + stashViewFeature = viewFeature{Name: "stash", Title: " Stash "} + commitMessageViewFeature = viewFeature{Name: "commitmessage", Title: " Commit Mesage "} - statusViews = []viewFeature{stageViewFeature, unstageViewFeature, stashViewFeature} + statusViews = []viewFeature{stageViewFeature, unstageViewFeature, stashViewFeature} + commitMesageReturnView string ) // open the status layout @@ -168,3 +173,73 @@ func refreshAllStatusView(g *gocui.Gui, entity *git.RepoEntity) error { } return nil } + +// open the commit message views +func (gui *Gui) openCommitMessageView(g *gocui.Gui, v *gocui.View) error { + maxX, maxY := g.Size() + commitMesageReturnView = v.Name() + v, err := g.SetView(commitMessageViewFeature.Name, maxX/2-30, maxY/2-3, maxX/2+30, maxY/2+3) + if err != nil { + if err != gocui.ErrUnknownView { + return err + } + v.Title = commitMessageViewFeature.Title + v.Wrap = true + v.Editable = true + v.Editor = gocui.DefaultEditor + v.Highlight = true + g.Cursor = true + } + gui.updateKeyBindingsView(g, commitMessageViewFeature.Name) + if _, err := g.SetCurrentView(commitMessageViewFeature.Name); err != nil { + return err + } + return nil +} + +// close the opened commite mesage view +func (gui *Gui) submitCommitMessageView(g *gocui.Gui, v *gocui.View) error { + entity := gui.getSelectedRepository() + w, err := entity.Repository.Worktree() + if err != nil { + return err + } + // WIP: This better be removed to git pkg + // TODO: read config and get name & e-mail + _, err = w.Commit(v.ViewBuffer(), &ggt.CommitOptions{ + Author: &object.Signature{ + Name: "İbrahim Serdar Açıkgöz", + Email: "serdaracikgoz86@gmail.com", + When: time.Now(), + }, + }) + if err != nil { + return err + } + entity.Refresh() + err = gui.closeCommitMessageView(g, v) + return err +} + +// close the opened commite mesage view +func (gui *Gui) closeCommitMessageView(g *gocui.Gui, v *gocui.View) error { + entity := gui.getSelectedRepository() + g.Cursor = false + if err := g.DeleteView(commitMessageViewFeature.Name); err != nil { + return err + } + if _, err := g.SetCurrentView(commitMesageReturnView); err != nil { + return err + } + if err := gui.refreshMain(g); err != nil { + return err + } + if err := gui.refreshViews(g, entity); err != nil { + return err + } + if err := refreshAllStatusView(g, entity); err != nil { + return err + } + gui.updateKeyBindingsView(g, commitMesageReturnView) + return nil +} |
