mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 23:02:27 +00:00
Logger: Add method for writing to stdout
Usually this just writes to stdout, but for ProgressBar, we need to
clear the current line, write the line to stdout, and then redraw the
progress bar.
(cherry picked from commit 696c026006
)
This commit is contained in:
parent
fcd048a526
commit
67a5941472
@ -3,6 +3,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace nix {
|
||||
|
||||
@ -24,6 +25,11 @@ void Logger::warn(const std::string & msg)
|
||||
log(lvlWarn, ANSI_YELLOW "warning:" ANSI_NORMAL " " + msg);
|
||||
}
|
||||
|
||||
void Logger::writeToStdout(std::string_view s)
|
||||
{
|
||||
std::cout << s << "\n";
|
||||
}
|
||||
|
||||
class SimpleLogger : public Logger
|
||||
{
|
||||
public:
|
||||
|
@ -78,6 +78,16 @@ public:
|
||||
virtual void stopActivity(ActivityId act) { };
|
||||
|
||||
virtual void result(ActivityId act, ResultType type, const Fields & fields) { };
|
||||
|
||||
virtual void writeToStdout(std::string_view s);
|
||||
|
||||
template<typename... Args>
|
||||
inline void stdout(const std::string & fs, const Args & ... args)
|
||||
{
|
||||
boost::format f(fs);
|
||||
formatHelper(f, args...);
|
||||
writeToStdout(f.str());
|
||||
}
|
||||
};
|
||||
|
||||
ActivityId getCurActivity();
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
namespace nix {
|
||||
|
||||
@ -442,6 +443,18 @@ public:
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void writeToStdout(std::string_view s) override
|
||||
{
|
||||
auto state(state_.lock());
|
||||
if (state->active) {
|
||||
std::cerr << "\r\e[K";
|
||||
Logger::writeToStdout(s);
|
||||
draw(*state);
|
||||
} else {
|
||||
Logger::writeToStdout(s);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void startProgressBar(bool printBuildLogs)
|
||||
|
Loading…
Reference in New Issue
Block a user