1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

Fix list_display on non-ttys and other output fixes

commit c1f742d775 broke what was one of the tenants of out output-
if piping pacman output somewhere else, we shouldn't ever try to
line-wrap and indent print our output. This makes it easier for tools to
use output from pacman -Ss, -Qs, -Qi, etc. list_display() unfortunately
was given a default value of 80 rather than 0, so fix this.

Next, make some additional changes that ensure we don't insert an
unnecessary blank line if for some crazy reason the indent level (such
as on -Qi output) is greater than the number of columns. Accomplish this
by printing the first item unconditionally as we do in
list_display_linebreak().

Finally, teach indentprint to not wrap if the number of columns is less
than the indent level, this prevents some forms of ridiculous output
such as the following:

    Install Date   : Wed
                     08
                     Jun
                     2011
                     04:39:19
                     AM
                     CDT

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-13 17:04:35 -05:00
parent b059040011
commit 895a888865

View File

@ -216,8 +216,9 @@ void indentprint(const char *str, int indent)
return;
}
/* if we're not a tty, print without indenting */
if(cols == 0) {
/* if we're not a tty, or our tty is not wide enough that wrapping even makes
* sense, print without indenting */
if(cols == 0 || indent > cols) {
printf("%s", str);
return;
}
@ -450,12 +451,16 @@ void list_display(const char *title, const alpm_list_t *list)
if(!list) {
printf("%s\n", _("None"));
} else {
int cols;
const int maxcols = getcols(80);
for(i = list, cols = len; i; i = alpm_list_next(i)) {
char *str = alpm_list_getdata(i);
const int maxcols = getcols(0);
int cols = len;
const char *str = alpm_list_getdata(list);
printf("%s", str);
cols += string_length(str);
for(i = alpm_list_next(list), cols = len; i; i = alpm_list_next(i)) {
const char *str = alpm_list_getdata(i);
int s = string_length(str);
if(cols + s + 2 >= maxcols) {
/* wrap only if we have enough usable column space */
if(maxcols > len && cols + s + 2 >= maxcols) {
int j;
cols = len;
printf("\n");