EXTENDED to augment prompt text and keypress handling
(initialValue string, config *survey.PromptConfig)
| 66 | |
| 67 | // EXTENDED to augment prompt text and keypress handling |
| 68 | func (e *GhEditor) prompt(initialValue string, config *survey.PromptConfig) (interface{}, error) { |
| 69 | err := e.Render( |
| 70 | EditorQuestionTemplate, |
| 71 | // EXTENDED to support printing editor in prompt and BlankAllowed |
| 72 | EditorTemplateData{ |
| 73 | Editor: *e.Editor, |
| 74 | BlankAllowed: e.BlankAllowed, |
| 75 | EditorCommand: EditorName(e.EditorCommand), |
| 76 | Config: config, |
| 77 | }, |
| 78 | ) |
| 79 | if err != nil { |
| 80 | return "", err |
| 81 | } |
| 82 | |
| 83 | // start reading runes from the standard in |
| 84 | rr := e.NewRuneReader() |
| 85 | _ = rr.SetTermMode() |
| 86 | defer func() { _ = rr.RestoreTermMode() }() |
| 87 | |
| 88 | cursor := e.NewCursor() |
| 89 | _ = cursor.Hide() |
| 90 | defer func() { |
| 91 | _ = cursor.Show() |
| 92 | }() |
| 93 | |
| 94 | for { |
| 95 | // EXTENDED to handle the e to edit / enter to skip behavior + BlankAllowed |
| 96 | r, _, err := rr.ReadRune() |
| 97 | if err != nil { |
| 98 | return "", err |
| 99 | } |
| 100 | if r == 'e' { |
| 101 | break |
| 102 | } |
| 103 | if r == '\r' || r == '\n' { |
| 104 | if e.BlankAllowed { |
| 105 | return initialValue, nil |
| 106 | } else { |
| 107 | continue |
| 108 | } |
| 109 | } |
| 110 | if r == terminal.KeyInterrupt { |
| 111 | return "", terminal.InterruptErr |
| 112 | } |
| 113 | if r == terminal.KeyEndTransmission { |
| 114 | break |
| 115 | } |
| 116 | if string(r) == config.HelpInput && e.Help != "" { |
| 117 | err = e.Render( |
| 118 | EditorQuestionTemplate, |
| 119 | EditorTemplateData{ |
| 120 | // EXTENDED to support printing editor in prompt, BlankAllowed |
| 121 | Editor: *e.Editor, |
| 122 | BlankAllowed: e.BlankAllowed, |
| 123 | EditorCommand: EditorName(e.EditorCommand), |
| 124 | ShowHelp: true, |
| 125 | Config: config, |