如何使用ansi代码为scala中的标准输出着色 [英] How to colorize the standard output in scala with ansi codes

查看:46
本文介绍了如何使用ansi代码为scala中的标准输出着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个 Scala 库可以帮助对写入标准输出的文本进行着色?

Is there a scala library that can help colorize text written to the standard output?

这个库应该利用 scala 字符串插值机制.

This library should take advantage of the scala string interpolation mechanic.

推荐答案

如果你使用的是 scala 2.11+ 你可以使用这个库:https://github.com/backuity/ansi-interpolator

If you're using scala 2.11+ you can use this library : https://github.com/backuity/ansi-interpolator

它使用宏在编译时转换字符串,并支持嵌套:

It uses a macro to transform your strings at compile time, and supports nesting:

ansi"Text containing ansi tags such as %bold{bold text} or %underline{can be %yellow{nested}}"

// you can also use string interpolation:
val someMsg = "hey"
ansi"My msg %bold{in bold: $someMsg}"

这篇关于如何使用ansi代码为scala中的标准输出着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆