From 1a65058a2683a71ccdb383ca7c7b7f7fc237fe80 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 19 Mar 2016 14:01:30 -0700 Subject: [PATCH] Don't display animations if running without a terminal. Fix for #156. --- .../java/com/beust/kobalt/wrapper/Main.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java index e26af232..be9d1760 100644 --- a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java +++ b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java @@ -370,15 +370,21 @@ public class Main { int bytesRead; long bytesSoFar = 0; byte[] buffer = new byte[100_000]; + boolean hasTerminal = System.console() != null; + if (! hasTerminal) { + log2(1, "\rDownloading " + url); + } while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); bytesSoFar += bytesRead; - if (bytesRead > 0) { - if (contentLength > 0) { - float percent = bytesSoFar * 100 / contentLength; - log2(1, "\rDownloading " + url + " " + percent + "%"); - } else { - log2(1, "."); + if (hasTerminal) { + if (bytesRead > 0) { + if (contentLength > 0) { + float percent = bytesSoFar * 100 / contentLength; + log2(1, "\rDownloading " + url + " " + percent + "%"); + } else { + log2(1, "."); + } } } }