SET( zypper_utils_HEADERS
utils/Augeas.h
utils/colors.h
+ utils/console.h
utils/getopt.h
utils/messages.h
utils/misc.h
SET( zypper_utils_SRCS
utils/Augeas.cc
utils/colors.cc
+ utils/console.cc
utils/getopt.cc
utils/messages.cc
utils/misc.cc
#include "zypp/base/Logger.h"
-#include "utils/misc.h"
+#include "utils/console.h"
#include "utils/text.h"
#include "Table.h"
// translators: help text for the 'a' option in the 'r/t/a' prompt
popts.setOptionHelp(2, _("Trust the key and import it into trusted keyring."));
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
zypper.out().prompt(PROMPT_YN_GPG_KEY_TRUST, s.str(), popts);
unsigned prep =
get_prompt_reply(zypper, PROMPT_YN_GPG_KEY_TRUST, popts);
#include <boost/format.hpp>
#include <iostream>
-#include <unistd.h>
+#include <unistd.h> // for getpass
#include "callbacks/media.h"
-#include "utils/misc.h"
#include "utils/messages.h"
#include "utils/prompt.h"
+#include "utils/misc.h" // for is_changeable_media
#include "zypp/media/MediaManager.h"
set_common_option_help(popts);
popts.setOptionHelp(4, _("Disable SSL certificate authority check and continue."));
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
// translators: this is a prompt text
zypper.out().prompt(PROMPT_ARI_MEDIA_PROBLEM, _("Abort, retry, ignore?"), popts);
int reply = get_prompt_reply(zypper, PROMPT_ARI_MEDIA_PROBLEM, popts);
int devcount = devices.size();
PromptOptions popts(numbers.str(), 0);
popts.setOptionHelp(devcount, _("Cancel"));
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
zypper.out().prompt(PROMPT_MEDIA_EJECT, _("Select device to eject."), popts);
int reply = get_prompt_reply(zypper, PROMPT_MEDIA_EJECT, popts);
if (reply == devcount)
set_common_option_help(popts);
popts.setOptionHelp(4, _("Eject medium."));
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
// translators: this is a prompt text
zypper.out().prompt(PROMPT_ARI_MEDIA_PROBLEM, _("Abort, retry, ignore?"), popts);
int reply = get_prompt_reply(zypper, PROMPT_ARI_MEDIA_PROBLEM, popts);
PromptOptions popts(_("a/r/i/u"), 0);
set_common_option_help(popts);
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
// translators: this is a prompt text
zypper.out().prompt(PROMPT_ARI_MEDIA_PROBLEM, _("Abort, retry, ignore?"), popts);
int reply = get_prompt_reply(zypper, PROMPT_ARI_MEDIA_PROBLEM, popts);
if (zypper.globalOpts().machine_readable)
cin >> password;
else
- password = getpass("");
+ password = ::getpass("");
if (password.empty())
return false;
auth_data.setPassword(password);
\*---------------------------------------------------------------------------*/
#include <iostream>
+#include <fstream>
#include <sstream>
#include <unistd.h>
#include "OutNormal.h"
-using std::cout;
-using std::cerr;
-using std::endl;
-using std::string;
-using std::ostringstream;
+using namespace std;
OutNormal::OutNormal(Verbosity verbosity)
: Out(TYPE_NORMAL, verbosity),
popts.setOptions(numbers.str() + _("c"), default_reply);
}
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
zypper.out().prompt(PROMPT_DEP_RESOLVE, prompt_text, popts, desc_stm.str());
unsigned int reply =
get_prompt_reply(zypper, PROMPT_DEP_RESOLVE, popts);
string prompt_text = _("View the notifications now?");
unsigned int reply;
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
zypper.out().prompt(PROMPT_YN_INST_REMOVE_CONTINUE, prompt_text, popts);
reply = get_prompt_reply(zypper, PROMPT_YN_INST_REMOVE_CONTINUE, popts);
unsigned int reply;
do
{
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
zypper.out().prompt(PROMPT_YN_INST_REMOVE_CONTINUE, prompt_text, popts);
reply = get_prompt_reply(zypper, PROMPT_YN_INST_REMOVE_CONTINUE, popts);
--- /dev/null
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
+/** \file console.cc
+ * Miscellaneous console utilities.
+ */
+
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <cstdlib>
+
+using namespace std;
+
+// ----------------------------------------------------------------------------
+
+// Read a string. "\004" (^D) on EOF.
+string readline_getline()
+{
+ // A static variable for holding the line.
+ static char *line_read = NULL;
+
+ /* If the buffer has already been allocated,
+ return the memory to the free pool. */
+ if (line_read) {
+ free (line_read);
+ line_read = NULL;
+ }
+
+ //::rl_catch_signals = 0;
+ /* Get a line from the user. */
+ line_read = ::readline ("zypper> ");
+
+ /* If the line has any text in it,
+ save it on the history. */
+ if (line_read && *line_read)
+ ::add_history (line_read);
+
+ if (line_read)
+ return line_read;
+ else
+ return "\004";
+}
+
+// ----------------------------------------------------------------------------
+
+unsigned get_screen_width()
+{
+ if (!::isatty(STDOUT_FILENO))
+ return -1; // no clipping
+
+ int width = 80;
+
+ const char *cols_env = getenv("COLUMNS");
+ if (cols_env)
+ width = ::atoi (cols_env);
+ else
+ {
+ ::rl_initialize();
+ //::rl_reset_screen_size();
+ ::rl_get_screen_size (NULL, &width);
+ }
+
+ // safe default
+ if (!width)
+ width = 80;
+
+ return width;
+}
+
+// ----------------------------------------------------------------------------
+
+void clear_keyboard_buffer()
+{
+ // note: this will not clear characters typed after the last \n
+ ifstream stm("/dev/tty", ifstream::in);
+ char s[8];
+ while (stm.good() && stm.readsome(s, 8));
+}
--- /dev/null
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
+/** \file console.h
+ * Miscellaneous console utilities.
+ */
+
+#ifndef CONSOLE_H_
+#define CONSOLE_H_
+
+/** Use readline to get line of input. */
+std::string readline_getline();
+
+/**
+ * Reads COLUMNS environment variable or gets the screen width from readline,
+ * in that order. Falls back to 80 if all that fails.
+ *
+ * \NOTE In case stdout is not connected to a terminal max. unsigned
+ * is returned. This should prevent clipping when output is redirected.
+ */
+unsigned get_screen_width();
+
+
+/**
+ * Clear the keyboard buffer.
+ * Useful before showing the user prompt message to catch any unwanted <enter>
+ * key hits (bnc #649248).
+ *
+ * \NOTE This will not clear characters typed after the last \n
+ */
+void clear_keyboard_buffer();
+
+
+#endif /* CONSOLE_H_ */
|__/|_| |_|
\*---------------------------------------------------------------------------*/
-#include <fstream>
#include <sstream>
#include <iostream>
-#include <unistd.h>
-#include <readline/readline.h>
-#include <readline/history.h>
+#include <unistd.h> // for getcwd()
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
using namespace std;
using namespace zypp;
-// Read a string. "\004" (^D) on EOF.
-string readline_getline()
-{
- // A static variable for holding the line.
- static char *line_read = NULL;
-
- /* If the buffer has already been allocated,
- return the memory to the free pool. */
- if (line_read) {
- free (line_read);
- line_read = NULL;
- }
-
- //::rl_catch_signals = 0;
- /* Get a line from the user. */
- line_read = ::readline ("zypper> ");
-
- /* If the line has any text in it,
- save it on the history. */
- if (line_read && *line_read)
- add_history (line_read);
-
- if (line_read)
- return line_read;
- else
- return "\004";
-}
-
-// ----------------------------------------------------------------------------
-
-unsigned get_screen_width()
-{
- if (!::isatty(STDOUT_FILENO))
- return -1; // no clipping
-
- int width = 80;
-
- const char *cols_env = getenv("COLUMNS");
- if (cols_env)
- width = ::atoi (cols_env);
- else
- {
- ::rl_initialize();
- //::rl_reset_screen_size();
- ::rl_get_screen_size (NULL, &width);
- }
-
- // safe default
- if (!width)
- width = 80;
-
- return width;
-}
-
// ----------------------------------------------------------------------------
bool is_changeable_media(const zypp::Url & url)
else
{
char buf[PATH_MAX];
- if (getcwd(buf, PATH_MAX) != NULL)
+ if (::getcwd(buf, PATH_MAX) != NULL)
{
DBG << "current working directory: " << buf << endl;
path = string(buf) + "/" + url_s;
#ifndef ZYPPER_UTILS_H
#define ZYPPER_UTILS_H
-#include <ostream>
#include <string>
#include <set>
+#include <list>
#include "zypp/Url.h"
#include "zypp/Pathname.h"
typedef std::set<zypp::ResKind> ResKindSet;
-std::string readline_getline();
-
-/**
- * Reads COLUMNS environment variable or gets the screen width from readline,
- * in that order. Falls back to 80 if all that fails.
- * \NOTE In case stdout is not connected to a terminal max. unsigned
- * is returned. This should prevent clipping when output is redirected.
- */
-unsigned get_screen_width();
-
bool is_changeable_media(const zypp::Url & url);
/** Converts user-supplied kind to zypp::ResKind object.
// correspond to abort/retry/ignore in that order.
// The answers should be lower case letters.
PromptOptions popts(_("a/r/i"), (unsigned int) default_action);
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
zypper.out().prompt(pid, _("Abort, retry, ignore?"), popts);
return get_prompt_reply(zypper, pid, popts);
}
Zypper & zypper = *Zypper::instance();
string yn = string(_("yes")) + "/" + _("no");
PromptOptions popts(yn, default_answer ? 0 : 1);
+ if (!zypper.globalOpts().non_interactive)
+ clear_keyboard_buffer();
zypper.out().prompt(pid, question, popts);
return !get_prompt_reply(zypper, pid, popts);
}
#include <set>
#include "output/prompt.h"
+#include "utils/console.h"
#include "main.h" // for gettext macros
/**