mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 21:38:19 -05:00
Don't wrap lines when we don't have a column size
For example when we are not in a tty, there is no point in wrapping the output. This actually makes the job harder for scripts. $ pacman -Si binutils | grep Desc Description : A set of programs to assemble and manipulate binary and The description was cut because the rest was on the following line. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> [Dan: use printf everywhere] Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
c88ac86292
commit
5dbd00faf7
@ -85,12 +85,6 @@ int needs_root(void)
|
|||||||
/* gets the current screen column width */
|
/* gets the current screen column width */
|
||||||
int getcols(void)
|
int getcols(void)
|
||||||
{
|
{
|
||||||
if(!isatty(1)) {
|
|
||||||
/* We will default to 80 columns if we're not a tty
|
|
||||||
* this seems a fairly standard file width.
|
|
||||||
*/
|
|
||||||
return 80;
|
|
||||||
} else {
|
|
||||||
#ifdef TIOCGSIZE
|
#ifdef TIOCGSIZE
|
||||||
struct ttysize win;
|
struct ttysize win;
|
||||||
if(ioctl(1, TIOCGSIZE, &win) == 0) {
|
if(ioctl(1, TIOCGSIZE, &win) == 0) {
|
||||||
@ -102,17 +96,7 @@ int getcols(void)
|
|||||||
return win.ws_col;
|
return win.ws_col;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* If we can't figure anything out, we'll just assume 80 columns */
|
return 0;
|
||||||
/* TODO any problems caused by this assumption? */
|
|
||||||
return 80;
|
|
||||||
}
|
|
||||||
/* Original envvar way - prone to display issues
|
|
||||||
const char *cenv = getenv("COLUMNS");
|
|
||||||
if(cenv != NULL) {
|
|
||||||
return atoi(cenv);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* does the same thing as 'mkdir -p' */
|
/* does the same thing as 'mkdir -p' */
|
||||||
@ -256,6 +240,14 @@ void indentprint(const char *str, int indent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cols = getcols();
|
||||||
|
|
||||||
|
/* if we're not a tty, print without indenting */
|
||||||
|
if(cols == 0) {
|
||||||
|
printf("%s", str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
len = strlen(str) + 1;
|
len = strlen(str) + 1;
|
||||||
wcstr = calloc(len, sizeof(wchar_t));
|
wcstr = calloc(len, sizeof(wchar_t));
|
||||||
len = mbstowcs(wcstr, str, len);
|
len = mbstowcs(wcstr, str, len);
|
||||||
@ -265,7 +257,6 @@ void indentprint(const char *str, int indent)
|
|||||||
if(!p) {
|
if(!p) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cols = getcols();
|
|
||||||
|
|
||||||
while(*p) {
|
while(*p) {
|
||||||
if(*p == L' ') {
|
if(*p == L' ') {
|
||||||
@ -284,7 +275,7 @@ void indentprint(const char *str, int indent)
|
|||||||
}
|
}
|
||||||
if(len > (cols - cidx - 1)) {
|
if(len > (cols - cidx - 1)) {
|
||||||
/* wrap to a newline and reindent */
|
/* wrap to a newline and reindent */
|
||||||
fprintf(stdout, "\n%-*s", indent, "");
|
printf("\n%-*s", indent, "");
|
||||||
cidx = indent;
|
cidx = indent;
|
||||||
} else {
|
} else {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
@ -292,7 +283,7 @@ void indentprint(const char *str, int indent)
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "%lc", (wint_t)*p);
|
printf("%lc", (wint_t)*p);
|
||||||
cidx += wcwidth(*p);
|
cidx += wcwidth(*p);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
@ -476,7 +467,7 @@ void list_display(const char *title, const alpm_list_t *list)
|
|||||||
/* two additional spaces are added to the length */
|
/* two additional spaces are added to the length */
|
||||||
s += 2;
|
s += 2;
|
||||||
int maxcols = getcols();
|
int maxcols = getcols();
|
||||||
if(s + cols > maxcols) {
|
if(s + cols > maxcols && maxcols > 0) {
|
||||||
int j;
|
int j;
|
||||||
cols = len;
|
cols = len;
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user