aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--atascii.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/atascii.c b/atascii.c
index d1d1243..19d7404 100644
--- a/atascii.c
+++ b/atascii.c
@@ -3,6 +3,36 @@
const char *atascii_inverse_on = "\x1b[7m";
const char *atascii_inverse_off = "\x1b[27m";
+/* only called in magazine mode. cursor control characters
+ like a bell in the middle of a non-inverse string
+ should not cause it to print {inv}{bell}{norm}. The {bell}
+ is "inherently" inverse (since its high bit is set) but doesn't
+ need to be printed that way. */
+static int affects_inv(int c) {
+ switch(c) {
+ case 0x1b: /* esc */
+ case 0x1c: /* up */
+ case 0x1d: /* down */
+ case 0x1e: /* left */
+ case 0x1f: /* right */
+ case 0x9b: /* EOL */
+ case 0x9c: /* del line */
+ case 0x9d: /* ins line */
+ case 0x9e: /* clear tab */
+ case 0x9f: /* set tab */
+ case 0x7d: /* cls */
+ case 0x7e: /* BS */
+ case 0x7f: /* tab */
+ case 0xfd: /* bell */
+ case 0xfe: /* del chr */
+ case 0xff: /* ins chr */
+ return 0;
+ default:
+ return 1;
+ }
+}
+
+
int atascii_context_init(atascii_ctx *ctx, int mode, int flags) {
memset(ctx, 0, sizeof(atascii_ctx));
@@ -64,20 +94,26 @@ char *atascii_a2utf(atascii_ctx *ctx, int src, char *dest) {
sequence, and one "inverse off" afterwards. */
if(src & 0x80) {
if(!ctx->inv) {
- ctx->inv = 1;
if(ctx->mode == ATA_MODE_MAGAZINE) {
- strcpy(dest, "{inv}");
+ if(affects_inv(src)) {
+ strcpy(dest, "{inv}");
+ ctx->inv = 1;
+ }
} else {
strcpy(dest, atascii_inverse_on);
+ ctx->inv = 1;
}
}
} else {
if(ctx->inv) {
- ctx->inv = 0;
if(ctx->mode == ATA_MODE_MAGAZINE) {
- strcpy(dest, "{norm}");
+ if(affects_inv(src)) {
+ strcpy(dest, "{norm}");
+ ctx->inv = 0;
+ }
} else {
strcpy(dest, atascii_inverse_off);
+ ctx->inv = 0;
}
}
}