summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel_Burrows@alumni.brown.edu <Daniel_Burrows@alumni.brown.edu>2010-05-25 21:00:40 -0700
committerDaniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu>2010-06-08 19:50:28 -0700
commit18d7376cf9e094ba47d7905e2d97186533bd479f (patch)
tree67582730685f7396baed7405fa3379913a0cded8
parent084d8537e44de3f3ff47f9bed66faac2914ae8e5 (diff)
downloadaptitude-18d7376cf9e094ba47d7905e2d97186533bd479f.tar.gz
Use the new progress stuff to get progress indicators from "search" and "versions".
Note that they currently display progress information even if stdout is not a tty, which really needs to be fixed.
-rw-r--r--src/cmdline/cmdline_progress_display.cc40
-rw-r--r--src/cmdline/cmdline_progress_display.h17
-rw-r--r--src/cmdline/cmdline_search.cc44
-rw-r--r--src/cmdline/cmdline_versions.cc33
4 files changed, 113 insertions, 21 deletions
diff --git a/src/cmdline/cmdline_progress_display.cc b/src/cmdline/cmdline_progress_display.cc
index 3369d27d..c35b5d6d 100644
--- a/src/cmdline/cmdline_progress_display.cc
+++ b/src/cmdline/cmdline_progress_display.cc
@@ -17,15 +17,19 @@
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
+// Local includes:
#include "cmdline_progress_display.h"
#include "transient_message.h"
#include <generic/util/progress_info.h>
+
+// System includes:
#include <boost/format.hpp>
#include <boost/make_shared.hpp>
+#include <cwidget/generic/util/transcode.h>
#include <sys/time.h>
@@ -33,9 +37,10 @@ using aptitude::util::progress_info;
using aptitude::util::progress_type_bar;
using aptitude::util::progress_type_none;
using aptitude::util::progress_type_pulse;
-using boost::format;
using boost::make_shared;
using boost::shared_ptr;
+using boost::wformat;
+using cwidget::util::transcode;
namespace aptitude
{
@@ -63,15 +68,15 @@ namespace aptitude
bool should_update(const progress_info &progress) const;
public:
- progress_display_impl();
+ progress_display_impl(const shared_ptr<transient_message> &_message);
void set_progress(const progress_info &progress,
bool force_update);
};
- progress_display_impl::progress_display_impl()
+ progress_display_impl::progress_display_impl(const shared_ptr<transient_message> &_message)
: last_progress(progress_info::none()),
- message(create_transient_message())
+ message(_message)
{
}
@@ -103,22 +108,22 @@ namespace aptitude
switch(progress.get_type())
{
case progress_type_none:
- message->set_text("");
+ message->set_text(L"");
break;
case progress_type_pulse:
- message->set_text( (format(" %s")
- % progress.get_progress_status()).str() );
+ message->set_text( (wformat(L" %s")
+ % transcode(progress.get_progress_status())).str() );
break;
case progress_type_bar:
- message->set_text( (format("[%3d%%] %s")
+ message->set_text( (wformat(L"[%3d%%] %s")
% progress.get_progress_percent_int()
- % progress.get_progress_status()).str() );
+ % transcode(progress.get_progress_status())).str() );
break;
default:
- message->set_text("INTERNAL ERROR");
+ message->set_text(L"INTERNAL ERROR");
break;
}
@@ -132,9 +137,20 @@ namespace aptitude
{
}
- shared_ptr<progress_display> create_progress_display()
+ shared_ptr<progress_display>
+ create_progress_display(const shared_ptr<transient_message> &message)
{
- return make_shared<progress_display_impl>();
+ return make_shared<progress_display_impl>(message);
+ }
+
+ shared_ptr<progress_display>
+ create_progress_display(const shared_ptr<terminal> &term,
+ const shared_ptr<terminal_locale> &term_locale)
+ {
+ const shared_ptr<transient_message> message =
+ create_transient_message(term, term_locale);
+
+ return create_progress_display(message);
}
}
}
diff --git a/src/cmdline/cmdline_progress_display.h b/src/cmdline/cmdline_progress_display.h
index 1612d2f4..b8ca1da6 100644
--- a/src/cmdline/cmdline_progress_display.h
+++ b/src/cmdline/cmdline_progress_display.h
@@ -20,6 +20,7 @@
#ifndef APTITUDE_CMDLINE_PROGRESS_DISPLAY_H
#define APTITUDE_CMDLINE_PROGRESS_DISPLAY_H
+// System includes:
#include <boost/shared_ptr.hpp>
namespace aptitude
@@ -31,6 +32,10 @@ namespace aptitude
namespace cmdline
{
+ class terminal;
+ class terminal_locale;
+ class transient_message;
+
/** \brief A general class for displaying a single line of
* progress information.
*
@@ -60,7 +65,17 @@ namespace aptitude
};
/** \brief Create a blank progress display. */
- boost::shared_ptr<progress_display> create_progress_display();
+ boost::shared_ptr<progress_display>
+ create_progress_display(const boost::shared_ptr<transient_message> &message);
+
+ /** \brief Create a blank progress display.
+ *
+ * This is a convenience routine, equivalent to creating a new
+ * transient message with the given terminal objects.
+ */
+ boost::shared_ptr<progress_display>
+ create_progress_display(const boost::shared_ptr<terminal> &term,
+ const boost::shared_ptr<terminal_locale> &term_locale);
}
}
diff --git a/src/cmdline/cmdline_search.cc b/src/cmdline/cmdline_search.cc
index f11ce84a..ad8c1920 100644
--- a/src/cmdline/cmdline_search.cc
+++ b/src/cmdline/cmdline_search.cc
@@ -23,8 +23,11 @@
#include "cmdline_search.h"
#include "cmdline_common.h"
+#include "cmdline_progress_display.h"
+#include "cmdline_search_progress.h"
#include "cmdline_util.h"
#include "terminal.h"
+#include "text_progress.h"
#include <aptitude.h>
#include <load_sortpolicy.h>
@@ -37,6 +40,8 @@
#include <generic/apt/matching/match.h>
#include <generic/apt/matching/parse.h>
#include <generic/apt/matching/pattern.h>
+#include <generic/apt/matching/serialize.h>
+#include <generic/util/progress_info.h>
#include <cwidget/config/column_definition.h>
#include <cwidget/generic/util/transcode.h>
@@ -46,15 +51,30 @@
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
+#include <boost/format.hpp>
#include <boost/scoped_ptr.hpp>
+#include <sigc++/bind.h>
+
#include <algorithm>
using namespace std;
namespace cw = cwidget;
using aptitude::Loggers;
+using aptitude::cmdline::create_progress_display;
using aptitude::cmdline::create_terminal;
+using aptitude::cmdline::create_terminal_locale;
+using aptitude::cmdline::make_text_progress;
+using aptitude::cmdline::progress_display;
+using aptitude::cmdline::search_progress;
using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_locale;
+using aptitude::matching::serialize_pattern;
+using aptitude::util::progress_info;
+using aptitude::util::progress_type_bar;
+using aptitude::util::progress_type_none;
+using aptitude::util::progress_type_pulse;
+using boost::format;
using boost::shared_ptr;
using cwidget::util::ref_ptr;
using cwidget::util::transcode;
@@ -69,11 +89,16 @@ namespace
int format_width,
const unsigned int screen_width,
bool disable_columns,
- bool debug)
+ bool debug,
+ const shared_ptr<terminal> &term,
+ const shared_ptr<terminal_locale> &term_locale)
{
typedef std::vector<std::pair<pkgCache::PkgIterator, ref_ptr<structural_match> > >
results_list;
+ const shared_ptr<progress_display> search_progress_display =
+ create_progress_display(term, term_locale);
+
results_list output;
ref_ptr<search_cache> search_info(search_cache::create());
for(std::vector<ref_ptr<pattern> >::const_iterator pIt = patterns.begin();
@@ -85,9 +110,14 @@ namespace
output,
*apt_cache_file,
*apt_package_records,
- debug);
+ debug,
+ sigc::bind(sigc::ptr_fun(&search_progress),
+ search_progress_display,
+ serialize_pattern(*pIt)));
}
+ search_progress_display->set_progress(progress_info::none(), true);
+
_error->DumpErrors();
std::sort(output.begin(), output.end(),
@@ -126,6 +156,7 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
bool disable_columns, bool debug)
{
shared_ptr<terminal> term = create_terminal();
+ shared_ptr<terminal_locale> term_locale = create_terminal_locale();
int real_width=-1;
@@ -175,9 +206,10 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
return -1;
}
- OpProgress progress;
+ shared_ptr<OpProgress> progress =
+ make_text_progress(true, term, term_locale);
- apt_init(&progress, true, status_fname);
+ apt_init(progress.get(), true, status_fname);
if(_error->PendingError())
{
@@ -208,5 +240,7 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
real_width,
screen_width,
disable_columns,
- debug);
+ debug,
+ term,
+ term_locale);
}
diff --git a/src/cmdline/cmdline_versions.cc b/src/cmdline/cmdline_versions.cc
index fa4b18e2..b919174b 100644
--- a/src/cmdline/cmdline_versions.cc
+++ b/src/cmdline/cmdline_versions.cc
@@ -21,6 +21,8 @@
// Local includes:
#include "cmdline_versions.h"
+#include "cmdline_progress_display.h"
+#include "cmdline_search_progress.h"
#include "cmdline_util.h"
#include "terminal.h"
@@ -29,6 +31,9 @@
#include <load_sortpolicy.h>
#include <generic/apt/matching/parse.h>
+#include <generic/apt/matching/pattern.h>
+#include <generic/apt/matching/serialize.h>
+#include <generic/util/progress_info.h>
// System includes:
@@ -40,6 +45,8 @@
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>
+#include <sigc++/bind.h>
+
#include <cwidget/generic/util/ref_ptr.h>
#include <vector>
@@ -47,13 +54,20 @@
namespace cw = cwidget;
namespace m = aptitude::matching;
+using aptitude::cmdline::create_progress_display;
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::progress_display;
+using aptitude::cmdline::search_progress;
using aptitude::cmdline::search_result_column_parameters;
using aptitude::cmdline::terminal;
+using aptitude::cmdline::terminal_locale;
using aptitude::cmdline::version_results_eq;
using aptitude::cmdline::version_results_lt;
+using aptitude::matching::serialize_pattern;
+using aptitude::util::progress_info;
using boost::shared_ptr;
namespace
@@ -227,7 +241,9 @@ namespace
bool disable_columns,
group_by_option group_by,
show_package_names_option show_package_names,
- bool debug)
+ bool debug,
+ const shared_ptr<terminal> &term,
+ const shared_ptr<terminal_locale> &term_locale)
{
// Set to -1 if any exact-name matches fail. Also set to -1 if
// there are no results at all.
@@ -236,6 +252,9 @@ namespace
typedef std::vector<std::pair<pkgCache::VerIterator, cw::util::ref_ptr<m::structural_match> > >
results_list;
+ const shared_ptr<progress_display> search_progress_display =
+ create_progress_display(term, term_locale);
+
results_list output;
cw::util::ref_ptr<m::search_cache> search_info(m::search_cache::create());
for(std::vector<cw::util::ref_ptr<m::pattern> >::const_iterator pIt = patterns.begin();
@@ -249,7 +268,10 @@ namespace
output,
*apt_cache_file,
*apt_package_records,
- debug);
+ debug,
+ sigc::bind(sigc::ptr_fun(&search_progress),
+ search_progress_display,
+ serialize_pattern(*pIt)));
// Warn the user if an exact name pattern didn't produce a
// result.
@@ -262,6 +284,8 @@ namespace
}
}
+ search_progress_display->set_progress(progress_info::none(), true);
+
if(output.empty())
return_value = 2;
@@ -492,6 +516,7 @@ int cmdline_versions(int argc, char *argv[], const char *status_fname,
show_package_names_option show_package_names)
{
shared_ptr<terminal> term = create_terminal();
+ shared_ptr<terminal_locale> term_locale = create_terminal_locale();
int real_width=-1;
@@ -583,5 +608,7 @@ int cmdline_versions(int argc, char *argv[], const char *status_fname,
disable_columns,
group_by,
show_package_names,
- debug);
+ debug,
+ term,
+ term_locale);
}