degesch: simplify formatter_flush()
This commit is contained in:
parent
4013921de7
commit
1ff56bfe5a
34
degesch.c
34
degesch.c
|
@ -1109,32 +1109,30 @@ static void
|
||||||
formatter_flush (struct formatter *self, FILE *stream)
|
formatter_flush (struct formatter *self, FILE *stream)
|
||||||
{
|
{
|
||||||
terminal_printer_fn printer = get_attribute_printer (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);
|
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_attributed = false;
|
||||||
bool is_tty = isatty (fileno (stream));
|
|
||||||
LIST_FOR_EACH (struct formatter_item, iter, self->items)
|
LIST_FOR_EACH (struct formatter_item, iter, self->items)
|
||||||
{
|
{
|
||||||
switch (iter->type)
|
switch (iter->type)
|
||||||
{
|
{
|
||||||
|
char *term;
|
||||||
case FORMATTER_ITEM_TEXT:
|
case FORMATTER_ITEM_TEXT:
|
||||||
if (is_tty)
|
term = iconv_xstrdup
|
||||||
{
|
(self->ctx->term_from_utf8, iter->data, -1, NULL);
|
||||||
char *term = iconv_xstrdup
|
fputs (term, stream);
|
||||||
(self->ctx->term_from_utf8, iter->data, -1, NULL);
|
free (term);
|
||||||
fputs (term, stream);
|
|
||||||
free (term);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fputs (iter->data, stream);
|
|
||||||
break;
|
break;
|
||||||
case FORMATTER_ITEM_ATTR:
|
case FORMATTER_ITEM_ATTR:
|
||||||
if (!printer)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (is_attributed)
|
if (is_attributed)
|
||||||
{
|
{
|
||||||
tputs (attr_reset, 1, printer);
|
tputs (attr_reset, 1, printer);
|
||||||
|
@ -1147,16 +1145,10 @@ formatter_flush (struct formatter *self, FILE *stream)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FORMATTER_ITEM_FG_COLOR:
|
case FORMATTER_ITEM_FG_COLOR:
|
||||||
if (!printer)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
tputs (g_terminal.color_set_fg[iter->color], 1, printer);
|
tputs (g_terminal.color_set_fg[iter->color], 1, printer);
|
||||||
is_attributed = true;
|
is_attributed = true;
|
||||||
break;
|
break;
|
||||||
case FORMATTER_ITEM_BG_COLOR:
|
case FORMATTER_ITEM_BG_COLOR:
|
||||||
if (!printer)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
tputs (g_terminal.color_set_bg[iter->color], 1, printer);
|
tputs (g_terminal.color_set_bg[iter->color], 1, printer);
|
||||||
is_attributed = true;
|
is_attributed = true;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue