mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 14:40:22 +00:00
logger: remove ANSI seqences if not terminal
This allows use of raw ANSI sequences instead of the rang stuff.
This commit is contained in:
@@ -276,6 +276,10 @@ public:
|
||||
|
||||
std::string msg = oss.str();
|
||||
|
||||
if (!get_log_output().is_interactive()) {
|
||||
msg = prune_ansi_sequences_str(msg.c_str());
|
||||
}
|
||||
|
||||
auto buf = get_log_output().get_buffer();
|
||||
buf.append(msg);
|
||||
buf.submit();
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "utils/color_out.h"
|
||||
|
||||
using std::cout;
|
||||
using std::string;
|
||||
|
||||
static bool color_stdout;
|
||||
|
||||
@@ -180,7 +181,8 @@ bool color_output_init() {
|
||||
return color_stdout;
|
||||
}
|
||||
|
||||
static int prune_ansi_sequences(const char *in, char *out) {
|
||||
template<class OutputIt>
|
||||
static int prune_ansi_sequences(const char *in, OutputIt out) {
|
||||
char c = *in;
|
||||
bool in_control = false;
|
||||
int written = 0;
|
||||
@@ -207,6 +209,12 @@ static int prune_ansi_sequences(const char *in, char *out) {
|
||||
return written;
|
||||
}
|
||||
|
||||
string prune_ansi_sequences_str(const char *in) {
|
||||
string out;
|
||||
prune_ansi_sequences(in, std::back_inserter(out));
|
||||
return out;
|
||||
}
|
||||
|
||||
int color_printf(const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
@@ -114,6 +114,10 @@ bool isMsysPty(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
std::string prune_ansi_sequences_str(const char *in);
|
||||
|
||||
/**
|
||||
* Class wrapping color output to terminal. Sample usage:
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user