From 181baa9aa5480a18ccb1615877b6abc7b41a797c Mon Sep 17 00:00:00 2001 From: Keitaroh Kobayashi Date: Mon, 8 May 2023 18:26:56 +0900 Subject: [PATCH] Detect when stdout is a TTY, use regular line breaks instead of resetting the line when stdout is not a TTY --- src/read_pbf.cpp | 15 ++++++++++++--- src/tilemaker.cpp | 10 +++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/read_pbf.cpp b/src/read_pbf.cpp index aa61372c..f5599c03 100644 --- a/src/read_pbf.cpp +++ b/src/read_pbf.cpp @@ -226,6 +226,7 @@ bool PbfReader::ReadBlock(std::istream &infile, OsmLuaProcessing &output, std::p nodeKeyPositions.insert(findStringPosition(pb, it.c_str())); } + bool is_terminal = isatty(1); for (int i=0; i 10) interval = 10; if (zoom > 11) interval = 100; if (zoom > 12) interval = 1000; + if (zoom > 13) interval = 5000; + if (zoom > 14) interval = 10000; boost::asio::post(pool, [=, &tile_coordinates, &pool, &sharedData, &osmStore, &io_mutex, &tc, &zoomDisplay]() { std::size_t end_index = std::min(tile_coordinates.size(), start_index + interval); @@ -478,7 +481,12 @@ int main(int argc, char* argv[]) { unsigned int zoom = tile_coordinates[end_index-1].first; if (zoom>zoomDisplay) zoomDisplay = zoom; - cout << "Zoom level " << zoomDisplay << ", writing tile " << tc << " of " << tile_coordinates.size() << " \r" << std::flush; + cout << "Zoom level " << zoomDisplay << ", writing tile " << tc << " of " << tile_coordinates.size(); + if (is_terminal) + cout << " \r"; + else + cout << std::endl; + cout << std::flush; }); }