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,15 +370,21 @@ 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 (bytesRead > 0) { if (hasTerminal) {
if (contentLength > 0) { if (bytesRead > 0) {
float percent = bytesSoFar * 100 / contentLength; if (contentLength > 0) {
log2(1, "\rDownloading " + url + " " + percent + "%"); float percent = bytesSoFar * 100 / contentLength;
} else { log2(1, "\rDownloading " + url + " " + percent + "%");
log2(1, "."); } else {
log2(1, ".");
}
} }
} }
} }