From 9cbd5b4ee113c660377ffe9c01ca374d6addfef4 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 11 Sep 2018 19:28:32 +0200 Subject: termui: allow to change the bug query --- input/input.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'input') 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) { -- cgit