Real-time progress report

This commit is almost identical to the reverted
60b907c87f693e3e4ce2cc91aa10d9125cfe441e, but it tries to avoid high CPU load
by not printing every line.