aboutsummaryrefslogtreecommitdiff
path: root/works/life/computer-network-experiment/Output.h
diff options
context:
space:
mode:
Diffstat (limited to 'works/life/computer-network-experiment/Output.h')
-rw-r--r--works/life/computer-network-experiment/Output.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/works/life/computer-network-experiment/Output.h b/works/life/computer-network-experiment/Output.h
index 22b913a..2d16eb0 100644
--- a/works/life/computer-network-experiment/Output.h
+++ b/works/life/computer-network-experiment/Output.h
@@ -3,19 +3,28 @@
#include "StringUtil.hpp"
#include <fmt/format.h>
+#include <folly/CancellationToken.h>
#include <folly/MPMCPipeline.h>
#include <folly/MPMCQueue.h>
-#include <folly/CancellationToken.h>
-#include <thread>
#include <iostream>
+#include <thread>
enum class OutputType { Normal, Error };
+enum class OutputColor { Normal, Green, Red, Yellow };
struct Output {
Output() = default;
Output(String message, OutputType type = OutputType::Normal)
- : message(std::move(message)), type(type) {}
+ : message(std::move(message)), type(type),
+ color(type == OutputType::Error ? OutputColor::Red
+ : OutputColor::Normal) {}
+
+ Output(String message, OutputColor color)
+ : message(std::move(message)), type(OutputType::Normal), color(color) {}
+
+ Output(String message, OutputType type, OutputColor color)
+ : message(std::move(message)), type(type), color(color) {}
CRU_DEFAULT_COPY(Output)
CRU_DEFAULT_MOVE(Output)
@@ -23,6 +32,7 @@ struct Output {
String message;
OutputType type;
+ OutputColor color;
};
extern folly::MPMCQueue<Output> output_queue;
@@ -43,6 +53,12 @@ void SendOutput(OutputType type, StringView format, Args &&...args) {
Output{fmt::format(format, std::forward<Args>(args)...), type});
}
+template <typename... Args>
+void SendOutput(OutputColor color, StringView format, Args &&...args) {
+ output_queue.blockingWrite(
+ Output{fmt::format(format, std::forward<Args>(args)...), color});
+}
+
void OutputThread();
void SignalAndWaitForOutputThreadStop();