libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

commit 5186a405fef4d365891e9ed28eb3d4a4c3c96cd1
parent 7eb7e3a3aa022076dd34d6449e8221fe506bdd66
Author: Frederic Cambus <fred@statdns.com>
Date:   Wed, 26 Sep 2018 10:34:56 +0200

Merge pull request #1 from jan2642/master

Add support for ANSI invert (7m & 27m)
Diffstat:
Msrc/loaders/ansi.c | 19++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -67,7 +67,7 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) int32_t background = 0, foreground = 7; // text attributes - bool bold = false, underline = false, italics = false, blink = false; + bool bold = false, underline = false, italics = false, blink = false, invert = false; // positions int32_t column = 0, row = 0, columnMax = 0, rowMax = 0; @@ -281,6 +281,7 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) underline = false; italics = false; blink = false; + invert = false; } if (seqValue == 1) { @@ -304,6 +305,12 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) blink = true; } + if (seqValue == 7) + invert = true; + + if (seqValue == 27) + invert = false; + if (seqValue > 29 && seqValue < 38) { foreground = seqValue - 30; @@ -367,8 +374,14 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) temp = realloc(ansi_buffer, (structIndex + 1) * sizeof (struct ansiChar)); ansi_buffer = temp; - ansi_buffer[structIndex].background = background; - ansi_buffer[structIndex].foreground = foreground; + if (invert) { + ansi_buffer[structIndex].background = foreground % 8; + ansi_buffer[structIndex].foreground = background + (foreground & 8); + } + else { + ansi_buffer[structIndex].background = background; + ansi_buffer[structIndex].foreground = foreground; + } ansi_buffer[structIndex].current_character = current_character; ansi_buffer[structIndex].bold = bold; ansi_buffer[structIndex].italics = italics;