Output newlines for each progress indicator when not on a tty.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#ifndef ISATTY_HPP
|
||||
#define ISATTY_HPP
|
||||
|
||||
// For isatty()
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
#define isatty _isatty
|
||||
#define fileno _fileno
|
||||
#else
|
||||
#error Unknown platform - don't know which header to include for isatty()
|
||||
#endif // win32
|
||||
#endif // unix
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
// Returns true if stdout is a tty, false otherwise
|
||||
// Useful for when you want to do something different when
|
||||
// output is redirected to a logfile
|
||||
inline bool IsStdoutATTY() { return isatty(fileno(stdout)); }
|
||||
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
|
||||
#include "util/isatty.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
@@ -71,6 +73,12 @@ class Percent
|
||||
{
|
||||
std::cout << ".";
|
||||
}
|
||||
|
||||
// When not on a TTY, print newlines after each progress indicator so
|
||||
// so that progress is visible to line-buffered logging systems
|
||||
if (!IsStdoutATTY())
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout.flush();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user