aboutsummaryrefslogtreecommitdiffstats
path: root/input/input.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-11 19:28:32 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-11 19:28:32 +0200
commit9cbd5b4ee113c660377ffe9c01ca374d6addfef4 (patch)
tree8720b18cba789d27f28b3ce024f7caa90e93ccc7 /input/input.go
parent30e38aab0849d28eaea11c5e1f9f9423a0999e0d (diff)
downloadgit-bug-9cbd5b4ee113c660377ffe9c01ca374d6addfef4.tar.gz
termui: allow to change the bug query
Diffstat (limited to 'input/input.go')
-rw-r--r--input/input.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/input/input.go b/input/input.go
index 8e7f3d97..16264efc 100644
--- a/input/input.go
+++ b/input/input.go
@@ -149,6 +149,38 @@ func BugTitleEditorInput(repo repository.Repo, preTitle string) (string, error)
return title, nil
}
+const queryTemplate = `%s
+
+# Please edit the bug query.
+# Lines starting with '#' will be ignored, and an empty query aborts the operation.
+`
+
+// QueryEditorInput will open the default editor in the terminal with a
+// template for the user to fill. The file is then processed to extract a query.
+func QueryEditorInput(repo repository.Repo, preQuery string) (string, error) {
+ template := fmt.Sprintf(queryTemplate, preQuery)
+ raw, err := launchEditorWithTemplate(repo, messageFilename, template)
+
+ if err != nil {
+ return "", err
+ }
+
+ lines := strings.Split(raw, "\n")
+
+ for _, line := range lines {
+ if strings.HasPrefix(line, "#") {
+ continue
+ }
+ trimmed := strings.TrimSpace(line)
+ if trimmed == "" {
+ continue
+ }
+ return trimmed, nil
+ }
+
+ return "", nil
+}
+
// launchEditorWithTemplate will launch an editor as launchEditor do, but with a
// provided template.
func launchEditorWithTemplate(repo repository.Repo, fileName string, template string) (string, error) {