summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-28 17:25:50 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-28 23:40:49 +0200
commit1ff56bfe5a521a148e58bb64c89de9f1e0b01a25 (patch)
tree465d68cc488e4eed439dc2986c7c3f7ead6bb729
parent4013921de777a455cd152752c78671db8f0062fa (diff)
downloadxK-1ff56bfe5a521a148e58bb64c89de9f1e0b01a25.tar.gz
xK-1ff56bfe5a521a148e58bb64c89de9f1e0b01a25.tar.xz
xK-1ff56bfe5a521a148e58bb64c89de9f1e0b01a25.zip
degesch: simplify formatter_flush()
-rw-r--r--degesch.c34
1 files 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;