1- package command
1+ package surveyext
22
33// This file extends survey.Editor to give it more flexible behavior. For more context, read
44// https://github.com/github/gh-cli/issues/70
5+ // To see what we extended, search through for EXTENDED comments.
56
67import (
78 "bytes"
@@ -18,7 +19,7 @@ import (
1819
1920var (
2021 bom = []byte {0xef , 0xbb , 0xbf }
21- editor = "nano"
22+ editor = "nano" // EXTENDED to switch from vim as a default editor
2223)
2324
2425func init () {
@@ -33,11 +34,12 @@ func init() {
3334 }
3435}
3536
36- type ghEditor struct {
37+ // EXTENDED to enable different prompting behavior
38+ type GhEditor struct {
3739 * survey.Editor
3840}
3941
40- // Templates with Color formatting. See Documentation: https://github.com/mgutz/ansi#style-format
42+ // EXTENDED to change prompt text
4143var EditorQuestionTemplate = `
4244{{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}}
4345{{- color .Config.Icons.Question.Format }}{{ .Config.Icons.Question.Text }} {{color "reset"}}
@@ -50,6 +52,7 @@ var EditorQuestionTemplate = `
5052 {{- color "cyan"}}[e: launch {{ .EditorName }}][enter: skip for now] {{color "reset"}}
5153{{- end}}`
5254
55+ // EXTENDED to pass editor name (to use in prompt)
5356type EditorTemplateData struct {
5457 survey.Editor
5558 EditorName string
@@ -59,12 +62,11 @@ type EditorTemplateData struct {
5962 Config * survey.PromptConfig
6063}
6164
62- // this is not being called in the embedding case and isn't consulted in the alias case because of
63- // the incomplete overriding.
64- func (e * ghEditor ) prompt (initialValue string , config * survey.PromptConfig ) (interface {}, error ) {
65- // render the template
65+ // EXTENDED to augment prompt text and keypress handling
66+ func (e * GhEditor ) prompt (initialValue string , config * survey.PromptConfig ) (interface {}, error ) {
6667 err := e .Render (
6768 EditorQuestionTemplate ,
69+ // EXTENDED to support printing editor in prompt
6870 EditorTemplateData {
6971 Editor : * e .Editor ,
7072 EditorName : filepath .Base (editor ),
@@ -85,6 +87,7 @@ func (e *ghEditor) prompt(initialValue string, config *survey.PromptConfig) (int
8587 defer cursor .Show ()
8688
8789 for {
90+ // EXTENDED to handle the e to edit / enter to skip behavior
8891 r , _ , err := rr .ReadRune ()
8992 if err != nil {
9093 return "" , err
@@ -105,6 +108,7 @@ func (e *ghEditor) prompt(initialValue string, config *survey.PromptConfig) (int
105108 err = e .Render (
106109 EditorQuestionTemplate ,
107110 EditorTemplateData {
111+ // EXTENDED to support printing editor in prompt
108112 Editor : * e .Editor ,
109113 EditorName : filepath .Base (editor ),
110114 ShowHelp : true ,
@@ -184,8 +188,8 @@ func (e *ghEditor) prompt(initialValue string, config *survey.PromptConfig) (int
184188 return text , nil
185189}
186190
187- // This is straight copypasta from survey to get our overriden prompt called.;
188- func (e * ghEditor ) Prompt (config * survey.PromptConfig ) (interface {}, error ) {
191+ // EXTENDED This is straight copypasta from survey to get our overriden prompt called.;
192+ func (e * GhEditor ) Prompt (config * survey.PromptConfig ) (interface {}, error ) {
189193 initialValue := ""
190194 if e .Default != "" && e .AppendDefault {
191195 initialValue = e .Default
0 commit comments