[pacman-dev] [PATCH] getcols: return 0 when not attached to a tty
Andrew Gregory
andrew.gregory.8 at gmail.com
Mon Aug 11 09:51:19 EDT 2014
Scripts that parse pacman's output (like pacsearch) generally do not
want wrapped lines.
Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
src/pacman/util.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 6a095fd..de103b6 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -46,7 +46,7 @@
#include "conf.h"
#include "callback.h"
-static int cached_columns = 0;
+static int cached_columns = -1;
struct table_cell_t {
char *label;
@@ -158,7 +158,7 @@ static int flush_term_input(int fd)
void columns_cache_reset(void)
{
- cached_columns = 0;
+ cached_columns = -1;
}
static int getcols_fd(int fd)
@@ -189,10 +189,15 @@ unsigned short getcols(void)
const char *e;
int c = 0;
- if(cached_columns > 0) {
+ if(cached_columns >= 0) {
return cached_columns;
}
+ if(!isatty(STDOUT_FILENO)) {
+ cached_columns = 0;
+ return 0;
+ }
+
e = getenv("COLUMNS");
if(e) {
c = strtol(e, NULL, 10);
--
2.0.1
More information about the pacman-dev
mailing list