Archive

Posts Tagged ‘ANSI, console’

Erlang R16支持带颜色的控制台

December 27th, 2013 6 comments

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

本文链接地址: 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.