diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2016-10-29 18:02:03 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2016-10-29 18:07:28 +0200 |
commit | 37e49b54cf50291c27262b74f608c33ad0e8c7fa (patch) | |
tree | 46f9bc5894ac480abf19dcaf7cb39c5305634646 /degesch.c | |
parent | 742d590b8ddd0ae13b2fbce50e96fcfa57cd088d (diff) | |
download | xK-37e49b54cf50291c27262b74f608c33ad0e8c7fa.tar.gz xK-37e49b54cf50291c27262b74f608c33ad0e8c7fa.tar.xz xK-37e49b54cf50291c27262b74f608c33ad0e8c7fa.zip |
degesch: rename things around terminal attributes
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 84 |
1 files changed, 41 insertions, 43 deletions
@@ -18,7 +18,6 @@ */ // A table of all attributes we use for output -// FIXME: awful naming, collides with ATTRIBUTE_* #define ATTR_TABLE(XX) \ XX( PROMPT, "prompt", "Terminal attrs for the prompt" ) \ XX( RESET, "reset", "String to reset terminal attributes" ) \ @@ -2785,24 +2784,24 @@ init_colors (struct app_context *ctx) enum { - ATTRIBUTE_BOLD = 1 << 0, - ATTRIBUTE_ITALIC = 1 << 1, - ATTRIBUTE_UNDERLINE = 1 << 2, - ATTRIBUTE_INVERSE = 1 << 3, - ATTRIBUTE_BLINK = 1 << 4 + TEXT_BOLD = 1 << 0, + TEXT_ITALIC = 1 << 1, + TEXT_UNDERLINE = 1 << 2, + TEXT_INVERSE = 1 << 3, + TEXT_BLINK = 1 << 4 }; -struct attribute_printer +struct attr_printer { char **attrs; ///< Named attributes FILE *stream; ///< Output stream bool dirty; ///< Attributes are set }; -#define ATTRIBUTE_PRINTER_INIT(ctx, stream) { ctx->attrs, stream, true } +#define ATTR_PRINTER_INIT(ctx, stream) { ctx->attrs, stream, true } static void -attribute_printer_tputs (struct attribute_printer *self, const char *attr) +attr_printer_tputs (struct attr_printer *self, const char *attr) { terminal_printer_fn printer = get_attribute_printer (self->stream); if (printer) @@ -2814,21 +2813,21 @@ attribute_printer_tputs (struct attribute_printer *self, const char *attr) } static void -attribute_printer_reset (struct attribute_printer *self) +attr_printer_reset (struct attr_printer *self) { if (self->dirty) - attribute_printer_tputs (self, self->attrs[ATTR_RESET]); + attr_printer_tputs (self, self->attrs[ATTR_RESET]); self->dirty = false; } static void -attribute_printer_apply_named (struct attribute_printer *self, int attribute) +attr_printer_apply_named (struct attr_printer *self, int attribute) { - attribute_printer_reset (self); + attr_printer_reset (self); if (attribute != ATTR_RESET) { - attribute_printer_tputs (self, self->attrs[attribute]); + attr_printer_tputs (self, self->attrs[attribute]); self->dirty = true; } } @@ -2841,7 +2840,7 @@ attribute_printer_apply_named (struct attribute_printer *self, int attribute) /// Interpolate from the 256-color palette to the 88-color one static int -attribute_printer_256_to_88 (int color) +attr_printer_256_to_88 (int color) { // These colours are the same everywhere if (color < 16) @@ -2861,7 +2860,7 @@ attribute_printer_256_to_88 (int color) } static int -attribute_printer_decode_color (int color, bool *is_bright) +attr_printer_decode_color (int color, bool *is_bright) { int16_t c16 = color; hard_assert (c16 < 16); int16_t c256 = color >> 16; hard_assert (c256 < 256); @@ -2879,7 +2878,7 @@ attribute_printer_decode_color (int color, bool *is_bright) return c16; case 88: - return c256 <= 0 ? c16 : attribute_printer_256_to_88 (c256); + return c256 <= 0 ? c16 : attr_printer_256_to_88 (c256); case 256: return c256 <= 0 ? c16 : c256; @@ -2890,15 +2889,15 @@ attribute_printer_decode_color (int color, bool *is_bright) } static void -attribute_printer_apply (struct attribute_printer *self, - int attributes, int want_fg, int want_bg) +attr_printer_apply (struct attr_printer *self, + int text_attrs, int wanted_fg, int wanted_bg) { bool fg_is_bright; - int fg = attribute_printer_decode_color (want_fg, &fg_is_bright); + int fg = attr_printer_decode_color (wanted_fg, &fg_is_bright); bool bg_is_bright; - int bg = attribute_printer_decode_color (want_bg, &bg_is_bright); + int bg = attr_printer_decode_color (wanted_bg, &bg_is_bright); - bool have_inverse = !!(attributes & ATTRIBUTE_INVERSE); + bool have_inverse = !!(text_attrs & TEXT_INVERSE); if (have_inverse) { bool tmp = fg_is_bright; @@ -2913,41 +2912,41 @@ attribute_printer_apply (struct attribute_printer *self, // to be, and we still can't make both colours bright, so it's more of // an interesting hack rather than anything else. if (!fg_is_bright && bg_is_bright && have_inverse) - attributes |= ATTRIBUTE_BOLD; + text_attrs |= TEXT_BOLD; else if (!fg_is_bright && bg_is_bright && !have_inverse && fg >= 0 && bg >= 0) { // As long as none of the colours is the default, we can swap them int tmp = fg; fg = bg; bg = tmp; - attributes |= ATTRIBUTE_BOLD | ATTRIBUTE_INVERSE; + text_attrs |= TEXT_BOLD | TEXT_INVERSE; } else { // This is what works on normal, decent terminals - if (fg_is_bright) attributes |= ATTRIBUTE_BOLD; - if (bg_is_bright) attributes |= ATTRIBUTE_BLINK; + if (fg_is_bright) text_attrs |= TEXT_BOLD; + if (bg_is_bright) text_attrs |= TEXT_BLINK; } - attribute_printer_reset (self); + attr_printer_reset (self); - if (attributes) - attribute_printer_tputs (self, tparm (set_attributes, + if (text_attrs) + attr_printer_tputs (self, tparm (set_attributes, 0, // standout - attributes & ATTRIBUTE_UNDERLINE, - attributes & ATTRIBUTE_INVERSE, - attributes & ATTRIBUTE_BLINK, + text_attrs & TEXT_UNDERLINE, + text_attrs & TEXT_INVERSE, + text_attrs & TEXT_BLINK, 0, // dim - attributes & ATTRIBUTE_BOLD, + text_attrs & TEXT_BOLD, 0, // blank 0, // protect 0)); // acs - if (enter_italics_mode && (attributes & ATTRIBUTE_ITALIC)) - attribute_printer_tputs (self, enter_italics_mode); + if (enter_italics_mode && (text_attrs & TEXT_ITALIC)) + attr_printer_tputs (self, enter_italics_mode); if (fg >= 0) - attribute_printer_tputs (self, g_terminal.color_set_fg[fg]); + attr_printer_tputs (self, g_terminal.color_set_fg[fg]); if (bg >= 0) - attribute_printer_tputs (self, g_terminal.color_set_bg[bg]); + attr_printer_tputs (self, g_terminal.color_set_bg[bg]); self->dirty = true; } @@ -3114,7 +3113,7 @@ formatter_add_item (struct formatter *self, struct formatter_item template_) #define FORMATTER_ADD_TEXT(self, text_) \ FORMATTER_ADD_ITEM ((self), TEXT, .text = (text_)) #define FORMATTER_ADD_SIMPLE(self, attribute_) \ - FORMATTER_ADD_ITEM ((self), SIMPLE, .attribute = ATTRIBUTE_ ## attribute_) + FORMATTER_ADD_ITEM ((self), SIMPLE, .attribute = TEXT_ ## attribute_) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3703,7 +3702,7 @@ formatter_flush (struct formatter *self, FILE *stream, int flush_opts) if (self->ctx->word_wrapping && !(flush_opts & FLUSH_OPT_NOWRAP)) line = line_wrap (line, g_terminal.columns); - struct attribute_printer state = ATTRIBUTE_PRINTER_INIT (self->ctx, stream); + struct attr_printer state = ATTR_PRINTER_INIT (self->ctx, stream); struct line_char_attrs attrs = {}; // Won't compare equal to anything LIST_FOR_EACH (struct line_char, c, line) { @@ -3714,16 +3713,15 @@ formatter_flush (struct formatter *self, FILE *stream, int flush_opts) { attrs = c->attrs; if (attrs.named != -1) - attribute_printer_apply_named (&state, attrs.named); + attr_printer_apply_named (&state, attrs.named); else - attribute_printer_apply (&state, - attrs.text, attrs.fg, attrs.bg); + attr_printer_apply (&state, attrs.text, attrs.fg, attrs.bg); } fwrite (c->bytes, c->len, 1, stream); free (c); } - attribute_printer_reset (&state); + attr_printer_reset (&state); } // --- Buffers ----------------------------------------------------------------- |