1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Don't display animations if running without a terminal.

Fix for #156.
This commit is contained in:
Cedric Beust 2016-03-19 14:01:30 -07:00
parent 23e161c2c2
commit 1a65058a26

View file

@ -370,9 +370,14 @@ public class Main {
int bytesRead; int bytesRead;
long bytesSoFar = 0; long bytesSoFar = 0;
byte[] buffer = new byte[100_000]; byte[] buffer = new byte[100_000];
boolean hasTerminal = System.console() != null;
if (! hasTerminal) {
log2(1, "\rDownloading " + url);
}
while ((bytesRead = inputStream.read(buffer)) != -1) { while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead); outputStream.write(buffer, 0, bytesRead);
bytesSoFar += bytesRead; bytesSoFar += bytesRead;
if (hasTerminal) {
if (bytesRead > 0) { if (bytesRead > 0) {
if (contentLength > 0) { if (contentLength > 0) {
float percent = bytesSoFar * 100 / contentLength; float percent = bytesSoFar * 100 / contentLength;
@ -382,6 +387,7 @@ public class Main {
} }
} }
} }
}
log2(1, "\n"); log2(1, "\n");
} }