Home > Erlang探索, 源码分析 > Erlang R16支持带颜色的控制台

Erlang R16支持带颜色的控制台

December 27th, 2013

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: Erlang R16支持带颜色的控制台

Erlang通过fix tty驱动的过滤,在R16版本支持带颜色的控制台,这个特性在我们做各种监控工具高亮非常有帮助,参见R16的Readme:

Support ANSI in console Unix platforms will no longer filter control sequences to the ttsl driver thus enabling ANSI and colors in console. (Thanks to Pedram Nimreezi)

应用程序方面已经有日志系统lager率先支持“Colored terminal output (requires R16+)”

我们来演示下:

$ erl
Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:16:16] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.3  (abort with ^G)
1> [io:fwrite("~s~s",[Level, Color])
1> ||
1> {Level, Color}<-
1> [
1> {debug,     "\e[0;38m" },
1> {info,      "\e[1;37m" },
1> {notice,    "\e[1;36m" },
1> {warning,   "\e[1;33m" },
1> {error,     "\e[1;31m" },
1> {critical,  "\e[1;35m" },
1> {alert,     "\e[1;44m" },
1> {emergency, "\e[1;41m" },
1> {eol,        "\e[0m\r\n"}
1> ]
1> ].
debuginfonoticewarningerrorcriticalalertemergencyeol
[ok,ok,ok,ok,ok,ok,ok,ok,ok]
2> 

效果如下图:erlang-color

祝玩得开心。

Post Footer automatically generated by wp-posturl plugin for wordpress.

  1. harveyzh
    December 28th, 2013 at 00:01 | #1

    请问,这个配置能在 erl 启动时,自动加载吗?

    Yu Feng Reply:

    当然呀

  2. KDr2
    January 15th, 2014 at 09:37 | #2

    打扰问个主题不相关的问题,现在 tv, appmon 貌似被移除了? 取代的他们的是什么呢?

    Yu Feng Reply:

    tv和appmon用的图像界面是gs, 目前要废掉gs,替代品是wx图像. 而tv,appmon都会被改写。

    KDr2 Reply:

    IRC问到了, 是 observer 😀

  3. calvin
    July 16th, 2015 at 15:38 | #3

    请问下,写入到文件里面的可有有颜色吗?

Comments are closed.