mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 09:58:29 +02:00
Allow editing multiline prompts with external text editor (#429)
- Adds a new `Preferences` struct to the config, initially only containing `Editor: bool (default false)`. This struct will be serialized to configs once there is a first tea induced change to the config (eg `tea login default <name>` or `tea login add`). - Use external editor for all multiline prompts if preferred. We already had a function for starting a texteditor for diff reviews; it does not really make sense to replace it with `survey.Editor`, as there is a big interface mismatch: survey expects strings as inputs, while our diff functions operate on files, fixes #424 Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/429 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
@ -14,9 +14,26 @@ import (
|
||||
"github.com/araddon/dateparse"
|
||||
)
|
||||
|
||||
// PromptMultiline runs a textfield-style prompt and blocks until input was made.
|
||||
func PromptMultiline(message string) (content string, err error) {
|
||||
err = survey.AskOne(&survey.Multiline{Message: message}, &content)
|
||||
// Multiline represents options for a prompt that expects multiline input
|
||||
type Multiline struct {
|
||||
Message string
|
||||
Default string
|
||||
Syntax string
|
||||
UseEditor bool
|
||||
}
|
||||
|
||||
// NewMultiline creates a prompt that switches between the inline multiline text
|
||||
// and a texteditor based prompt
|
||||
func NewMultiline(opts Multiline) (prompt survey.Prompt) {
|
||||
if opts.UseEditor {
|
||||
prompt = &survey.Editor{
|
||||
Message: opts.Message,
|
||||
Default: opts.Default,
|
||||
FileName: "*." + opts.Syntax,
|
||||
}
|
||||
} else {
|
||||
prompt = &survey.Multiline{Message: opts.Message, Default: opts.Default}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user