From 1ff56bfe5a521a148e58bb64c89de9f1e0b01a25 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 28 Apr 2015 17:25:50 +0200
Subject: degesch: simplify formatter_flush()
---
degesch.c | 34 +++++++++++++---------------------
1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/degesch.c b/degesch.c
index 274f437..19bdcfb 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1109,32 +1109,30 @@ static void
formatter_flush (struct formatter *self, FILE *stream)
{
terminal_printer_fn printer = get_attribute_printer (stream);
+ if (!printer)
+ {
+ LIST_FOR_EACH (struct formatter_item, iter, self->items)
+ if (iter->type == FORMATTER_ITEM_TEXT)
+ fputs (iter->data, stream);
+ return;
+ }
const char *attr_reset = str_map_find (&self->ctx->config, ATTR_RESET);
- if (printer)
- tputs (attr_reset, 1, printer);
+ tputs (attr_reset, 1, printer);
bool is_attributed = false;
- bool is_tty = isatty (fileno (stream));
LIST_FOR_EACH (struct formatter_item, iter, self->items)
{
switch (iter->type)
{
+ char *term;
case FORMATTER_ITEM_TEXT:
- if (is_tty)
- {
- char *term = iconv_xstrdup
- (self->ctx->term_from_utf8, iter->data, -1, NULL);
- fputs (term, stream);
- free (term);
- }
- else
- fputs (iter->data, stream);
+ term = iconv_xstrdup
+ (self->ctx->term_from_utf8, iter->data, -1, NULL);
+ fputs (term, stream);
+ free (term);
break;
case FORMATTER_ITEM_ATTR:
- if (!printer)
- continue;
-
if (is_attributed)
{
tputs (attr_reset, 1, printer);
@@ -1147,16 +1145,10 @@ formatter_flush (struct formatter *self, FILE *stream)
}
break;
case FORMATTER_ITEM_FG_COLOR:
- if (!printer)
- continue;
-
tputs (g_terminal.color_set_fg[iter->color], 1, printer);
is_attributed = true;
break;
case FORMATTER_ITEM_BG_COLOR:
- if (!printer)
- continue;
-
tputs (g_terminal.color_set_bg[iter->color], 1, printer);
is_attributed = true;
break;
--
cgit v1.2.3-70-g09d2