diff options
author | Michael Muré <batolettre@gmail.com> | 2018-10-04 21:47:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-04 21:47:01 +0200 |
commit | 43db2c77348016d9bc05c713765b2b58534c7c39 (patch) | |
tree | 3a80c4fe5599acb47dae61f61bd8f2ce0a80fa0a /termui/termui.go | |
parent | f464363213ce7315d1f3ea10138450a4ca7432d3 (diff) | |
parent | 97afd6b68a0f358a0c8b88c9e22cd7c57080a3ad (diff) | |
download | git-bug-43db2c77348016d9bc05c713765b2b58534c7c39.tar.gz |
Merge pull request #60 from adamslc/commentedit
termui: add the ability to edit comments
Diffstat (limited to 'termui/termui.go')
-rw-r--r-- | termui/termui.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/termui/termui.go b/termui/termui.go index f2163d96..5c39869b 100644 --- a/termui/termui.go +++ b/termui/termui.go @@ -4,6 +4,7 @@ package termui import ( "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/input" + "github.com/MichaelMure/git-bug/util/git" "github.com/jroimartin/gocui" "github.com/pkg/errors" ) @@ -210,7 +211,7 @@ func addCommentWithEditor(bug *cache.BugCache) error { ui.g.Close() ui.g = nil - message, err := input.BugCommentEditorInput(ui.cache) + message, err := input.BugCommentEditorInput(ui.cache, "") if err != nil && err != input.ErrEmptyMessage { return err @@ -230,6 +231,41 @@ func addCommentWithEditor(bug *cache.BugCache) error { return errTerminateMainloop } +func editCommentWithEditor(bug *cache.BugCache, target git.Hash, preMessage string) error { + // This is somewhat hacky. + // As there is no way to pause gocui, run the editor and restart gocui, + // we have to stop it entirely and start a new one later. + // + // - an error channel is used to route the returned error of this new + // instance into the original launch function + // - a custom error (errTerminateMainloop) is used to terminate the original + // instance's mainLoop. This error is then filtered. + + ui.g.Close() + ui.g = nil + + message, err := input.BugCommentEditorInput(ui.cache, preMessage) + if err != nil && err != input.ErrEmptyMessage { + return err + } + + if err == input.ErrEmptyMessage { + // TODO: Allow comments to be deleted? + ui.msgPopup.Activate(msgPopupErrorTitle, "Empty message, aborting.") + } else if message == preMessage { + ui.msgPopup.Activate(msgPopupErrorTitle, "No changes found, aborting.") + } else { + err := bug.EditComment(target, message) + if err != nil { + return err + } + } + + initGui(nil) + + return errTerminateMainloop +} + func setTitleWithEditor(bug *cache.BugCache) error { // This is somewhat hacky. // As there is no way to pause gocui, run the editor and restart gocui, |