use more clear name
This commit is contained in:
parent
3c8b87c9c6
commit
9641eee38a
2 changed files with 20 additions and 20 deletions
|
|
@ -87,7 +87,7 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle, providedBody string, def
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read config: %w", err)
|
||||
}
|
||||
editorName, _ := cfg.Get(defaultHostname, "editor")
|
||||
editorCommand, _ := cfg.Get(defaultHostname, "editor")
|
||||
|
||||
var inProgress titleBody
|
||||
inProgress.Title = defs.Title
|
||||
|
|
@ -116,7 +116,7 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle, providedBody string, def
|
|||
bodyQuestion := &survey.Question{
|
||||
Name: "body",
|
||||
Prompt: &surveyext.GhEditor{
|
||||
EditorName: editorName,
|
||||
EditorCommand: editorCommand,
|
||||
Editor: &survey.Editor{
|
||||
Message: "Body",
|
||||
FileName: "*.md",
|
||||
|
|
|
|||
|
|
@ -37,15 +37,15 @@ func init() {
|
|||
// EXTENDED to enable different prompting behavior
|
||||
type GhEditor struct {
|
||||
*survey.Editor
|
||||
EditorName string
|
||||
EditorCommand string
|
||||
}
|
||||
|
||||
func (e *GhEditor) editorName() string {
|
||||
if e.EditorName == "" {
|
||||
func (e *GhEditor) editorCommand() string {
|
||||
if e.EditorCommand == "" {
|
||||
return defaultEditor
|
||||
}
|
||||
|
||||
return e.EditorName
|
||||
return e.EditorCommand
|
||||
}
|
||||
|
||||
// EXTENDED to change prompt text
|
||||
|
|
@ -58,17 +58,17 @@ var EditorQuestionTemplate = `
|
|||
{{- else }}
|
||||
{{- if and .Help (not .ShowHelp)}}{{color "cyan"}}[{{ .Config.HelpInput }} for help]{{color "reset"}} {{end}}
|
||||
{{- if and .Default (not .HideDefault)}}{{color "white"}}({{.Default}}) {{color "reset"}}{{end}}
|
||||
{{- color "cyan"}}[(e) to launch {{ .EditorName }}, enter to skip] {{color "reset"}}
|
||||
{{- color "cyan"}}[(e) to launch {{ .EditorCommand }}, enter to skip] {{color "reset"}}
|
||||
{{- end}}`
|
||||
|
||||
// EXTENDED to pass editor name (to use in prompt)
|
||||
type EditorTemplateData struct {
|
||||
survey.Editor
|
||||
EditorName string
|
||||
Answer string
|
||||
ShowAnswer bool
|
||||
ShowHelp bool
|
||||
Config *survey.PromptConfig
|
||||
EditorCommand string
|
||||
Answer string
|
||||
ShowAnswer bool
|
||||
ShowHelp bool
|
||||
Config *survey.PromptConfig
|
||||
}
|
||||
|
||||
// EXTENDED to augment prompt text and keypress handling
|
||||
|
|
@ -77,9 +77,9 @@ func (e *GhEditor) prompt(initialValue string, config *survey.PromptConfig) (int
|
|||
EditorQuestionTemplate,
|
||||
// EXTENDED to support printing editor in prompt
|
||||
EditorTemplateData{
|
||||
Editor: *e.Editor,
|
||||
EditorName: filepath.Base(e.editorName()),
|
||||
Config: config,
|
||||
Editor: *e.Editor,
|
||||
EditorCommand: filepath.Base(e.editorCommand()),
|
||||
Config: config,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
|
@ -118,10 +118,10 @@ func (e *GhEditor) prompt(initialValue string, config *survey.PromptConfig) (int
|
|||
EditorQuestionTemplate,
|
||||
EditorTemplateData{
|
||||
// EXTENDED to support printing editor in prompt
|
||||
Editor: *e.Editor,
|
||||
EditorName: filepath.Base(e.editorName()),
|
||||
ShowHelp: true,
|
||||
Config: config,
|
||||
Editor: *e.Editor,
|
||||
EditorCommand: filepath.Base(e.editorCommand()),
|
||||
ShowHelp: true,
|
||||
Config: config,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
|
@ -164,7 +164,7 @@ func (e *GhEditor) prompt(initialValue string, config *survey.PromptConfig) (int
|
|||
|
||||
stdio := e.Stdio()
|
||||
|
||||
args, err := shellquote.Split(e.editorName())
|
||||
args, err := shellquote.Split(e.editorCommand())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue