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:
Norwin
2021-10-14 22:36:08 +08:00
committed by Lunny Xiao
parent 5b77345b03
commit 78a95f1ca4
7 changed files with 62 additions and 11 deletions

View File

@ -17,9 +17,16 @@ import (
"gopkg.in/yaml.v2"
)
// Preferences that are stored in and read from the config file
type Preferences struct {
// Prefer using an external text editor over inline multiline prompts
Editor bool `yaml:"editor"`
}
// LocalConfig represents local configurations
type LocalConfig struct {
Logins []Login `yaml:"logins"`
Logins []Login `yaml:"logins"`
Prefs Preferences `yaml:"preferences"`
}
var (
@ -55,6 +62,11 @@ func GetConfigPath() string {
return configFilePath
}
// GetPreferences returns preferences based on the config file
func GetPreferences() Preferences {
return config.Prefs
}
// loadConfig load config from file
func loadConfig() (err error) {
loadConfigOnce.Do(func() {