diff options
| author | Julian Andres Klode <jak@debian.org> | 2024-10-22 12:35:17 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2024-10-22 12:35:17 +0000 |
| commit | 8e20203cc68aa39ed5736f46c608f89c523fbf30 (patch) | |
| tree | ab75c6c5f404113c693443fe3f94540c8b886deb | |
| parent | 3c1d97fb21e1fb8b731e6833a5eaa618fd197fcb (diff) | |
| parent | c4de80035d4164d86ec5f15a7568598993b504b6 (diff) | |
Merge branch 'feature/ignorantprompt' into 'main'
Ignore pending input before confirmation prompts
See merge request apt-team/apt!375
| -rw-r--r-- | apt-private/private-output.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 4a946f2b8..3d234727f 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -23,6 +23,7 @@ #include <langinfo.h> #include <regex.h> #include <sys/ioctl.h> +#include <termios.h> #include <unistd.h> #include <sstream> @@ -809,6 +810,12 @@ bool YnPrompt(char const * const Question, bool const Default, bool const ShowGl else _error->DumpErrors(c2o, GlobalError::NOTICE); } + // ignore pending input on terminal + if (not AssumeYes && not AssumeNo && isatty(STDIN_FILENO) == 1) + { + tcflush(STDIN_FILENO, TCIFLUSH); + std::cin.clear(); + } c2o << Question << std::flush; @@ -854,9 +861,10 @@ bool YnPrompt(char const * const Question, bool const Default, bool const ShowGl char response[1024] = ""; std::cin.getline(response, sizeof(response)); - if (!std::cin) return false; + if (isatty(STDIN_FILENO) == 0) + c1o << response << '\n'; if (strlen(response) == 0) return Default; |
