summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-06 19:00:34 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-06 19:00:34 -0500
commitfb60761c469f3b144e741cef14762a5b6a037112 (patch)
tree6f40a8683d2d3a89ec0c77e3cef65f86af379d78 /util
parentc05569d223d5bda4390f1c501dc5915149617c93 (diff)
downloadhorizon-fb60761c469f3b144e741cef14762a5b6a037112.tar.gz
horizon-fb60761c469f3b144e741cef14762a5b6a037112.tar.bz2
horizon-fb60761c469f3b144e741cef14762a5b6a037112.tar.xz
horizon-fb60761c469f3b144e741cef14762a5b6a037112.zip
Add some pretty handlers and use them
Diffstat (limited to 'util')
-rw-r--r--util/output.hh28
1 files changed, 25 insertions, 3 deletions
diff --git a/util/output.hh b/util/output.hh
index ac356bc..f4f939f 100644
--- a/util/output.hh
+++ b/util/output.hh
@@ -16,6 +16,28 @@
#include <string>
#include <iostream>
+/*! Bolds output on +stream+ if it's a TTY.
+ * @param pretty Whether to act.
+ * @param stream The stream to turn bold.
+ */
+inline void bold_if_pretty(bool pretty, std::ostream &stream) {
+ if(pretty) stream << "\033[0;1m";
+}
+
+/*! ANSI colour code on +stream+ if +pretty+.
+ * @param pretty Whether to act.
+ * @param stream The stream on which to colourise output.
+ * @param what The colour code.
+ */
+inline void colour_if_pretty(bool pretty, std::ostream &stream,
+ std::string what) {
+ if(pretty) stream << "\033[" + what + ";1m";
+}
+
+inline void reset_if_pretty(bool pretty, std::ostream &stream) {
+ if(pretty) stream << "\033[0m";
+}
+
/*! Outputs a message of the specified +type+ to the log stream.
* @param type The type of message to output.
* @param colour The colourisation of the message.
@@ -28,11 +50,11 @@ inline void output_message(std::string type, std::string colour,
std::string where, std::string message,
std::string detail = "", bool pretty = false) {
std::cerr << where << ": ";
- if(pretty) std::cerr << "\033[" + colour + ";1m";
+ colour_if_pretty(pretty, std::cerr, colour);
std::cerr << type << ": ";
- if(pretty) std::cerr << "\033[0;1m";
+ bold_if_pretty(pretty, std::cerr);
std::cerr << message;
- if(pretty) std::cerr << "\033[0m";
+ reset_if_pretty(pretty, std::cerr);
if(!detail.empty()) {
std::cerr << ": " << detail;
}