From 868936626cd32590b697cc5ba0c67e032deabd38 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 7 Jun 2021 19:24:39 +0800 Subject: import(life): ... --- works/life/computer-network-experiment/Output.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'works/life/computer-network-experiment/Output.h') 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 +#include #include #include -#include -#include #include +#include 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_queue; @@ -43,6 +53,12 @@ void SendOutput(OutputType type, StringView format, Args &&...args) { Output{fmt::format(format, std::forward(args)...), type}); } +template +void SendOutput(OutputColor color, StringView format, Args &&...args) { + output_queue.blockingWrite( + Output{fmt::format(format, std::forward(args)...), color}); +} + void OutputThread(); void SignalAndWaitForOutputThreadStop(); -- cgit v1.2.3