From 76456fd07e12bef4e383e40ec5607d6e2cd3b6a2 Mon Sep 17 00:00:00 2001 From: Daniel Burrows Date: Sat, 7 Jun 2008 12:48:04 -0700 Subject: Implement the "disable column formatting" feature via a new command-line option, "--disable-columns". (Closes: #141929) This should make 'aptitude search' more useful in scripting contexts or other situations where its output is being used noninteractively. --- doc/en/aptitude.xml | 18 +++++++++++-- doc/en/manpage.xml | 48 ++++++++++++++++++++++++++++++++++ src/cmdline/cmdline_search.cc | 60 +++++++++++++++++++++++++++++++++++-------- src/cmdline/cmdline_search.h | 3 ++- src/main.cc | 11 ++++++-- 5 files changed, 125 insertions(+), 15 deletions(-) diff --git a/doc/en/aptitude.xml b/doc/en/aptitude.xml index e0cfb200..f383fef6 100644 --- a/doc/en/aptitude.xml +++ b/doc/en/aptitude.xml @@ -9439,6 +9439,20 @@ iuAU wesnoth-data +930kB 0.8.7-1 0.8.8-1.0w + + Aptitude::CmdLine::Disable-Columns + false + + If this option is enabled, the results of command-line + searches (performed via aptitude + search) will not be formatted into + fixed-width columns or truncated to the screen width. + This is equivalent to the --disable-columns + command-line option. + + + Aptitude::CmdLine::Download-Only false @@ -9629,8 +9643,8 @@ iuAU wesnoth-data +930kB 0.8.7-1 0.8.8-1.0w Aptitude::Safe-Resolver::No-New-Installs false - If this option is enabled, then when the - safe dependency resolver has been + If this option is true, then when + the safe dependency resolver has been activated via --safe-resolver, the resolver will not be allowed to install packages diff --git a/doc/en/manpage.xml b/doc/en/manpage.xml index 3f939ee7..e3ae7046 100644 --- a/doc/en/manpage.xml +++ b/doc/en/manpage.xml @@ -1006,6 +1006,48 @@ i A texlive-latex-extra Conflicts textopo + + --disable-columns + + + + This option causes aptitude search to + output its results without any special formatting. In + particular: normally &aptitude; will add whitespace or + truncate search results in an attempt to fit its results + into vertical columns. With this flag, + each line will be formed by replacing any format escapes + in the format string with the correponding text; column + widths will be ignored. + + + + For instance, the first few lines of output from aptitude search -F '%p %V' --disable-columns libedataserver might be: + + + disksearch 1.2.1-3 +hp-search-mac 0.1.3 +libbsearch-ruby 1.5-5 +libbsearch-ruby1.8 1.5-5 +libclass-dbi-abstractsearch-perl 0.07-2 +libdbix-fulltextsearch-perl 0.73-10 + + + As in the above example, + --disable-columns is often useful in + combination with a custom display format set using the + command-line option -F. + + + + This corresponds to the configuration option + Aptitude::CmdLine::Disable-Columns. + + + + -D, --show-deps @@ -1057,6 +1099,12 @@ i A texlive-latex-extra Conflicts textopo available version (see the section Customizing how packages are displayed in the &aptitude; reference manual for more information). + + The command-line option --disable-columns + is often useful in combination with -F. + + This corresponds to the configuration option Aptitude::CmdLine::Package-Display-Format. diff --git a/src/cmdline/cmdline_search.cc b/src/cmdline/cmdline_search.cc index 45bf3f5f..e76376c9 100644 --- a/src/cmdline/cmdline_search.cc +++ b/src/cmdline/cmdline_search.cc @@ -27,8 +27,9 @@ using namespace std; namespace cw = cwidget; using cwidget::util::transcode; using namespace aptitude::matching; +using namespace cwidget::config; -class search_result_parameters : public cwidget::config::column_parameters +class search_result_parameters : public column_parameters { pkg_match_result *r; public: @@ -91,7 +92,8 @@ public: // FIXME: apt-cache does lots of tricks to make this fast. Should I? int cmdline_search(int argc, char *argv[], const char *status_fname, - string display_format, string width, string sort) + string display_format, string width, string sort, + bool disable_columns) { int real_width=-1; @@ -123,7 +125,7 @@ int cmdline_search(int argc, char *argv[], const char *status_fname, return -1; } - cwidget::config::column_definition_list *columns = + column_definition_list *columns = parse_columns(wdisplay_format, pkg_item::pkg_columnizer::parse_column_type, pkg_item::pkg_columnizer::defaults); @@ -201,15 +203,53 @@ int cmdline_search(int argc, char *argv[], const char *status_fname, for(vector >::iterator i=output.begin(); i!=output.end(); ++i) { - cwidget::config::column_parameters *p = + column_parameters *p = new search_result_parameters(i->second); + pkg_item::pkg_columnizer columnizer(i->first, + i->first.VersionList(), + *columns, + 0); + if(disable_columns) + { + // Instantiate the format string without clipping or + // expanding columns. + // + // TODO: this should move into cwidget in the future, as a new + // mode of operation for layout_columns(). + std::wstring output; + + for(column_definition_list::iterator it = columns->begin(); + it != columns->end(); + ++it) + { + if(it->type == column_definition::COLUMN_LITERAL) + output += it->arg; + else + { + eassert(it->type == column_definition::COLUMN_GENERATED || + it->type == column_definition::COLUMN_PARAM); + + if(it->type == column_definition::COLUMN_GENERATED) + { + cwidget::column_disposition disp = columnizer.setup_column(it->ival); + output += disp.text; + } + else + { + if(p->param_count() <= it->ival) + output += L"###"; + else + output += p->get_param(it->ival); + } + } + } - printf("%ls\n", - pkg_item::pkg_columnizer(i->first, - i->first.VersionList(), - *columns, - 0).layout_columns(real_width==-1?screen_width:real_width, - *p).c_str()); + printf("%ls\n", output.c_str()); + } + else + printf("%ls\n", + columnizer.layout_columns(real_width==-1?screen_width:real_width, + *p).c_str()); // Note that this deletes the whole result, so we can't re-use // the list. diff --git a/src/cmdline/cmdline_search.h b/src/cmdline/cmdline_search.h index ead96a70..284f2601 100644 --- a/src/cmdline/cmdline_search.h +++ b/src/cmdline/cmdline_search.h @@ -11,6 +11,7 @@ */ int cmdline_search(int argc, char *argv[], const char *status_fname, - std::string display_format, std::string width, std::string sort); + std::string display_format, std::string width, std::string sort, + bool disable_columns); #endif // CMDLINE_SEARCH_H diff --git a/src/main.cc b/src/main.cc index f105d0eb..d4bd2107 100644 --- a/src/main.cc +++ b/src/main.cc @@ -207,7 +207,8 @@ enum { OPTION_SAFE_RESOLVER, OPTION_FULL_RESOLVER, OPTION_ARCH_ONLY, - OPTION_NOT_ARCH_ONLY + OPTION_NOT_ARCH_ONLY, + OPTION_DISABLE_COLUMNS }; int getopt_result; @@ -230,6 +231,7 @@ option opts[]={ {"prompt", 0, NULL, 'P'}, {"sort", 1, NULL, 'O'}, {"target-release", 1, NULL, 't'}, + {"disable-columns", 0, &getopt_result, OPTION_DISABLE_COLUMNS}, {"no-new-installs", 0, &getopt_result, OPTION_NO_NEW_INSTALLS}, {"no-new-upgrades", 0, &getopt_result, OPTION_NO_NEW_UPGRADES}, {"allow-new-installs", 0, &getopt_result, OPTION_ALLOW_NEW_INSTALLS}, @@ -282,6 +284,7 @@ int main(int argc, char *argv[]) bool safe_resolver_no_new_installs = aptcfg->FindB(PACKAGE "::Safe-Resolver::No-New-Installs", false); bool safe_resolver_no_new_upgrades = aptcfg->FindB(PACKAGE "::Safe-Resolver::No-New-Upgrades", false); bool always_use_safe_resolver = aptcfg->FindB(PACKAGE "::Always-Use-Safe-Resolver", false); + bool disable_columns = aptcfg->FindB(PACKAGE "::CmdLine::Disable-Columns", false); bool safe_resolver_option = false; bool full_resolver_option = false; @@ -520,6 +523,9 @@ int main(int argc, char *argv[]) case OPTION_ARCH_ONLY: arch_only = true; break; + case OPTION_DISABLE_COLUMNS: + disable_columns = true; + break; default: fprintf(stderr, "%s", _("WEIRDNESS: unknown option code received\n")); @@ -599,7 +605,8 @@ int main(int argc, char *argv[]) return cmdline_search(argc-optind, argv+optind, status_fname, display_format, width, - sort_policy); + sort_policy, + disable_columns); else if(!strcasecmp(argv[optind], "why")) return cmdline_why(argc - optind, argv + optind, status_fname, verbose, false); -- cgit v1.2.3