ask asks survey questions on the terminal, using standard options. It fails unless hasTTY, but ideally callers should avoid calling it in that case.
(qs []*survey.Question, response interface{})
| 155 | // ask asks survey questions on the terminal, using standard options. |
| 156 | // It fails unless hasTTY, but ideally callers should avoid calling it in that case. |
| 157 | func (p *Prompter) Ask(qs []*survey.Question, response interface{}) error { |
| 158 | if !hasTTY { |
| 159 | return fmt.Errorf("no terminal") |
| 160 | } |
| 161 | err := survey.Ask(qs, response, survey.WithShowCursor(true)) |
| 162 | // The survey package temporarily clears the terminal's ISIG mode bit |
| 163 | // (see tcsetattr(3)) so the QUIT button (Ctrl-C) is reported as |
| 164 | // ASCII \x03 (ETX) instead of delivering SIGINT to the application. |
| 165 | // So we have to serve ourselves the SIGINT. |
| 166 | // |
| 167 | // https://github.com/AlecAivazis/survey/#why-isnt-ctrl-c-working |
| 168 | if err == terminal.InterruptErr { |
| 169 | self, _ := os.FindProcess(os.Getpid()) |
| 170 | _ = self.Signal(os.Interrupt) // assumes POSIX |
| 171 | |
| 172 | // Suspend the goroutine, to avoid a race between |
| 173 | // return from main and async delivery of INT signal. |
| 174 | select {} |
| 175 | } |
| 176 | return err |
| 177 | } |
| 178 | |
| 179 | var ErrTooManyArgs = errors.New("the command accepts no arguments") |
| 180 |
no test coverage detected