From c9c7075dc116c4fc6813a1120c21339f7aebaf25 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Tue, 22 Sep 2009 20:43:06 +0200 Subject: [PATCH] Don't print text as columns when the output is not a tty The code also makes sure to terminate with a newline, unless the output is empty. --- Library/Homebrew/utils.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 7658e35cbe..3efeb99a6c 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -76,8 +76,13 @@ end def puts_columns items, cols = 4 items = items.join("\n") if items.is_a?(Array) - width=`stty size`.chomp.split(" ").last - IO.popen("pr -#{cols} -t", "w"){|io| io.write(items) } + items.concat("\n") unless items.empty? + if $stdout.tty? + width=`stty size`.chomp.split(" ").last + IO.popen("pr -#{cols} -t", "w"){|io| io.write(items) } + else + items.each { |i| $stdout.write(i) } + end end def exec_editor *args