1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -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,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, ".");
}
}
}
}