summaryrefslogtreecommitdiff
path: root/src/cmdline
diff options
context:
space:
mode:
authorDaniel_Burrows@alumni.brown.edu <Daniel_Burrows@alumni.brown.edu>2010-07-08 09:43:26 -0700
committerDaniel Burrows <dburrows@debian.org>2010-07-10 10:27:33 -0700
commit999360e26876e4e15734735c2826748ce830ba37 (patch)
tree67fba895b366f5330b2b6cfed0ce5bad07ade099 /src/cmdline
parentd6c98d5670bddada3158daa81208f2a847b79361 (diff)
downloadaptitude-999360e26876e4e15734735c2826748ce830ba37.tar.gz
Split the "terminal" interface into several interfaces that each export one piece of its functionality.
This will make some of the tests easier to write, since often some of the code requires just the ability to read the screen width, or just the ability to read input from the terminal. Splitting the terminal interface means no need to mock out the parts that aren't used.
Diffstat (limited to 'src/cmdline')
-rw-r--r--src/cmdline/cmdline_action.cc32
-rw-r--r--src/cmdline/cmdline_action.h8
-rw-r--r--src/cmdline/cmdline_changelog.cc49
-rw-r--r--src/cmdline/cmdline_changelog.h4
-rw-r--r--src/cmdline/cmdline_clean.cc13
-rw-r--r--src/cmdline/cmdline_do_action.cc11
-rw-r--r--src/cmdline/cmdline_download.cc8
-rw-r--r--src/cmdline/cmdline_download_progress_display.cc24
-rw-r--r--src/cmdline/cmdline_download_progress_display.h6
-rw-r--r--src/cmdline/cmdline_extract_cache_subset.cc9
-rw-r--r--src/cmdline/cmdline_forget_new.cc9
-rw-r--r--src/cmdline/cmdline_progress.cc12
-rw-r--r--src/cmdline/cmdline_progress.h4
-rw-r--r--src/cmdline/cmdline_progress_display.cc7
-rw-r--r--src/cmdline/cmdline_progress_display.h8
-rw-r--r--src/cmdline/cmdline_prompt.cc70
-rw-r--r--src/cmdline/cmdline_prompt.h4
-rw-r--r--src/cmdline/cmdline_resolver.cc44
-rw-r--r--src/cmdline/cmdline_resolver.h8
-rw-r--r--src/cmdline/cmdline_search.cc20
-rw-r--r--src/cmdline/cmdline_show.cc36
-rw-r--r--src/cmdline/cmdline_show.h4
-rw-r--r--src/cmdline/cmdline_simulate.cc6
-rw-r--r--src/cmdline/cmdline_simulate.h4
-rw-r--r--src/cmdline/cmdline_spinner.cc8
-rw-r--r--src/cmdline/cmdline_spinner.h6
-rw-r--r--src/cmdline/cmdline_update.cc9
-rw-r--r--src/cmdline/cmdline_user_tag.cc9
-rw-r--r--src/cmdline/cmdline_util.cc26
-rw-r--r--src/cmdline/cmdline_util.h16
-rw-r--r--src/cmdline/cmdline_versions.cc18
-rw-r--r--src/cmdline/cmdline_why.cc23
-rw-r--r--src/cmdline/cmdline_why.h4
-rw-r--r--src/cmdline/mocks/teletype.cc51
-rw-r--r--src/cmdline/mocks/teletype.h11
-rw-r--r--src/cmdline/mocks/terminal.cc163
-rw-r--r--src/cmdline/mocks/terminal.h95
-rw-r--r--src/cmdline/terminal.cc24
-rw-r--r--src/cmdline/terminal.h55
-rw-r--r--src/cmdline/text_progress.cc7
-rw-r--r--src/cmdline/text_progress.h8
-rw-r--r--src/cmdline/transient_message.cc44
-rw-r--r--src/cmdline/transient_message.h13
43 files changed, 552 insertions, 438 deletions
diff --git a/src/cmdline/cmdline_action.cc b/src/cmdline/cmdline_action.cc
index 59d61617..87b0667b 100644
--- a/src/cmdline/cmdline_action.cc
+++ b/src/cmdline/cmdline_action.cc
@@ -28,7 +28,7 @@
namespace cw = cwidget;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_metrics;
using boost::shared_ptr;
namespace
@@ -43,7 +43,7 @@ namespace
pkgset &to_remove, pkgset &to_purge,
int verbose,
bool allow_auto,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
aptitude::cmdline::source_package sourcepkg =
aptitude::cmdline::find_source_package(pkg,
@@ -147,7 +147,7 @@ namespace
policy,
arch_only,
allow_auto,
- term);
+ term_metrics);
satisfied = true;
}
}
@@ -182,7 +182,7 @@ namespace
policy,
arch_only,
allow_auto,
- term);
+ term_metrics);
}
}
}
@@ -229,7 +229,7 @@ bool cmdline_applyaction(cmdline_pkgaction_type action,
pkgPolicy &policy,
bool arch_only,
bool allow_auto,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
// Handle virtual packages.
if(!pkg.ProvidesList().end())
@@ -285,7 +285,7 @@ bool cmdline_applyaction(cmdline_pkgaction_type action,
{
printf(_("\"%s\" is a virtual package provided by:\n"),
pkg.Name());
- cmdline_show_pkglist(cands, term);
+ cmdline_show_pkglist(cands, term_metrics);
printf(_("You must choose one to install.\n"));
}
return false;
@@ -435,7 +435,7 @@ bool cmdline_applyaction(cmdline_pkgaction_type action,
to_remove, to_purge,
verbose,
allow_auto,
- term);
+ term_metrics);
default:
fprintf(stderr, "Internal error: impossible pkgaction type\n");
abort();
@@ -452,7 +452,7 @@ bool cmdline_applyaction(string s,
int verbose,
pkgPolicy &policy, bool arch_only,
bool allow_auto,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
using namespace aptitude::matching;
@@ -485,7 +485,7 @@ bool cmdline_applyaction(string s,
sourcestr,
policy, arch_only,
allow_auto,
- term) && rval;
+ term_metrics) && rval;
}
// break out.
@@ -532,7 +532,7 @@ bool cmdline_applyaction(string s,
to_remove, to_purge,
verbose,
allow_auto,
- term);
+ term_metrics);
// Maybe they misspelled the package name?
pkgvector possible;
@@ -553,7 +553,7 @@ bool cmdline_applyaction(string s,
else
{
printf(_("Couldn't find package \"%s\". However, the following\npackages contain \"%s\" in their name:\n"), package.c_str(), package.c_str());
- cmdline_show_pkglist(possible, term);
+ cmdline_show_pkglist(possible, term_metrics);
}
}
else
@@ -580,7 +580,7 @@ bool cmdline_applyaction(string s,
else
{
printf(_("Couldn't find any package matching \"%s\". However, the following\npackages contain \"%s\" in their description:\n"), package.c_str(), package.c_str());
- cmdline_show_pkglist(possible, term);
+ cmdline_show_pkglist(possible, term_metrics);
}
}
@@ -592,7 +592,7 @@ bool cmdline_applyaction(string s,
to_install, to_hold, to_remove, to_purge,
verbose, source,
sourcestr, policy, arch_only, allow_auto,
- term);
+ term_metrics);
}
else
{
@@ -618,7 +618,7 @@ bool cmdline_applyaction(string s,
sourcestr,
policy, arch_only,
allow_auto,
- term))
+ term_metrics))
rval = false;
}
}
@@ -707,7 +707,7 @@ void cmdline_parse_action(string s,
int verbose,
pkgPolicy &policy, bool arch_only,
bool allow_auto,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term)
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics)
{
string::size_type loc=0;
@@ -745,7 +745,7 @@ void cmdline_parse_action(string s,
to_remove, to_purge,
verbose, policy,
arch_only, allow_auto,
- term))
+ term_metrics))
return;
}
}
diff --git a/src/cmdline/cmdline_action.h b/src/cmdline/cmdline_action.h
index ae1eda65..37510d31 100644
--- a/src/cmdline/cmdline_action.h
+++ b/src/cmdline/cmdline_action.h
@@ -37,7 +37,7 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
}
}
@@ -111,7 +111,7 @@ bool cmdline_applyaction(cmdline_pkgaction_type action,
pkgPolicy &policy,
bool arch_only,
bool allow_auto,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term);
/** \brief Apply the given command-line action to the given package,
* updating the command-line state appropriately.
@@ -172,7 +172,7 @@ bool cmdline_applyaction(string s,
int verbose,
pkgPolicy &policy, bool arch_only,
bool allow_auto,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term);
/** \brief Parses a list of actions and executes them.
*
@@ -229,6 +229,6 @@ void cmdline_parse_action(string s,
int verbose,
pkgPolicy &policy, bool arch_only,
bool allow_auto,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term);
#endif // CMDLINE_ACTION_H
diff --git a/src/cmdline/cmdline_changelog.cc b/src/cmdline/cmdline_changelog.cc
index 8d9bccf9..53e6faf7 100644
--- a/src/cmdline/cmdline_changelog.cc
+++ b/src/cmdline/cmdline_changelog.cc
@@ -54,7 +54,8 @@
using namespace std;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_io;
+using aptitude::cmdline::terminal_metrics;
using boost::shared_ptr;
namespace
@@ -74,15 +75,15 @@ void set_name(temp::name n, temp::name *target)
{
std::string description;
bool quiet;
- shared_ptr<terminal> term;
+ shared_ptr<terminal_metrics> term_metrics;
public:
single_download_progress(const std::string &_description,
bool _quiet,
- const shared_ptr<terminal> &_term)
+ const shared_ptr<terminal_metrics> &_term_metrics)
: description(_description),
quiet(_quiet),
- term(_term)
+ term_metrics(_term_metrics)
{
}
@@ -95,7 +96,7 @@ void set_name(temp::name n, temp::name *target)
if (quiet)
return;
- const int screen_width = term->get_screen_width();
+ const int screen_width = term_metrics->get_screen_width();
unsigned long TotalBytes = totalSize;
unsigned long CurrentBytes = currentSize;
@@ -129,7 +130,7 @@ void set_name(temp::name n, temp::name *target)
{
if(!quiet)
std::cout << "\r"
- << std::string(term->get_screen_width(), ' ')
+ << std::string(term_metrics->get_screen_width(), ' ')
<< "\r";
std::cout << _("Get:") << " " << description << std::endl;
@@ -139,7 +140,7 @@ void set_name(temp::name n, temp::name *target)
{
if(!quiet)
std::cout << "\r"
- << std::string(term->get_screen_width(), ' ')
+ << std::string(term_metrics->get_screen_width(), ' ')
<< "\r";
std::cout << _("Err ") << description << std::endl;
@@ -154,10 +155,10 @@ void set_name(temp::name n, temp::name *target)
public:
changelog_download_callbacks(temp::name &_out_changelog_file,
const std::string &short_description,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
: single_download_progress(short_description,
aptcfg->FindI("Quiet", 0) > 0,
- term),
+ term_metrics),
out_changelog_file(_out_changelog_file)
{
}
@@ -185,7 +186,7 @@ void set_name(temp::name n, temp::name *target)
void get_changelog(const pkgCache::VerIterator &ver,
temp::name &out_changelog_file,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
const std::string short_description =
(boost::format("Changelog of %s") % ver.ParentPkg().Name()).str();
@@ -193,7 +194,7 @@ void set_name(temp::name n, temp::name *target)
boost::shared_ptr<changelog_download_callbacks>
callbacks = boost::make_shared<changelog_download_callbacks>(boost::ref(out_changelog_file),
short_description,
- term);
+ term_metrics);
get_changelog(aptitude::apt::changelog_info::create(ver),
callbacks,
@@ -219,7 +220,7 @@ void set_name(temp::name n, temp::name *target)
const std::string &section,
const std::string &name,
temp::name &out_changelog_file,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
const std::string short_description =
(boost::format("Changelog of %s") % name).str();
@@ -227,7 +228,7 @@ void set_name(temp::name n, temp::name *target)
boost::shared_ptr<changelog_download_callbacks>
callbacks = boost::make_shared<changelog_download_callbacks>(boost::ref(out_changelog_file),
short_description,
- term);
+ term_metrics);
boost::shared_ptr<aptitude::apt::changelog_info>
info = aptitude::apt::changelog_info::create(srcpkg, ver, section, name);
@@ -246,7 +247,7 @@ void set_name(temp::name n, temp::name *target)
*/
temp::name changelog_by_version(const std::string &pkg,
const std::string &ver,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
// Try forcing the particular version that was
// selected, using various sections. FIXME: relies
@@ -256,16 +257,16 @@ temp::name changelog_by_version(const std::string &pkg,
temp::name rval;
- get_changelog_from_source(pkg, ver, "", pkg, rval, term);
+ get_changelog_from_source(pkg, ver, "", pkg, rval, term_metrics);
if(!rval.valid())
{
- get_changelog_from_source(pkg, ver, "contrib/foo", pkg, rval, term);
+ get_changelog_from_source(pkg, ver, "contrib/foo", pkg, rval, term_metrics);
}
if(!rval.valid())
{
- get_changelog_from_source(pkg, ver, "non-free/foo", pkg, rval, term);
+ get_changelog_from_source(pkg, ver, "non-free/foo", pkg, rval, term_metrics);
}
return rval;
@@ -273,7 +274,7 @@ temp::name changelog_by_version(const std::string &pkg,
}
void do_cmdline_changelog(const vector<string> &packages,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
const char *pager="/usr/bin/sensible-pager";
@@ -356,7 +357,7 @@ void do_cmdline_changelog(const vector<string> &packages,
p.get_section(),
pkg.Name(),
filename,
- term);
+ term_metrics);
}
else
{
@@ -365,13 +366,13 @@ void do_cmdline_changelog(const vector<string> &packages,
if(ver.end())
{
if(source == cmdline_version_version)
- filename = changelog_by_version(package, sourcestr, term);
+ filename = changelog_by_version(package, sourcestr, term_metrics);
// If we don't even have a version string, leave
// filename blank; we'll fail below.
}
else
{
- get_changelog(ver, filename, term);
+ get_changelog(ver, filename, term_metrics);
}
}
}
@@ -389,7 +390,7 @@ void do_cmdline_changelog(const vector<string> &packages,
p.get_section(),
p.get_package(),
filename,
- term);
+ term_metrics);
}
else
{
@@ -414,7 +415,7 @@ void do_cmdline_changelog(const vector<string> &packages,
break;
case cmdline_version_version:
- filename = changelog_by_version(package, sourcestr, term);
+ filename = changelog_by_version(package, sourcestr, term_metrics);
break;
}
}
@@ -433,7 +434,7 @@ void do_cmdline_changelog(const vector<string> &packages,
// TODO: fetch them all in one go.
int cmdline_changelog(int argc, char *argv[])
{
- shared_ptr<terminal> term = create_terminal();
+ shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
diff --git a/src/cmdline/cmdline_changelog.h b/src/cmdline/cmdline_changelog.h
index f638e705..580b8fb4 100644
--- a/src/cmdline/cmdline_changelog.h
+++ b/src/cmdline/cmdline_changelog.h
@@ -33,7 +33,7 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
}
}
@@ -43,7 +43,7 @@ namespace aptitude
* descriptors. DumpErrors() is called after each changelog is displayed.
*/
void do_cmdline_changelog(const std::vector<std::string> &packages,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
int cmdline_changelog(int argc, char *argv[]);
diff --git a/src/cmdline/cmdline_clean.cc b/src/cmdline/cmdline_clean.cc
index b4810cf0..683f654d 100644
--- a/src/cmdline/cmdline_clean.cc
+++ b/src/cmdline/cmdline_clean.cc
@@ -44,16 +44,14 @@
using namespace std;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_io;
using aptitude::cmdline::terminal_locale;
using boost::shared_ptr;
int cmdline_clean(int argc, char *argv[], bool simulate)
{
- const shared_ptr<terminal> term = create_terminal();
- const shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ const shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
@@ -63,7 +61,7 @@ int cmdline_clean(int argc, char *argv[], bool simulate)
return -1;
}
- shared_ptr<OpProgress> progress = make_text_progress(false, term, term_locale);
+ shared_ptr<OpProgress> progress = make_text_progress(false, term, term, term);
apt_init(progress.get(), false);
@@ -137,8 +135,7 @@ public:
int cmdline_autoclean(int argc, char *argv[], bool simulate)
{
- const shared_ptr<terminal> term = create_terminal();
- const shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ const shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
@@ -148,7 +145,7 @@ int cmdline_autoclean(int argc, char *argv[], bool simulate)
return -1;
}
- shared_ptr<OpProgress> progress = make_text_progress(false, term, term_locale);
+ shared_ptr<OpProgress> progress = make_text_progress(false, term, term, term);
apt_init(progress.get(), false);
diff --git a/src/cmdline/cmdline_do_action.cc b/src/cmdline/cmdline_do_action.cc
index fc791247..2ba99ae2 100644
--- a/src/cmdline/cmdline_do_action.cc
+++ b/src/cmdline/cmdline_do_action.cc
@@ -49,10 +49,8 @@
using namespace std;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
-using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_io;
using boost::shared_ptr;
namespace
@@ -101,8 +99,7 @@ int cmdline_do_action(int argc, char *argv[],
bool arch_only,
bool queue_only, int verbose)
{
- shared_ptr<terminal> term = create_terminal();
- shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
@@ -167,7 +164,7 @@ int cmdline_do_action(int argc, char *argv[],
if(resolver_mode == resolver_mode_default)
resolver_mode = resolver_mode_full;
- shared_ptr<OpProgress> progress = make_text_progress(false, term, term_locale);
+ shared_ptr<OpProgress> progress = make_text_progress(false, term, term, term);
aptcfg->SetNoUser(PACKAGE "::Auto-Upgrade", "false");
@@ -394,7 +391,7 @@ int cmdline_do_action(int argc, char *argv[],
sigc::ptr_fun(&run_dpkg_directly));
int rval =
- (cmdline_do_download(&m, verbose, term, term_locale)
+ (cmdline_do_download(&m, verbose, term, term, term)
== download_manager::success ? 0 : -1);
if(_error->PendingError())
diff --git a/src/cmdline/cmdline_download.cc b/src/cmdline/cmdline_download.cc
index 1c53e71f..94aa7ff6 100644
--- a/src/cmdline/cmdline_download.cc
+++ b/src/cmdline/cmdline_download.cc
@@ -28,17 +28,15 @@
#include <stdio.h>
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_io;
using aptitude::cmdline::terminal_locale;
using boost::shared_ptr;
// Download stuff to the current directory
int cmdline_download(int argc, char *argv[])
{
- shared_ptr<terminal> term = create_terminal();
- shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ shared_ptr<terminal_io> term = create_terminal();
if(argc<=1)
{
@@ -48,7 +46,7 @@ int cmdline_download(int argc, char *argv[])
_error->DumpErrors();
- shared_ptr<OpProgress> progress = make_text_progress(false, term, term_locale);
+ shared_ptr<OpProgress> progress = make_text_progress(false, term, term, term);
apt_init(progress.get(), false);
pkgSourceList list;
diff --git a/src/cmdline/cmdline_download_progress_display.cc b/src/cmdline/cmdline_download_progress_display.cc
index 2830d432..fbabf853 100644
--- a/src/cmdline/cmdline_download_progress_display.cc
+++ b/src/cmdline/cmdline_download_progress_display.cc
@@ -37,16 +37,16 @@ namespace aptitude
class download_progress : public views::download_progress
{
shared_ptr<transient_message> message;
- shared_ptr<terminal> term;
shared_ptr<terminal_locale> term_locale;
+ shared_ptr<terminal_metrics> term_metrics;
download_progress(const shared_ptr<transient_message> &_message,
- const shared_ptr<terminal> &_term,
- const shared_ptr<terminal_locale> &_term_locale);
+ const shared_ptr<terminal_locale> &_term_locale,
+ const shared_ptr<terminal_metrics> &_term_metrics);
friend shared_ptr<download_progress>
make_shared<download_progress>(const shared_ptr<transient_message> &,
- const shared_ptr<terminal> &,
- const shared_ptr<terminal_locale> &);
+ const shared_ptr<terminal_locale> &,
+ const shared_ptr<terminal_metrics> &);
public:
bool update_progress(const status &current_status);
@@ -74,11 +74,11 @@ namespace aptitude
};
download_progress::download_progress(const shared_ptr<transient_message> &_message,
- const shared_ptr<terminal> &_term,
- const shared_ptr<terminal_locale> &_term_locale)
+ const shared_ptr<terminal_locale> &_term_locale,
+ const shared_ptr<terminal_metrics> &_term_metrics)
: message(_message),
- term(_term),
- term_locale(_term_locale)
+ term_locale(_term_locale),
+ term_metrics(_term_metrics)
{
}
@@ -122,10 +122,10 @@ namespace aptitude
shared_ptr<views::download_progress>
create_download_progress_display(const boost::shared_ptr<transient_message> &message,
- const boost::shared_ptr<terminal> &term,
- const boost::shared_ptr<terminal_locale> &term_locale)
+ const boost::shared_ptr<terminal_locale> &term_locale,
+ const boost::shared_ptr<terminal_metrics> &term_metrics)
{
- return make_shared<download_progress>(message, term, term_locale);
+ return make_shared<download_progress>(message, term_locale, term_metrics);
}
}
}
diff --git a/src/cmdline/cmdline_download_progress_display.h b/src/cmdline/cmdline_download_progress_display.h
index 45e31e32..a2cd7d46 100644
--- a/src/cmdline/cmdline_download_progress_display.h
+++ b/src/cmdline/cmdline_download_progress_display.h
@@ -32,8 +32,8 @@ namespace aptitude
namespace cmdline
{
- class terminal;
class terminal_locale;
+ class terminal_metrics;
class transient_message;
/**
@@ -47,8 +47,8 @@ namespace aptitude
*/
boost::shared_ptr<views::download_progress>
create_download_progress_display(const boost::shared_ptr<transient_message> &message,
- const boost::shared_ptr<terminal> &term,
- const boost::shared_ptr<terminal_locale> &term_locale);
+ const boost::shared_ptr<terminal_locale> &term_locale,
+ const boost::shared_ptr<terminal_metrics> &term_metrics);
}
}
diff --git a/src/cmdline/cmdline_extract_cache_subset.cc b/src/cmdline/cmdline_extract_cache_subset.cc
index 4ceebca8..e13bd46b 100644
--- a/src/cmdline/cmdline_extract_cache_subset.cc
+++ b/src/cmdline/cmdline_extract_cache_subset.cc
@@ -41,10 +41,8 @@
#include <stdio.h>
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
-using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_io;
using boost::shared_ptr;
namespace aptitude
@@ -59,12 +57,11 @@ namespace aptitude
return -1;
}
- const shared_ptr<terminal> term = create_terminal();
- const shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ const shared_ptr<terminal_io> term = create_terminal();
std::string out_dir = argv[1];
- boost::shared_ptr<OpProgress> progress = make_text_progress(false, term, term_locale);
+ boost::shared_ptr<OpProgress> progress = make_text_progress(false, term, term, term);
apt_init(progress.get(), true);
if(_error->PendingError())
diff --git a/src/cmdline/cmdline_forget_new.cc b/src/cmdline/cmdline_forget_new.cc
index a7211f39..e1485f52 100644
--- a/src/cmdline/cmdline_forget_new.cc
+++ b/src/cmdline/cmdline_forget_new.cc
@@ -38,17 +38,14 @@
using namespace std;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
-using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_io;
using boost::shared_ptr;
int cmdline_forget_new(int argc, char *argv[],
const char *status_fname, bool simulate)
{
- const shared_ptr<terminal> term = create_terminal();
- const shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ const shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
@@ -60,7 +57,7 @@ int cmdline_forget_new(int argc, char *argv[],
return -1;
}
- shared_ptr<OpProgress> progress = make_text_progress(false, term, term_locale);
+ shared_ptr<OpProgress> progress = make_text_progress(false, term, term, term);
apt_init(progress.get(), false, status_fname);
diff --git a/src/cmdline/cmdline_progress.cc b/src/cmdline/cmdline_progress.cc
index 2cd4407a..c4e06f48 100644
--- a/src/cmdline/cmdline_progress.cc
+++ b/src/cmdline/cmdline_progress.cc
@@ -35,7 +35,7 @@
#include <sigc++/functors/mem_fun.h>
#include <sigc++/functors/ptr_fun.h>
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_metrics;
using boost::shared_ptr;
static void dl_complete(download_signal_log &manager,
@@ -50,15 +50,15 @@ namespace
download_signal_log &,
const sigc::slot1<void, bool> &,
unsigned int &screen_width,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
- screen_width = term->get_screen_width();
+ screen_width = term_metrics->get_screen_width();
// Note that we don't call the continuation; we assume that
// another slot invoked by the same signal will do that.
}
}
-download_signal_log *gen_cmdline_download_progress(const shared_ptr<terminal> &term)
+download_signal_log *gen_cmdline_download_progress(const shared_ptr<terminal_metrics> &term_metrics)
{
// The terminal expects a reference to a variable that will be
// updated in-place to contain the current screen width.
@@ -67,7 +67,7 @@ download_signal_log *gen_cmdline_download_progress(const shared_ptr<terminal> &t
// the terminal object directly -- will require either moving it
// into cmdline/ (preferred?) or moving the terminal into generic/.
static unsigned int screen_width;
- screen_width = term->get_screen_width();
+ screen_width = term_metrics->get_screen_width();
download_signal_log *m=new download_signal_log;
@@ -80,7 +80,7 @@ download_signal_log *gen_cmdline_download_progress(const shared_ptr<terminal> &t
m->Fail_sig.connect(sigc::mem_fun(*acqprogress, &AcqTextStatus::Fail));
m->Pulse_sig.connect(sigc::bind(sigc::ptr_fun(&do_update_screen_width),
sigc::ref(screen_width),
- term));
+ term_metrics));
m->Pulse_sig.connect(sigc::mem_fun(*acqprogress, &AcqTextStatus::Pulse));
m->Start_sig.connect(sigc::mem_fun(*acqprogress, &AcqTextStatus::Start));
m->Stop_sig.connect(sigc::mem_fun(*acqprogress, &AcqTextStatus::Stop));
diff --git a/src/cmdline/cmdline_progress.h b/src/cmdline/cmdline_progress.h
index f3050480..7af1447d 100644
--- a/src/cmdline/cmdline_progress.h
+++ b/src/cmdline/cmdline_progress.h
@@ -33,11 +33,11 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
}
}
download_signal_log *
-gen_cmdline_download_progress(const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+gen_cmdline_download_progress(const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
#endif // CMDLINE_PROGRESS_H
diff --git a/src/cmdline/cmdline_progress_display.cc b/src/cmdline/cmdline_progress_display.cc
index ba58f2d9..9de608bd 100644
--- a/src/cmdline/cmdline_progress_display.cc
+++ b/src/cmdline/cmdline_progress_display.cc
@@ -193,11 +193,12 @@ namespace aptitude
}
shared_ptr<views::progress>
- create_progress_display(const shared_ptr<terminal> &term,
- const shared_ptr<terminal_locale> &term_locale)
+ create_progress_display(const shared_ptr<terminal_locale> &term_locale,
+ const shared_ptr<terminal_metrics> &term_metrics,
+ const shared_ptr<terminal_output> &term_output)
{
const shared_ptr<transient_message> message =
- create_transient_message(term, term_locale);
+ create_transient_message(term_locale, term_metrics, term_output);
const bool old_style_percentage =
aptcfg->FindB(PACKAGE "::CmdLine::Progress::Percent-On-Right", false);
diff --git a/src/cmdline/cmdline_progress_display.h b/src/cmdline/cmdline_progress_display.h
index 9ab4150a..5dc3aa5d 100644
--- a/src/cmdline/cmdline_progress_display.h
+++ b/src/cmdline/cmdline_progress_display.h
@@ -32,8 +32,9 @@ namespace aptitude
namespace cmdline
{
- class terminal;
class terminal_locale;
+ class terminal_metrics;
+ class terminal_output;
class transient_message;
/** \brief Create a blank progress display.
@@ -58,8 +59,9 @@ namespace aptitude
* transient message with the given terminal objects.
*/
boost::shared_ptr<views::progress>
- create_progress_display(const boost::shared_ptr<terminal> &term,
- const boost::shared_ptr<terminal_locale> &term_locale);
+ create_progress_display(const boost::shared_ptr<terminal_locale> &term_locale,
+ const boost::shared_ptr<terminal_metrics> &term_metrics,
+ const boost::shared_ptr<terminal_output> &term_output);
}
}
diff --git a/src/cmdline/cmdline_prompt.cc b/src/cmdline/cmdline_prompt.cc
index 8076f646..2e888ab6 100644
--- a/src/cmdline/cmdline_prompt.cc
+++ b/src/cmdline/cmdline_prompt.cc
@@ -59,7 +59,7 @@
using namespace std;
namespace cw = cwidget;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_metrics;
using aptitude::why::make_cmdline_why_callbacks;
using aptitude::why::why_callbacks;
using boost::shared_ptr;
@@ -152,7 +152,7 @@ namespace
std::string roots_string(const pkgCache::PkgIterator &pkg,
int verbose,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
using namespace aptitude::matching;
using cw::util::ref_ptr;
@@ -187,7 +187,7 @@ namespace
true));
const boost::shared_ptr<why_callbacks> callbacks =
- make_cmdline_why_callbacks(verbose, term);
+ make_cmdline_why_callbacks(verbose, term_metrics);
for(std::vector<search_params>::const_iterator it = params.begin();
it != params.end(); ++it)
{
@@ -258,7 +258,7 @@ static void cmdline_show_instinfo(pkgvector &items,
bool showsize,
bool showpurge,
bool showwhy,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
sort(items.begin(), items.end(), pkg_byname_compare);
strvector output;
@@ -372,7 +372,7 @@ static void cmdline_show_instinfo(pkgvector &items,
if(showwhy)
{
- std::string whystring(roots_string(*i, verbose, term));
+ std::string whystring(roots_string(*i, verbose, term_metrics));
if(!whystring.empty())
{
s += " ";
@@ -386,7 +386,7 @@ static void cmdline_show_instinfo(pkgvector &items,
output.push_back(s);
}
- cmdline_show_stringlist(output, term);
+ cmdline_show_stringlist(output, term_metrics);
}
// Note that not all of these are actually used, but I'm preserving
@@ -434,7 +434,7 @@ string prompt_string(const string &prompt)
* fat warning message about them. Returns false if the user doesn't
* want to continue.
*/
-static bool prompt_essential(const shared_ptr<terminal> &term)
+static bool prompt_essential(const shared_ptr<terminal_metrics> &term_metrics)
{
pkgvector todelete, whatsbroken;
bool ok=true;
@@ -459,7 +459,7 @@ static bool prompt_essential(const shared_ptr<terminal> &term)
ok=false;
printf(_("The following ESSENTIAL packages will be REMOVED!\n"));
- cmdline_show_pkglist(todelete, term);
+ cmdline_show_pkglist(todelete, term_metrics);
printf("\n");
}
@@ -503,7 +503,7 @@ static bool prompt_essential(const shared_ptr<terminal> &term)
*
* \return true if everything is OK or the user overrode the warning.
*/
-static bool prompt_trust(const shared_ptr<terminal> &term)
+static bool prompt_trust(const shared_ptr<terminal_metrics> &term_metrics)
{
pkgvector untrusted;
@@ -530,7 +530,7 @@ static bool prompt_trust(const shared_ptr<terminal> &term)
"You should only proceed with the installation if you are certain that\n"
"this is what you want to do.\n\n"));
- cmdline_show_pkglist(untrusted, term);
+ cmdline_show_pkglist(untrusted, term_metrics);
printf("\n");
@@ -614,7 +614,7 @@ bool cmdline_show_preview(bool as_upgrade, pkgset &to_install,
bool showvers, bool showdeps,
bool showsize, bool showwhy,
int verbose,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
const int quiet = aptcfg->FindI("Quiet", 0);
@@ -700,20 +700,20 @@ bool cmdline_show_preview(bool as_upgrade, pkgset &to_install,
i == pkg_auto_remove ||
i == pkg_unused_remove,
showwhy,
- term);
+ term_metrics);
}
}
if(quiet == 0 && !recommended.empty())
{
printf(_("The following packages are RECOMMENDED but will NOT be installed:\n"));
- cmdline_show_instinfo(recommended, verbose, showvers, showdeps, showsize, false, showwhy, term);
+ cmdline_show_instinfo(recommended, verbose, showvers, showdeps, showsize, false, showwhy, term_metrics);
}
if(verbose>0 && !suggested.empty())
{
printf(_("The following packages are SUGGESTED but will NOT be installed:\n"));
- cmdline_show_instinfo(suggested, verbose, showvers, showdeps, showsize, false, showwhy, term);
+ cmdline_show_instinfo(suggested, verbose, showvers, showdeps, showsize, false, showwhy, term_metrics);
}
if((*apt_cache_file)->DelCount() == 0 &&
@@ -763,7 +763,7 @@ bool cmdline_show_preview(bool as_upgrade, pkgset &to_install,
static void cmdline_parse_show(string response,
int verbose,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
// assume response[0]=='i'
std::vector<std::string> packages;
@@ -774,13 +774,13 @@ static void cmdline_parse_show(string response,
else
for(std::vector<std::string>::const_iterator it = packages.begin();
it != packages.end(); ++it)
- do_cmdline_show(*it, verbose, term);
+ do_cmdline_show(*it, verbose, term_metrics);
prompt_string(_("Press Return to continue."));
}
// Erm. Merge w/ above?
-static void cmdline_parse_changelog(string response, const shared_ptr<terminal> &term)
+static void cmdline_parse_changelog(string response, const shared_ptr<terminal_metrics> &term_metrics)
{
vector<string> packages;
// assume response[0]=='c'
@@ -789,13 +789,13 @@ static void cmdline_parse_changelog(string response, const shared_ptr<terminal>
if(packages.empty())
printf(_("No packages found -- enter the package names on the line after 'c'.\n"));
else
- do_cmdline_changelog(packages, term);
+ do_cmdline_changelog(packages, term_metrics);
prompt_string(_("Press Return to continue"));
}
static void cmdline_parse_why(string response,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
vector<string> arguments;
// assume response[0]=='w'
@@ -809,7 +809,7 @@ static void cmdline_parse_why(string response,
string root = arguments.back();
arguments.pop_back();
const shared_ptr<why_callbacks> callbacks =
- make_cmdline_why_callbacks(0, term);
+ make_cmdline_why_callbacks(0, term_metrics);
std::auto_ptr<cw::fragment> frag(do_why(arguments, root,
aptitude::why::no_summary,
false, false,
@@ -817,7 +817,7 @@ static void cmdline_parse_why(string response,
success));
if(frag.get() != NULL)
{
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
std::cout << frag->layout(screen_width, screen_width, cwidget::style());
}
_error->DumpErrors();
@@ -831,7 +831,7 @@ static inline cw::fragment *flowindentbox(int i1, int irest, cw::fragment *f)
static void prompt_help(ostream &out,
bool show_resolver_key,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
std::vector<cw::fragment *> fragments;
@@ -918,7 +918,7 @@ static void prompt_help(ostream &out,
cw::fragment *f = indentbox(2, 2, cw::sequence_fragment(fragments));
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
out << _("Commands:") << endl;
out << f->layout(screen_width, screen_width, cwidget::style());
delete f;
@@ -939,7 +939,7 @@ bool cmdline_do_prompt(bool as_upgrade,
bool force_no_change,
pkgPolicy &policy,
bool arch_only,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
bool exit=false;
bool rval=true;
@@ -960,7 +960,7 @@ bool cmdline_do_prompt(bool as_upgrade,
// ahead, we can break out immediately.
if(!cmdline_show_preview(true, to_install, to_hold, to_remove,
showvers, showdeps, showsize, showwhy, verbose,
- term) &&
+ term_metrics) &&
first &&
!always_prompt &&
(*apt_cache_file)->BrokenCount()==0)
@@ -978,7 +978,7 @@ bool cmdline_do_prompt(bool as_upgrade,
verbose,
policy,
arch_only,
- term))
+ term_metrics))
{
case aptitude::cmdline::resolver_success:
break;
@@ -998,7 +998,7 @@ bool cmdline_do_prompt(bool as_upgrade,
// changes the resolver made.
cmdline_show_preview(true, to_install, to_hold, to_remove,
showvers, showdeps, showsize, showwhy,
- verbose, term);
+ verbose, term_metrics);
if((*apt_cache_file)->DelCount() == 0 &&
(*apt_cache_file)->InstCount() == 0)
@@ -1036,7 +1036,7 @@ bool cmdline_do_prompt(bool as_upgrade,
if(first)
{
const std::string msg = _("aptitude failed to find a solution to these dependencies. You can solve them yourself by hand or type 'n' to quit.");
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cw::fragment *f = cw::text_fragment(msg);
cout << f->layout(screen_width,
screen_width,
@@ -1080,7 +1080,7 @@ bool cmdline_do_prompt(bool as_upgrade,
if(have_broken)
{
cw::fragment *f = flowbox(cw::text_fragment(_("Enter a package management command (such as '+ package' to install a package), 'R' to attempt automatic dependency resolution or 'N' to abort.")));
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cout << f->layout(screen_width,
screen_width,
cwidget::style());
@@ -1131,13 +1131,13 @@ bool cmdline_do_prompt(bool as_upgrade,
printf(_("\nSize changes will not be shown.\n\n"));
break;
case 'I':
- cmdline_parse_show(response, verbose, term);
+ cmdline_parse_show(response, verbose, term_metrics);
break;
case 'C':
- cmdline_parse_changelog(response, term);
+ cmdline_parse_changelog(response, term_metrics);
break;
case 'W': // should be 'Y' but that's for "yes"
- cmdline_parse_why(response, term);
+ cmdline_parse_why(response, term_metrics);
break;
case '+':
case '-':
@@ -1154,14 +1154,14 @@ bool cmdline_do_prompt(bool as_upgrade,
to_install, to_hold,
to_remove, to_purge, verbose,
policy, arch_only, true,
- term);
+ term_metrics);
}
break;
case 'E':
ui_preview();
case '?':
valid_response=false;
- prompt_help(cout, have_broken, term);
+ prompt_help(cout, have_broken, term_metrics);
break;
default:
printf("%s", unknown_key_message.c_str());
@@ -1172,7 +1172,7 @@ bool cmdline_do_prompt(bool as_upgrade,
}
// Note: only show the prompt if we're planning to continue.
- if(rval && (!prompt_essential(term) || !prompt_trust(term)))
+ if(rval && (!prompt_essential(term_metrics) || !prompt_trust(term_metrics)))
{
rval=false;
exit=true;
diff --git a/src/cmdline/cmdline_prompt.h b/src/cmdline/cmdline_prompt.h
index b9c2683e..96f9a186 100644
--- a/src/cmdline/cmdline_prompt.h
+++ b/src/cmdline/cmdline_prompt.h
@@ -82,14 +82,14 @@ bool cmdline_do_prompt(bool as_upgrade,
bool force_no_change,
pkgPolicy &policy,
bool arch_only,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
bool cmdline_show_preview(bool as_upgrade, pkgset &to_install,
pkgset &to_hold, pkgset &to_remove,
bool showvers, bool showdeps,
bool showsize, bool showwhy,
int verbose,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
/** Prompt for a single line of input from the user.
*
diff --git a/src/cmdline/cmdline_resolver.cc b/src/cmdline/cmdline_resolver.cc
index da2c2f40..f17f73aa 100644
--- a/src/cmdline/cmdline_resolver.cc
+++ b/src/cmdline/cmdline_resolver.cc
@@ -62,7 +62,7 @@
using namespace std;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_metrics;
using boost::shared_ptr;
typedef generic_solution<aptitude_universe> aptitude_solution;
@@ -216,7 +216,7 @@ static inline cw::fragment *flowindentbox(int i1, int irest, cw::fragment *f)
}
static void resolver_help(ostream &out,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
cw::fragment *f=indentbox(2, 2,
cw::fragf(_("y: %F"
@@ -282,7 +282,7 @@ static void resolver_help(ostream &out,
flowindentbox(0, 3,
cw::fragf(_("Adjustments will cause the current solution to be discarded and recalculated as necessary.")))));
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
out << f->layout(screen_width, screen_width, cwidget::style());
delete f;
}
@@ -527,7 +527,7 @@ static void reject_or_mandate_version(const string &s,
void cmdline_resolver_show_choice(const choice &c,
const std::string &tag,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
cw::fragment *info_fragment = NULL;
bool is_rejected = false;
@@ -616,7 +616,7 @@ void cmdline_resolver_show_choice(const choice &c,
// aren't translated.
: cw::fragf(_("Enter \"a %s\" to require that new solutions include this action if possible."), tag.c_str()))));
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cwidget::fragment_contents lines = f->layout(screen_width, screen_width, cwidget::style());
delete f;
@@ -806,7 +806,7 @@ static aptitude_solution wait_for_solution(cwidget::threads::box<cmdline_resolve
}
aptitude_solution calculate_current_solution(bool suppress_message,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
const int step_limit = aptcfg->FindI(PACKAGE "::ProblemResolver::StepLimit", 5000);
if(step_limit <= 0)
@@ -831,7 +831,7 @@ aptitude_solution calculate_current_solution(bool suppress_message,
return resman->get_solution(resman->get_selected_solution(), 0);
- cmdline_spinner spin(aptcfg->FindI("Quiet", 0), term);
+ cmdline_spinner spin(aptcfg->FindI("Quiet", 0), term_metrics);
if(!suppress_message)
std::cout << _("Resolving dependencies...") << std::endl;
@@ -856,7 +856,7 @@ cmdline_resolve_deps(pkgset &to_install,
int verbose,
pkgPolicy &policy,
bool arch_only,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
bool story_is_default = aptcfg->FindB(PACKAGE "::CmdLine::Resolver-Show-Steps", false);
@@ -884,7 +884,7 @@ cmdline_resolve_deps(pkgset &to_install,
{
try
{
- aptitude_solution sol = calculate_current_solution(true, term);
+ aptitude_solution sol = calculate_current_solution(true, term_metrics);
if(_error->PendingError())
_error->DumpErrors();
@@ -901,7 +901,7 @@ cmdline_resolve_deps(pkgset &to_install,
: solution_fragment_with_ids(sol, ids),
NULL);
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cwidget::fragment_contents lines=f->layout(screen_width, screen_width, cwidget::style());
delete f;
@@ -926,7 +926,7 @@ cmdline_resolve_deps(pkgset &to_install,
switch(toupper(response[loc]))
{
case 'Y':
- (*apt_cache_file)->apply_solution(calculate_current_solution(true, term), NULL);
+ (*apt_cache_file)->apply_solution(calculate_current_solution(true, term_metrics), NULL);
modified_pkgs=true;
break;
case 'N':
@@ -951,7 +951,7 @@ cmdline_resolve_deps(pkgset &to_install,
cw::fragment *f = story_is_default
? solution_story(sol, &ids)
: solution_fragment_with_ids(sol, ids);
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cout << f->layout(screen_width, screen_width,
cwidget::style()) << endl;
delete f;
@@ -976,7 +976,7 @@ cmdline_resolve_deps(pkgset &to_install,
break;
case '?':
cout << _("The following commands are available:") << endl;
- resolver_help(cout, term);
+ resolver_help(cout, term_metrics);
break;
case '+':
case '-':
@@ -989,7 +989,7 @@ cmdline_resolve_deps(pkgset &to_install,
to_install, to_hold,
to_remove, to_purge, verbose,
policy, arch_only, false,
- term);
+ term_metrics);
modified_pkgs=true;
}
break;
@@ -1029,12 +1029,12 @@ cmdline_resolve_deps(pkgset &to_install,
if(found == ids.end())
{
cout << _("Invalid response; please enter one of the following commands:") << endl;
- resolver_help(cout, term);
+ resolver_help(cout, term_metrics);
}
else
{
const choice &c = found->second;
- cmdline_resolver_show_choice(c, first_word, term);
+ cmdline_resolver_show_choice(c, first_word, term_metrics);
}
}
break;
@@ -1064,7 +1064,7 @@ cmdline_resolve_deps(pkgset &to_install,
case 'Y':
try
{
- calculate_current_solution(false, term);
+ calculate_current_solution(false, term_metrics);
done=true;
}
catch(NoMoreTime)
@@ -1140,7 +1140,7 @@ namespace aptitude
{
// Implements the --show-resolver-actions command-line parameters.
void show_resolver_actions(const generic_solution<aptitude_universe> &solution,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
if(solution.get_choices().size() > 0)
{
@@ -1148,7 +1148,7 @@ namespace aptitude
// separate the solution from this message..
std::cout << std::endl;
std::auto_ptr<cw::fragment> story(solution_story(solution, NULL));
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
std::cout << story->layout(screen_width, screen_width, cwidget::style());
}
}
@@ -1159,7 +1159,7 @@ namespace aptitude
bool no_new_installs,
bool no_new_upgrades,
bool show_story,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
if(!resman->resolver_exists())
return true;
@@ -1174,14 +1174,14 @@ namespace aptitude
boost::make_shared<cmdline_resolver_continuation>(boost::ref(retbox)),
cmdline_resolver_trampoline);
- cmdline_spinner spin(aptcfg->FindI("Quiet", 0), term);
+ cmdline_spinner spin(aptcfg->FindI("Quiet", 0), term_metrics);
// TODO: maybe we should say "calculating upgrade" if we're
// running safe-upgrade?
std::cout << _("Resolving dependencies...") << std::endl;
generic_solution<aptitude_universe> sol = wait_for_solution(retbox, spin);
if(show_story)
- show_resolver_actions(sol, term);
+ show_resolver_actions(sol, term_metrics);
(*apt_cache_file)->apply_solution(sol, NULL);
}
diff --git a/src/cmdline/cmdline_resolver.h b/src/cmdline/cmdline_resolver.h
index 2ffaad46..b664024e 100644
--- a/src/cmdline/cmdline_resolver.h
+++ b/src/cmdline/cmdline_resolver.h
@@ -41,7 +41,7 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
/** \brief Represents the termination state of the
* command-line resolver.
@@ -92,7 +92,7 @@ namespace aptitude
*/
generic_solution<aptitude_universe> calculate_current_solution(bool print_resolving_dependencies,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
/** \brief Write the resolver state to a file as appropriate.
*
@@ -138,7 +138,7 @@ cmdline_resolve_deps(pkgset &to_install,
int verbose,
pkgPolicy &policy,
bool arch_only,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
namespace aptitude
{
@@ -164,7 +164,7 @@ namespace aptitude
bool no_new_installs,
bool no_new_upgrades,
bool show_story,
- const boost::shared_ptr<terminal> &term);
+ const boost::shared_ptr<terminal_metrics> &term_metrics);
}
}
diff --git a/src/cmdline/cmdline_search.cc b/src/cmdline/cmdline_search.cc
index 49349340..6e811db9 100644
--- a/src/cmdline/cmdline_search.cc
+++ b/src/cmdline/cmdline_search.cc
@@ -65,10 +65,11 @@ namespace cw = cwidget;
using aptitude::Loggers;
using aptitude::cmdline::create_search_progress;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_io;
using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_metrics;
+using aptitude::cmdline::terminal_output;
using aptitude::matching::serialize_pattern;
using aptitude::util::create_throttle;
using aptitude::util::progress_info;
@@ -93,14 +94,15 @@ namespace
const unsigned int screen_width,
bool disable_columns,
bool debug,
- const shared_ptr<terminal> &term,
- const shared_ptr<terminal_locale> &term_locale)
+ const shared_ptr<terminal_locale> &term_locale,
+ const shared_ptr<terminal_metrics> &term_metrics,
+ const shared_ptr<terminal_output> &term_output)
{
typedef std::vector<std::pair<pkgCache::PkgIterator, ref_ptr<structural_match> > >
results_list;
const shared_ptr<progress> search_progress_display =
- create_progress_display(term, term_locale);
+ create_progress_display(term_locale, term_metrics, term_output);
const shared_ptr<throttle> search_progress_throttle =
create_throttle();
@@ -164,8 +166,7 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
string display_format, string width, string sort,
bool disable_columns, bool debug)
{
- shared_ptr<terminal> term = create_terminal();
- shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ shared_ptr<terminal_io> term = create_terminal();
int real_width=-1;
@@ -216,7 +217,7 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
}
shared_ptr<OpProgress> progress =
- make_text_progress(true, term, term_locale);
+ make_text_progress(true, term, term, term);
apt_init(progress.get(), true, status_fname);
@@ -251,5 +252,6 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
disable_columns,
debug,
term,
- term_locale);
+ term,
+ term);
}
diff --git a/src/cmdline/cmdline_show.cc b/src/cmdline/cmdline_show.cc
index e523821d..29c5591a 100644
--- a/src/cmdline/cmdline_show.cc
+++ b/src/cmdline/cmdline_show.cc
@@ -52,10 +52,9 @@
namespace cw = cwidget;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
-using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_io;
+using aptitude::cmdline::terminal_metrics;
using boost::shared_ptr;
using cwidget::fragf;
using cwidget::fragment;
@@ -371,7 +370,7 @@ static cwidget::fragment *state_fragment(pkgCache::PkgIterator pkg, pkgCache::Ve
/** \brief Shows information about a package. */
static void show_package(pkgCache::PkgIterator pkg, int verbose,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
vector<cw::fragment *> fragments;
@@ -381,7 +380,7 @@ static void show_package(pkgCache::PkgIterator pkg, int verbose,
cw::fragment *f=cw::sequence_fragment(fragments);
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cout << f->layout(screen_width, screen_width, cwidget::style());
delete f;
@@ -485,13 +484,13 @@ cw::fragment *version_file_fragment(const pkgCache::VerIterator &ver,
}
static void show_version(pkgCache::VerIterator ver, int verbose,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
if(ver.FileList().end())
{
cw::fragment *f=version_file_fragment(ver, ver.FileList(), verbose);
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cout << f->layout(screen_width, screen_width, cwidget::style());
delete f;
@@ -502,7 +501,7 @@ static void show_version(pkgCache::VerIterator ver, int verbose,
{
cw::fragment *f=version_file_fragment(ver, vf, verbose);
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
cout << f->layout(screen_width, screen_width, cwidget::style()) << endl;
delete f;
@@ -520,7 +519,7 @@ bool do_cmdline_show_target(const pkgCache::PkgIterator &pkg,
const string &sourcestr,
int verbose,
bool has_explicit_source,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
if(verbose == 0 || has_explicit_source)
{
@@ -534,20 +533,20 @@ bool do_cmdline_show_target(const pkgCache::PkgIterator &pkg,
ver = pkg.VersionList();
if(!ver.end())
- show_version(ver, verbose, term);
+ show_version(ver, verbose, term_metrics);
else
- show_package(pkg, verbose, term);
+ show_package(pkg, verbose, term_metrics);
}
else if(!pkg.VersionList().end())
for(pkgCache::VerIterator ver=pkg.VersionList(); !ver.end(); ++ver)
- show_version(ver, verbose, term);
+ show_version(ver, verbose, term_metrics);
else
- show_package(pkg, verbose, term);
+ show_package(pkg, verbose, term_metrics);
return true;
}
-bool do_cmdline_show(string s, int verbose, const shared_ptr<terminal> &term)
+bool do_cmdline_show(string s, int verbose, const shared_ptr<terminal_metrics> &term_metrics)
{
cmdline_version_source source;
string name, sourcestr;
@@ -585,7 +584,7 @@ bool do_cmdline_show(string s, int verbose, const shared_ptr<terminal> &term)
sourcestr,
verbose,
has_explicit_source,
- term);
+ term_metrics);
else if(is_pattern)
{
using namespace aptitude::matching;
@@ -614,7 +613,7 @@ bool do_cmdline_show(string s, int verbose, const shared_ptr<terminal> &term)
sourcestr,
verbose,
has_explicit_source,
- term))
+ term_metrics))
return false;
}
}
@@ -627,12 +626,11 @@ bool do_cmdline_show(string s, int verbose, const shared_ptr<terminal> &term)
int cmdline_show(int argc, char *argv[], int verbose)
{
- shared_ptr<terminal> term = create_terminal();
- shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
- shared_ptr<OpProgress> progress = make_text_progress(true, term, term_locale);
+ shared_ptr<OpProgress> progress = make_text_progress(true, term, term, term);
apt_init(progress.get(), false);
if(_error->PendingError())
diff --git a/src/cmdline/cmdline_show.h b/src/cmdline/cmdline_show.h
index 5498d1b6..ebc33f82 100644
--- a/src/cmdline/cmdline_show.h
+++ b/src/cmdline/cmdline_show.h
@@ -41,7 +41,7 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
}
}
@@ -58,7 +58,7 @@ cwidget::fragment *version_file_fragment(const pkgCache::VerIterator &ver,
/** Run the "show" operation on a single argument, presented as a string. */
bool do_cmdline_show(std::string s, int verbose,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
/** The "show" user command. */
int cmdline_show(int argc, char *argv[], int verbose);
diff --git a/src/cmdline/cmdline_simulate.cc b/src/cmdline/cmdline_simulate.cc
index 97a8e835..a50d20c1 100644
--- a/src/cmdline/cmdline_simulate.cc
+++ b/src/cmdline/cmdline_simulate.cc
@@ -36,7 +36,7 @@
#include <stdio.h>
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_metrics;
using boost::shared_ptr;
int cmdline_simulate(bool as_upgrade,
@@ -47,7 +47,7 @@ int cmdline_simulate(bool as_upgrade,
bool always_prompt, int verbose,
bool assume_yes, bool force_no_change,
pkgPolicy &policy, bool arch_only,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
if(!cmdline_do_prompt(as_upgrade,
to_install, to_hold, to_remove, to_purge,
@@ -55,7 +55,7 @@ int cmdline_simulate(bool as_upgrade,
always_prompt, verbose,
assume_yes, force_no_change,
policy, arch_only,
- term))
+ term_metrics))
{
printf(_("Abort.\n"));
return 0;
diff --git a/src/cmdline/cmdline_simulate.h b/src/cmdline/cmdline_simulate.h
index 93f88718..4f90600c 100644
--- a/src/cmdline/cmdline_simulate.h
+++ b/src/cmdline/cmdline_simulate.h
@@ -36,7 +36,7 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
}
}
@@ -73,7 +73,7 @@ int cmdline_simulate(bool as_upgrade,
bool always_prompt, int verbose,
bool assume_yes, bool force_no_change,
pkgPolicy &policy, bool arch_only,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
#endif // CMDLINE_SIMULATE_H
diff --git a/src/cmdline/cmdline_spinner.cc b/src/cmdline/cmdline_spinner.cc
index 28b2940e..c8cc1586 100644
--- a/src/cmdline/cmdline_spinner.cc
+++ b/src/cmdline/cmdline_spinner.cc
@@ -27,14 +27,14 @@
// System includes:
#include <iostream>
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_metrics;
using boost::shared_ptr;
cmdline_spinner::cmdline_spinner(int _quiet_level,
- const shared_ptr<terminal> &_term)
+ const shared_ptr<terminal_metrics> &_term_metrics)
: count(0),
quiet_level(_quiet_level),
- term(_term)
+ term_metrics(_term_metrics)
{
}
@@ -60,7 +60,7 @@ void cmdline_spinner::display() const
if(quiet_level > 0)
return;
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
// Build the string to output.
std::string out(msg, 0, screen_width - 2);
diff --git a/src/cmdline/cmdline_spinner.h b/src/cmdline/cmdline_spinner.h
index 4cb3f085..2408b4a3 100644
--- a/src/cmdline/cmdline_spinner.h
+++ b/src/cmdline/cmdline_spinner.h
@@ -34,7 +34,7 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
}
}
@@ -49,11 +49,11 @@ class cmdline_spinner
/** The quietness of this spinner. */
int quiet_level;
- boost::shared_ptr<aptitude::cmdline::terminal> term;
+ boost::shared_ptr<aptitude::cmdline::terminal_metrics> term_metrics;
public:
cmdline_spinner(int _quiet_level,
- const boost::shared_ptr<aptitude::cmdline::terminal> &_term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &_term_metrics);
/** Display the current spinner state, overwriting the current
* terminal line.
diff --git a/src/cmdline/cmdline_update.cc b/src/cmdline/cmdline_update.cc
index 641aa230..9e82c894 100644
--- a/src/cmdline/cmdline_update.cc
+++ b/src/cmdline/cmdline_update.cc
@@ -36,9 +36,7 @@
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
-using aptitude::cmdline::terminal;
-using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_io;
using boost::shared_ptr;
void print_autoclean_msg()
@@ -48,8 +46,7 @@ void print_autoclean_msg()
int cmdline_update(int argc, char *argv[], int verbose)
{
- shared_ptr<terminal> term = create_terminal();
- shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
@@ -67,7 +64,7 @@ int cmdline_update(int argc, char *argv[], int verbose)
download_update_manager m;
m.pre_autoclean_hook.connect(sigc::ptr_fun(print_autoclean_msg));
int rval =
- (cmdline_do_download(&m, verbose, term, term_locale)
+ (cmdline_do_download(&m, verbose, term, term, term)
== download_manager::success ? 0 : -1);
if(_error->PendingError())
diff --git a/src/cmdline/cmdline_user_tag.cc b/src/cmdline/cmdline_user_tag.cc
index 01c5acb5..ba7a5810 100644
--- a/src/cmdline/cmdline_user_tag.cc
+++ b/src/cmdline/cmdline_user_tag.cc
@@ -39,10 +39,8 @@
#include <string.h>
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
-using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_io;
using boost::shared_ptr;
namespace aptitude
@@ -84,8 +82,7 @@ namespace aptitude
int cmdline_user_tag(int argc, char *argv[], int quiet, int verbose)
{
- const shared_ptr<terminal> term = create_terminal();
- const shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ const shared_ptr<terminal_io> term = create_terminal();
user_tag_action action = (user_tag_action)-1;
@@ -164,7 +161,7 @@ namespace aptitude
}
}
- shared_ptr<OpProgress> text_progress = make_text_progress(false, term, term_locale);
+ shared_ptr<OpProgress> text_progress = make_text_progress(false, term, term, term);
if(!(*apt_cache_file)->save_selection_list(*text_progress))
return 1;
diff --git a/src/cmdline/cmdline_util.cc b/src/cmdline/cmdline_util.cc
index 82fd3d3c..1bc8317a 100644
--- a/src/cmdline/cmdline_util.cc
+++ b/src/cmdline/cmdline_util.cc
@@ -60,8 +60,9 @@
namespace cw = cwidget;
using aptitude::cmdline::make_text_progress;
-using aptitude::cmdline::terminal;
using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_metrics;
+using aptitude::cmdline::terminal_output;
using boost::shared_ptr;
namespace
@@ -109,9 +110,9 @@ void ui_solution_screen()
}
void cmdline_show_stringlist(strvector &items,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
int loc=2;
@@ -133,14 +134,14 @@ void cmdline_show_stringlist(strvector &items,
}
void cmdline_show_pkglist(pkgvector &items,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
strvector tmp;
for(pkgvector::iterator i=items.begin(); i!=items.end(); ++i)
tmp.push_back(i->Name());
- cmdline_show_stringlist(tmp, term);
+ cmdline_show_stringlist(tmp, term_metrics);
}
pkgCache::VerIterator cmdline_find_ver(pkgCache::PkgIterator pkg,
@@ -319,7 +320,7 @@ namespace
void show_stats_change(stats initial, stats final,
bool show_all,
bool show_unchanged,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
using cw::fragf;
using cw::util::ssprintf;
@@ -404,7 +405,7 @@ namespace
{
cw::fragment *f = join_fragments(output_fragments, L"\n");
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
std::cout << f->layout(screen_width, screen_width, cw::style());
delete f;
}
@@ -422,11 +423,12 @@ namespace
download_manager::result cmdline_do_download(download_manager *m,
int verbose,
- const shared_ptr<terminal> &term,
- const shared_ptr<terminal_locale> &term_locale)
+ const shared_ptr<terminal_locale> &term_locale,
+ const shared_ptr<terminal_metrics> &term_metrics,
+ const shared_ptr<terminal_output> &term_output)
{
stats initial_stats(0, 0, 0, std::set<std::string>());
- shared_ptr<OpProgress> progress = make_text_progress(false, term, term_locale);
+ shared_ptr<OpProgress> progress = make_text_progress(false, term_locale, term_metrics, term_output);
if(aptcfg->FindI("Quiet", 0) == 0)
{
@@ -440,7 +442,7 @@ download_manager::result cmdline_do_download(download_manager *m,
initial_stats = compute_apt_stats();
}
- std::auto_ptr<download_signal_log> log(gen_cmdline_download_progress(term));
+ std::auto_ptr<download_signal_log> log(gen_cmdline_download_progress(term_metrics));
// Dump errors here because prepare() might check for pending errors
// and think something failed.
@@ -468,7 +470,7 @@ download_manager::result cmdline_do_download(download_manager *m,
final_stats = compute_apt_stats();
show_stats_change(initial_stats, final_stats,
verbose >= 1, verbose >= 2,
- term);
+ term_metrics);
}
return finish_res;
diff --git a/src/cmdline/cmdline_util.h b/src/cmdline/cmdline_util.h
index b09cd38c..89cf1963 100644
--- a/src/cmdline/cmdline_util.h
+++ b/src/cmdline/cmdline_util.h
@@ -49,15 +49,16 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
class terminal_locale;
+ class terminal_metrics;
+ class terminal_output;
}
}
void cmdline_show_pkglist(pkgvector &items,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
void cmdline_show_stringlist(strvector &items,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term);
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics);
/** Finds a candidate version for the package using the given source.
*/
@@ -99,8 +100,8 @@ bool cmdline_parse_source(const string &input,
* \param m the download process to run.
* \param verbose the verbosity level; controls how many
* stats are printed when the run completes.
- * \param term the terminal object to use for printing
- * the download progress.
+ * \param term_metrics the object from which to read the terminal
+ * dimensions.
* \param term_locale the locale used for output to the terminal.
*
* \return the success status of the post-download commands, or
@@ -108,8 +109,9 @@ bool cmdline_parse_source(const string &input,
*/
download_manager::result cmdline_do_download(download_manager *m,
int verbose,
- const boost::shared_ptr<aptitude::cmdline::terminal> &term,
- const boost::shared_ptr<aptitude::cmdline::terminal_locale> &term_locale);
+ const boost::shared_ptr<aptitude::cmdline::terminal_locale> &term_locale,
+ const boost::shared_ptr<aptitude::cmdline::terminal_metrics> &term_metrics,
+ const boost::shared_ptr<aptitude::cmdline::terminal_output> &term_output);
namespace aptitude
{
diff --git a/src/cmdline/cmdline_versions.cc b/src/cmdline/cmdline_versions.cc
index 46351328..cb6ddfc5 100644
--- a/src/cmdline/cmdline_versions.cc
+++ b/src/cmdline/cmdline_versions.cc
@@ -59,12 +59,13 @@ namespace m = aptitude::matching;
using aptitude::cmdline::create_progress_display;
using aptitude::cmdline::create_search_progress;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::create_terminal_locale;
using aptitude::cmdline::lessthan_1st;
using aptitude::cmdline::package_results_lt;
using aptitude::cmdline::search_result_column_parameters;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_io;
using aptitude::cmdline::terminal_locale;
+using aptitude::cmdline::terminal_metrics;
+using aptitude::cmdline::terminal_output;
using aptitude::cmdline::version_results_eq;
using aptitude::cmdline::version_results_lt;
using aptitude::matching::serialize_pattern;
@@ -246,8 +247,9 @@ namespace
group_by_option group_by,
show_package_names_option show_package_names,
bool debug,
- const shared_ptr<terminal> &term,
- const shared_ptr<terminal_locale> &term_locale)
+ const shared_ptr<terminal_locale> &term_locale,
+ const shared_ptr<terminal_metrics> &term_metrics,
+ const shared_ptr<terminal_output> &term_output)
{
// Set to -1 if any exact-name matches fail. Also set to -1 if
// there are no results at all.
@@ -257,7 +259,7 @@ namespace
results_list;
const shared_ptr<progress> search_progress_display =
- create_progress_display(term, term_locale);
+ create_progress_display(term_locale, term_metrics, term_output);
const shared_ptr<throttle> search_progress_throttle =
create_throttle();
@@ -525,8 +527,7 @@ int cmdline_versions(int argc, char *argv[], const char *status_fname,
group_by_option group_by,
show_package_names_option show_package_names)
{
- shared_ptr<terminal> term = create_terminal();
- shared_ptr<terminal_locale> term_locale = create_terminal_locale();
+ shared_ptr<terminal_io> term = create_terminal();
int real_width=-1;
@@ -620,5 +621,6 @@ int cmdline_versions(int argc, char *argv[], const char *status_fname,
show_package_names,
debug,
term,
- term_locale);
+ term,
+ term);
}
diff --git a/src/cmdline/cmdline_why.cc b/src/cmdline/cmdline_why.cc
index 377e586c..d03fda8c 100644
--- a/src/cmdline/cmdline_why.cc
+++ b/src/cmdline/cmdline_why.cc
@@ -60,7 +60,8 @@
namespace cw = cwidget;
using aptitude::cmdline::create_terminal;
-using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_io;
+using aptitude::cmdline::terminal_metrics;
using aptitude::why::make_cmdline_why_callbacks;
using aptitude::why::why_callbacks;
using boost::make_shared;
@@ -1104,16 +1105,16 @@ namespace aptitude
{
class cmdline_why_callbacks : public why_callbacks
{
- const shared_ptr<terminal> term;
+ const shared_ptr<terminal_metrics> term_metrics;
const int verbosity;
const unsigned int screen_width;
public:
- cmdline_why_callbacks(const shared_ptr<terminal> &_term,
+ cmdline_why_callbacks(const shared_ptr<terminal_metrics> &_term_metrics,
const int _verbosity)
- : term(_term),
+ : term_metrics(_term_metrics),
verbosity(_verbosity),
- screen_width(_term->get_screen_width())
+ screen_width(_term_metrics->get_screen_width())
{
}
@@ -1208,9 +1209,9 @@ namespace aptitude
shared_ptr<why_callbacks>
make_cmdline_why_callbacks(const int verbosity,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
- return make_shared<cmdline_why_callbacks>(term, verbosity);
+ return make_shared<cmdline_why_callbacks>(term_metrics, verbosity);
}
}
}
@@ -1298,16 +1299,16 @@ int do_why(const std::vector<cwidget::util::ref_ptr<pattern> > &leaves,
aptitude::why::roots_string_mode display_mode,
int verbosity,
bool root_is_removal,
- const shared_ptr<terminal> &term)
+ const shared_ptr<terminal_metrics> &term_metrics)
{
bool success = false;
const shared_ptr<why_callbacks> callbacks =
- make_cmdline_why_callbacks(verbosity, term);
+ make_cmdline_why_callbacks(verbosity, term_metrics);
std::auto_ptr<cw::fragment> f(do_why(leaves, root, display_mode,
verbosity, root_is_removal,
callbacks,
success));
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
// TODO: display each result as we find it.
std::cout << f->layout(screen_width, screen_width, cw::style());
@@ -1407,7 +1408,7 @@ int cmdline_why(int argc, char *argv[],
aptitude::why::roots_string_mode display_mode,
bool is_why_not)
{
- const shared_ptr<terminal> term = create_terminal();
+ const shared_ptr<terminal_io> term = create_terminal();
_error->DumpErrors();
diff --git a/src/cmdline/cmdline_why.h b/src/cmdline/cmdline_why.h
index 880efe99..7b8d7e36 100644
--- a/src/cmdline/cmdline_why.h
+++ b/src/cmdline/cmdline_why.h
@@ -108,7 +108,7 @@ namespace aptitude
{
namespace cmdline
{
- class terminal;
+ class terminal_metrics;
}
namespace why
@@ -497,7 +497,7 @@ namespace aptitude
*/
boost::shared_ptr<why_callbacks>
make_cmdline_why_callbacks(const int verbosity,
- const boost::shared_ptr<cmdline::terminal> &term);
+ const boost::shared_ptr<cmdline::terminal_metrics> &term_metrics);
/** \brief Search for a justification for an action.
*
diff --git a/src/cmdline/mocks/teletype.cc b/src/cmdline/mocks/teletype.cc
index efbff62f..83c290ca 100644
--- a/src/cmdline/mocks/teletype.cc
+++ b/src/cmdline/mocks/teletype.cc
@@ -51,8 +51,9 @@ namespace aptitude
// The character cell containing the cursor:
unsigned int cursor_position;
- const shared_ptr<terminal> term;
const shared_ptr<terminal_locale> term_locale;
+ const shared_ptr<terminal_metrics> term_metrics;
+ const shared_ptr<terminal_with_combined_output> term_output;
void scroll_line(std::wstring &new_last_line);
void do_set_last_line(const std::wstring &new_last_line);
@@ -73,34 +74,17 @@ namespace aptitude
}
public:
- teletype_with_terminal(const shared_ptr<terminal> &_term,
- const shared_ptr<terminal_locale> &_term_locale)
+ teletype_with_terminal(const shared_ptr<terminal_locale> &_term_locale,
+ const shared_ptr<terminal_metrics> &_term_metrics,
+ const shared_ptr<terminal_with_combined_output> &_term_output)
: cursor_idx(0),
cursor_position(0),
- term(_term),
- term_locale(_term_locale)
+ term_locale(_term_locale),
+ term_metrics(_term_metrics),
+ term_output(_term_output)
{
- ON_CALL(*term, output(_))
+ ON_CALL(*term_output, output(_))
.WillByDefault(Invoke(this, &teletype_with_terminal::handle_output));
-
- // TODO: need to defer this until flush() is called!
- ON_CALL(*term, move_to_beginning_of_line())
- .WillByDefault(Invoke(this, &teletype_with_terminal::handle_move_to_beginning_of_line));
-
- // Normally code using this interface will ignore calls to
- // functions on the terminal, so set that as the default
- // behavior.
- EXPECT_CALL(*term, output(_))
- .Times(AnyNumber());
-
- EXPECT_CALL(*term, write_text(_))
- .Times(AnyNumber());
-
- EXPECT_CALL(*term, flush())
- .Times(AnyNumber());
-
- EXPECT_CALL(*term, move_to_beginning_of_line())
- .Times(AnyNumber());
}
};
@@ -127,7 +111,7 @@ namespace aptitude
void teletype_with_terminal::handle_output(const std::wstring &output)
{
std::wstring new_last_line = last_line;
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
for(std::wstring::const_iterator it = output.begin();
it != output.end(); ++it)
@@ -222,19 +206,16 @@ namespace aptitude
do_set_last_line(new_last_line);
}
-
- void teletype_with_terminal::handle_move_to_beginning_of_line()
- {
- cursor_position = 0;
- cursor_idx = 0;
- }
}
shared_ptr<teletype>
- create_teletype(const boost::shared_ptr<terminal> &term,
- const boost::shared_ptr<terminal_locale> &term_locale)
+ create_teletype(const shared_ptr<terminal_locale> &term_locale,
+ const shared_ptr<terminal_metrics> &term_metrics,
+ const boost::shared_ptr<terminal_with_combined_output> &term_output)
{
- return make_shared<teletype_with_terminal>(term, term_locale);
+ return make_shared<teletype_with_terminal>(term_locale,
+ term_metrics,
+ term_output);
}
}
}
diff --git a/src/cmdline/mocks/teletype.h b/src/cmdline/mocks/teletype.h
index bdd5f49a..d0b0ae41 100644
--- a/src/cmdline/mocks/teletype.h
+++ b/src/cmdline/mocks/teletype.h
@@ -32,8 +32,9 @@ namespace aptitude
{
namespace mocks
{
- class terminal;
class terminal_locale;
+ class terminal_metrics;
+ class terminal_with_combined_output;
inline std::string make_str(const char *s)
{
@@ -88,13 +89,11 @@ namespace aptitude
/** \brief Create a teletype mock specialized to process the
* output from the given terminal.
- *
- * Also adds expectations on the terminal to ignore all calls
- * to output() and flush(), so they don't generate errors.
*/
boost::shared_ptr<teletype>
- create_teletype(const boost::shared_ptr<terminal> &term,
- const boost::shared_ptr<terminal_locale> &term_locale);
+ create_teletype(const boost::shared_ptr<terminal_locale> &term_locale,
+ const boost::shared_ptr<terminal_metrics> &term_metrics,
+ const boost::shared_ptr<terminal_with_combined_output> &term_output);
}
}
}
diff --git a/src/cmdline/mocks/terminal.cc b/src/cmdline/mocks/terminal.cc
index 484a0658..4b797938 100644
--- a/src/cmdline/mocks/terminal.cc
+++ b/src/cmdline/mocks/terminal.cc
@@ -37,9 +37,20 @@ namespace aptitude
{
namespace mocks
{
- shared_ptr<terminal> terminal::create()
+
+ terminal_input::terminal_input()
+ {
+ }
+
+ shared_ptr<terminal_input> terminal_input::create()
+ {
+ return make_shared<terminal_input>();
+ }
+
+ terminal_locale::terminal_locale()
{
- return make_shared<terminal>();
+ EXPECT_CALL(*this, wcwidth(_))
+ .WillRepeatedly(Return(1));
}
shared_ptr<terminal_locale> terminal_locale::create()
@@ -47,77 +58,105 @@ namespace aptitude
return make_shared<terminal_locale>();
}
- class terminal::combining_impl : public terminal
+ terminal_metrics::terminal_metrics()
{
+ }
+
+ shared_ptr<terminal_metrics> terminal_metrics::create()
+ {
+ return make_shared<terminal_metrics>();
+ }
+
+ terminal_output::terminal_output()
+ {
+ }
+
+ shared_ptr<terminal_output> terminal_output::create()
+ {
+ return make_shared<terminal_output>();
+ }
+
+ class combining_terminal_output::impl : public combining_terminal_output
+ {
+ friend shared_ptr<impl> make_shared<impl>();
+ impl();
+
std::wstring pending_writes;
- void do_write_text(const std::wstring &s)
- {
- std::wstring::size_type start = 0;
- for(std::wstring::size_type nl = s.find('\n', start);
- nl != s.npos; nl = s.find('\n', start))
- {
- pending_writes.append(s, start, (nl - start) + 1);
- start = nl + 1;
-
- output(pending_writes);
- pending_writes.clear();
- }
-
- pending_writes.append(s, start, s.npos);
- }
-
- void do_move_to_beginning_of_line()
- {
- do_write_text(L"\r");
- }
-
- void do_flush()
- {
- if(!pending_writes.empty())
- {
- output(pending_writes);
- pending_writes.clear();
- }
- }
+ void do_write_text(const std::wstring &s);
public:
- combining_impl()
- {
- }
-
- void write_text(const std::wstring &s)
- {
- do_write_text(s);
- terminal::write_text(s);
- }
-
- void move_to_beginning_of_line()
- {
- do_move_to_beginning_of_line();
- terminal::move_to_beginning_of_line();
- }
-
- // This is overridden (rather than relying on ON_CALL) to
- // ensure that output is written before the mock's flush() is
- // called; otherwise, it looks like the output comes second,
- // which is surprising.
- void flush()
- {
- do_flush();
- terminal::flush();
- }
+ void write_text(const std::wstring &s);
+ void move_to_beginning_of_line();
+ void flush();
+
+ static shared_ptr<impl> create();
};
- shared_ptr<terminal> create_combining_terminal()
+ combining_terminal_output::impl::impl()
{
- return make_shared<terminal::combining_impl>();
}
- terminal_locale::terminal_locale()
+ void combining_terminal_output::impl::do_write_text(const std::wstring &s)
{
- EXPECT_CALL(*this, wcwidth(_))
- .WillRepeatedly(Return(1));
+ std::wstring::size_type start = 0;
+ for(std::wstring::size_type nl = s.find('\n', start);
+ nl != s.npos; nl = s.find('\n', start))
+ {
+ pending_writes.append(s, start, (nl - start) + 1);
+ start = nl + 1;
+
+ output(pending_writes);
+ pending_writes.clear();
+ }
+
+ pending_writes.append(s, start, s.npos);
+ }
+
+ void combining_terminal_output::impl::write_text(const std::wstring &s)
+ {
+ do_write_text(s);
+ }
+
+ void combining_terminal_output::impl::move_to_beginning_of_line()
+ {
+ do_write_text(L"\r");
+ }
+
+ void combining_terminal_output::impl::flush()
+ {
+ if(!pending_writes.empty())
+ {
+ output(pending_writes);
+ pending_writes.clear();
+ }
+ }
+
+ terminal_with_combined_output::terminal_with_combined_output()
+ {
+ }
+
+ terminal_with_combined_output::~terminal_with_combined_output()
+ {
+ }
+
+ shared_ptr<terminal_with_combined_output> terminal_with_combined_output::create()
+ {
+ return make_shared<terminal_with_combined_output>();
+ }
+
+ combining_terminal_output::combining_terminal_output()
+ {
+ }
+
+ shared_ptr<combining_terminal_output::impl> combining_terminal_output::impl::create()
+ {
+ return make_shared<combining_terminal_output::impl>();
+ }
+
+ shared_ptr<combining_terminal_output> combining_terminal_output::create()
+ {
+ return impl::create();
}
}
}
diff --git a/src/cmdline/mocks/terminal.h b/src/cmdline/mocks/terminal.h
index a47cc04b..20403d6a 100644
--- a/src/cmdline/mocks/terminal.h
+++ b/src/cmdline/mocks/terminal.h
@@ -45,31 +45,48 @@ namespace aptitude
* used to test other mocks that extend the terminal's behavior
* (such as the teletype mock). To get a terminal that
* interprets calls to write_text(), use
- * create_combining_terminal().
+ * combining_terminal_output.
*/
- class terminal : public aptitude::cmdline::terminal
+ class terminal_output : public aptitude::cmdline::terminal_output
{
- class combining_impl;
- friend boost::shared_ptr<terminal> create_combining_terminal();
+ friend boost::shared_ptr<terminal_output>
+ boost::make_shared<terminal_output>();
+
+ terminal_output();
public:
MOCK_METHOD0(output_is_a_terminal, bool());
MOCK_METHOD1(write_text, void(const std::wstring &));
MOCK_METHOD0(move_to_beginning_of_line, void());
MOCK_METHOD0(flush, void());
+
+ static boost::shared_ptr<terminal_output> create();
+ };
+
+ class terminal_input : public aptitude::cmdline::terminal_input
+ {
+ friend boost::shared_ptr<terminal_input>
+ boost::make_shared<terminal_input>();
+
+ terminal_input();
+
+ public:
MOCK_METHOD1(prompt_for_input, std::wstring(const std::wstring &));
- MOCK_METHOD0(get_screen_width, unsigned int());
- // This method is invoked when the terminal would flush its
- // output: specifically, for each newline that's written and
- // for each call to flush().
- //
- // If the terminal would flush, but there's no text to flush,
- // this isn't invoked.
- MOCK_METHOD1(output, void(const std::wstring &));
+ static boost::shared_ptr<terminal_input> create();
+ };
+
+ class terminal_metrics : public aptitude::cmdline::terminal_metrics
+ {
+ friend boost::shared_ptr<terminal_metrics>
+ boost::make_shared<terminal_metrics>();
+
+ terminal_metrics();
+
+ public:
+ MOCK_METHOD0(get_screen_width, unsigned int());
- /** \brief Create a terminal object. */
- static boost::shared_ptr<terminal> create();
+ static boost::shared_ptr<terminal_metrics> create();
};
/** \brief A mock for the terminal locale routines.
@@ -90,9 +107,35 @@ namespace aptitude
static boost::shared_ptr<terminal_locale> create();
};
- /** \brief Create a mock terminal that interprets calls to
- * write_text() and flush(), invoking output() when
- * appropriate.
+ /** \brief Interface for objects that emit terminal output as a
+ * sequence of string writes.
+ */
+ class terminal_with_combined_output
+ {
+ terminal_with_combined_output();
+
+ friend class combining_terminal_output;
+
+ friend boost::shared_ptr<terminal_with_combined_output>
+ boost::make_shared<terminal_with_combined_output>();
+
+ public:
+ virtual ~terminal_with_combined_output();
+
+ // This method is invoked when the terminal would flush its
+ // output: specifically, for each newline that's written and
+ // for each call to flush().
+ //
+ // If the terminal would flush, but there's no text to flush,
+ // this isn't invoked.
+ MOCK_METHOD1(output, void(const std::wstring &));
+
+ static boost::shared_ptr<terminal_with_combined_output> create();
+ };
+
+ /** \brief Interface for objects that can receive calls to
+ * terminal_output and emit calls as a
+ * terminal_with_combined_output.
*
* Calls to move_to_beginning_of_line() are rewritten to place
* '\r' on the output stream instead. This is done so that
@@ -100,7 +143,23 @@ namespace aptitude
* move_to_beginning_of_line() occurs in the right place
* relative to calls to write_to_text().
*/
- boost::shared_ptr<terminal> create_combining_terminal();
+ class combining_terminal_output : public aptitude::cmdline::terminal_output,
+ public terminal_with_combined_output
+ {
+ class impl;
+ friend class impl;
+
+ friend boost::shared_ptr<combining_terminal_output>
+ create_combining_terminal_output();
+
+ combining_terminal_output();
+
+ public:
+ // Mocked because tests might want to override its behavior:
+ MOCK_METHOD0(output_is_a_terminal, bool());
+
+ static boost::shared_ptr<combining_terminal_output> create();
+ };
}
}
}
diff --git a/src/cmdline/terminal.cc b/src/cmdline/terminal.cc
index fd71031f..bce7b077 100644
--- a/src/cmdline/terminal.cc
+++ b/src/cmdline/terminal.cc
@@ -56,7 +56,7 @@ namespace aptitude
// -- watch out for what happens if the curses UI starts up,
// we'll have to tear down the handler, and be sure to handle
// memory barriers.
- class terminal_impl : public terminal
+ class terminal_impl : public terminal_io
{
public:
bool output_is_a_terminal();
@@ -65,6 +65,7 @@ namespace aptitude
void flush();
std::wstring prompt_for_input(const std::wstring &msg);
unsigned int get_screen_width();
+ int wcwidth(wchar_t ch);
};
bool terminal_impl::output_is_a_terminal()
@@ -121,19 +122,13 @@ namespace aptitude
return 80;
}
- class terminal_locale_impl : public terminal_locale
- {
- public:
- int wcwidth(wchar_t ch);
- };
-
- int terminal_locale_impl::wcwidth(wchar_t ch)
+ int terminal_impl::wcwidth(wchar_t ch)
{
return ::wcwidth(ch);
}
}
- terminal::~terminal()
+ terminal_input::~terminal_input()
{
}
@@ -141,14 +136,17 @@ namespace aptitude
{
}
- shared_ptr<terminal> create_terminal()
+ terminal_metrics::~terminal_metrics()
{
- return make_shared<terminal_impl>();
}
- shared_ptr<terminal_locale> create_terminal_locale()
+ terminal_output::~terminal_output()
{
- return make_shared<terminal_locale_impl>();
+ }
+
+ shared_ptr<terminal_io> create_terminal()
+ {
+ return make_shared<terminal_impl>();
}
}
}
diff --git a/src/cmdline/terminal.h b/src/cmdline/terminal.h
index b77765dc..a169acee 100644
--- a/src/cmdline/terminal.h
+++ b/src/cmdline/terminal.h
@@ -45,13 +45,20 @@ namespace aptitude
/** \brief Abstraction of the I/O device used for the command-line
* code.
*
- * A virtual interface is used so that we can dummy it out for
- * testing (see mocks/terminal.h).
+ * Virtual interfaces are used so that we can dummy them out for
+ * testing (see mocks/terminal.h). Using several virtual
+ * interfaces allows code to specify more precisely which
+ * functionality is required, so we don't have to
*/
- class terminal
+ // @{
+
+ /** \brief Interface representing the ability to write to the
+ * terminal.
+ */
+ class terminal_output
{
public:
- virtual ~terminal();
+ virtual ~terminal_output();
/** \brief Check whether the output stream seems to be connected
* to a terminal.
@@ -79,6 +86,15 @@ namespace aptitude
* printed.
*/
virtual void flush() = 0;
+ };
+
+ /** \brief Interface representing the ability to read from the
+ * terminal.
+ */
+ class terminal_input
+ {
+ public:
+ ~terminal_input();
/** \brief Prompt for a line of input from the terminal device.
*
@@ -96,6 +112,15 @@ namespace aptitude
* and aborts the program.
*/
virtual std::wstring prompt_for_input(const std::wstring &msg) = 0;
+ };
+
+ /** \brief Interface representing the ability to read the
+ * characteristics of the terminal.
+ */
+ class terminal_metrics
+ {
+ public:
+ ~terminal_metrics();
/** \brief Retrieve the current screen width.
*
@@ -127,16 +152,26 @@ namespace aptitude
*/
virtual int wcwidth(wchar_t ch) = 0;
};
+ // @}
- /** \brief Create a terminal object attached to the standard I/O
- streams.
+ /** \brief Master interface representing all the terminal
+ * capabilities at once.
+ *
+ * This should normally not be passed as a parameter to
+ * functions; it exists so that create_terminal() has a return
+ * type.
*/
- boost::shared_ptr<terminal> create_terminal();
+ class terminal_io : public terminal_input,
+ public terminal_locale,
+ public terminal_metrics,
+ public terminal_output
+ {
+ };
- /** \brief Create a terminal locale object using the system locale
- * definitions.
+ /** \brief Create a terminal object attached to the standard I/O
+ * streams and using the system locale definitions.
*/
- boost::shared_ptr<terminal_locale> create_terminal_locale();
+ boost::shared_ptr<terminal_io> create_terminal();
}
}
diff --git a/src/cmdline/text_progress.cc b/src/cmdline/text_progress.cc
index e7b895b6..05b88558 100644
--- a/src/cmdline/text_progress.cc
+++ b/src/cmdline/text_progress.cc
@@ -151,11 +151,12 @@ namespace aptitude
shared_ptr<OpProgress>
make_text_progress(bool require_tty_decorations,
- const shared_ptr<terminal> &term,
- const shared_ptr<terminal_locale> &term_locale)
+ const shared_ptr<terminal_locale> &term_locale,
+ const shared_ptr<terminal_metrics> &term_metrics,
+ const shared_ptr<terminal_output> &term_output)
{
return make_text_progress(require_tty_decorations,
- create_progress_display(term, term_locale));
+ create_progress_display(term_locale, term_metrics, term_output));
}
}
}
diff --git a/src/cmdline/text_progress.h b/src/cmdline/text_progress.h
index fc30e983..b8ee189e 100644
--- a/src/cmdline/text_progress.h
+++ b/src/cmdline/text_progress.h
@@ -34,8 +34,9 @@ namespace aptitude
namespace cmdline
{
- class terminal;
class terminal_locale;
+ class terminal_metrics;
+ class terminal_output;
/** \brief Create a customized text spinner that's similar to
* apt's spinner, but "cleans up" after itself if stdout appears
@@ -65,8 +66,9 @@ namespace aptitude
*/
boost::shared_ptr<OpProgress>
make_text_progress(bool require_tty_decorations,
- const boost::shared_ptr<terminal> &term,
- const boost::shared_ptr<terminal_locale> &term_locale);
+ const boost::shared_ptr<terminal_locale> &term_locale,
+ const boost::shared_ptr<terminal_metrics> &term_metrics,
+ const boost::shared_ptr<terminal_output> &term_output);
}
}
diff --git a/src/cmdline/transient_message.cc b/src/cmdline/transient_message.cc
index ea06e482..a90f6fda 100644
--- a/src/cmdline/transient_message.cc
+++ b/src/cmdline/transient_message.cc
@@ -76,20 +76,25 @@ namespace aptitude
// The last string we displayed.
std::wstring last_line;
- // The terminal used to output text.
- shared_ptr<terminal> term;
-
// The locale to be used with that terminal.
shared_ptr<terminal_locale> term_locale;
+ // The dimensions of the terminal.
+ shared_ptr<terminal_metrics> term_metrics;
+
+ // The terminal output object used to display this message.
+ shared_ptr<terminal_output> term_output;
+
void clear_last_line();
public:
- transient_message_impl(const shared_ptr<terminal> &_term,
- const shared_ptr<terminal_locale> &_term_locale)
+ transient_message_impl(const shared_ptr<terminal_locale> &_term_locale,
+ const shared_ptr<terminal_metrics> &_term_metrics,
+ const shared_ptr<terminal_output> &_term_output)
: last_line_len(0),
- term(_term),
- term_locale(_term_locale)
+ term_locale(_term_locale),
+ term_metrics(_term_metrics),
+ term_output(_term_output)
{
}
@@ -102,10 +107,10 @@ namespace aptitude
{
static const std::wstring blank(L" ");
- term->move_to_beginning_of_line();
+ term_output->move_to_beginning_of_line();
for(std::size_t i = 0; i < last_line_len; ++i)
- term->write_text(blank);
- term->move_to_beginning_of_line();
+ term_output->write_text(blank);
+ term_output->move_to_beginning_of_line();
last_line_len = 0;
}
@@ -117,7 +122,7 @@ namespace aptitude
// do.
return;
- const unsigned int screen_width = term->get_screen_width();
+ const unsigned int screen_width = term_metrics->get_screen_width();
// Display the message on a single line of the terminal.
@@ -150,8 +155,8 @@ namespace aptitude
const std::wstring display(line.begin(), display_end);
clear_last_line();
- term->write_text(display);
- term->flush();
+ term_output->write_text(display);
+ term_output->flush();
last_line_len = display_width;
last_line = line;
}
@@ -159,8 +164,8 @@ namespace aptitude
void transient_message_impl::display_and_advance(const std::wstring &msg)
{
clear_last_line();
- term->write_text(msg);
- term->write_text(L"\n");
+ term_output->write_text(msg);
+ term_output->write_text(L"\n");
last_line_len = 0;
last_line.clear();
@@ -168,13 +173,14 @@ namespace aptitude
}
shared_ptr<transient_message>
- create_transient_message(const shared_ptr<terminal> &term,
- const shared_ptr<terminal_locale> &term_locale)
+ create_transient_message(const shared_ptr<terminal_locale> &term_locale,
+ const shared_ptr<terminal_metrics> &term_metrics,
+ const shared_ptr<terminal_output> &term_output)
{
- if(!term->output_is_a_terminal())
+ if(!term_output->output_is_a_terminal())
return make_shared<dummy_transient_message>();
else
- return make_shared<transient_message_impl>(term, term_locale);
+ return make_shared<transient_message_impl>(term_locale, term_metrics, term_output);
}
}
}
diff --git a/src/cmdline/transient_message.h b/src/cmdline/transient_message.h
index 54e29aec..787c1d56 100644
--- a/src/cmdline/transient_message.h
+++ b/src/cmdline/transient_message.h
@@ -49,20 +49,23 @@ namespace aptitude
virtual void display_and_advance(const std::wstring &text) = 0;
};
- class terminal;
class terminal_locale;
+ class terminal_metrics;
+ class terminal_output;
/** \brief Create a new transient message object.
*
* If the given terminal is not a tty when this function is
* invoked, no output will be generated.
*
- * \param term The terminal to use for output.
- * \param term_locale Locale information for the given terminal.
+ * \param term_locale Locale information for the given terminal.
+ * \param term_metrics The terminal metrics object to use.
+ * \param term_output The terminal output object to use.
*/
boost::shared_ptr<transient_message>
- create_transient_message(const boost::shared_ptr<terminal> &term,
- const boost::shared_ptr<terminal_locale> &term_locale);
+ create_transient_message(const boost::shared_ptr<terminal_locale> &term_locale,
+ const boost::shared_ptr<terminal_metrics> &term_metrics,
+ const boost::shared_ptr<terminal_output> &term_output);
}
}