[erlang-patches] Support ANSI in the console

Pedram Nimreezi mc@REDACTED
Wed Nov 14 14:49:24 CET 2012


The ttsl driver strips ANSI escape sequences from the console.

This commit addresses that and allows for them to be supported.
        https://github.com/DeadZen/otp/compare/maint...ansi-console
        https://github.com/DeadZen/otp/compare/maint...ansi-console.patch

git fetch git://github.com/DeadZen/otp.git ansi-console

Supplemental Note...
  This has been tested, used and abused for nearly a year, and should
apply cleanly to the last few major versions

Initially the patch was simply:
--- a/erts/emulator/drivers/unix/ttsl_drv.c	2011-05-24 07:16:43.000000000 -0400
+++ b/erts/emulator/drivers/unix/ttsl_drv.c	2011-12-10 14:24:23.000000000 -0500
@@ -912,6 +912,15 @@ static int insert_buf(byte *s, int n)
 		lbuf[lpos++] = (CONTROL_TAG | ((Uint32) ch));
 		ch = 0;
 	    } while (lpos % 8);
+	} else if (ch == '\e') {
+	    write_buf(lbuf + buffpos, lpos - buffpos);
+	    outc('\e');
+
+	    if (llen > lpos) {
+		memcpy(lbuf, lbuf + lpos, llen - lpos);
+	    }
+	    llen -= lpos;
+	    lpos = buffpos = 0;	


Recently I've compared various approaches, however, and decided to
push my patch and findings...

For instance I've compared this change to allowing for the ''\e"
control character 27 to these locations:

https://github.com/DeadZen/otp/blob/d3e3d51dbb21f0fdb125becacb80e34d0565fff7/erts/emulator/drivers/unix/ttsl_drv.c#L901
https://github.com/DeadZen/otp/blob/d3e3d51dbb21f0fdb125becacb80e34d0565fff7/erts/emulator/drivers/unix/ttsl_drv.c#L599
https://github.com/DeadZen/otp/blob/d3e3d51dbb21f0fdb125becacb80e34d0565fff7/erts/emulator/drivers/unix/ttsl_drv.c#L609

but believe, the "console display control characters" section and the
smallest possible change would be here:

https://github.com/DeadZen/otp/blob/d3e3d51dbb21f0fdb125becacb80e34d0565fff7/erts/emulator/drivers/unix/ttsl_drv.c#L915

I have thoroughly tested, including using a forked copy of the lager
application at high speed for extended durations here:
git fetch git://github.com/DeadZen/lager.git colors

For this patch I've reduced the affected lines to the smallest degree
I believe possible. Thank you.


-- 
/* Sincerely
--------------------------------------------------------------
Pedram Nimreezi - Chief Technology Officer  */

// The hardest part of design … is keeping features out. - Donald Norman



More information about the erlang-patches mailing list