@@ -179,6 +179,27 @@ command_exec(struct command *cmd)
ohshite(_("unable to execute %s (%s)"), cmd->name, cmd->filename);
}
+
+/**
+ * Get a suitable pager.
+ *
+ * @return A string representing a pager.
+ */
+const char *
+command_get_pager(void)
+{
+ const char *pager;
+ if (!isatty(1))
+ return CAT;
+ pager = getenv("PAGER");
+ if (str_is_unset(pager))
+ pager = DEFAULTPAGER;
+ return pager;
+}
/**
* Execute a shell with a possible command.
*
@@ -54,6 +54,7 @@ void command_add_args(struct command *cmd, ...) DPKG_ATTR_SENTINEL;
void command_exec(struct command *cmd) DPKG_ATTR_NORET;
+const char *command_get_pager(void);
void command_shell(const char *cmd, const char *name);
/** @} */
@@ -110,6 +110,7 @@ DPKG_BEGIN_DECLS
#define TAR "tar"
#define RM "rm"
+#define CAT "cat"
#define FIND "find"
#define DIFF "diff"
@@ -128,6 +128,7 @@ LIBDPKG_PRIVATE {
command_add_argv;
command_add_args;
command_exec;
+ command_get_pager;
command_shell;
command_destroy;