如何在 Scala 或 Java 的控制台输出中使用颜色?

发布于 2024-09-18 12:17:12 字数 36 浏览 2 评论 0原文

如何在 Scala 或 Java 的控制台输出中使用颜色?

How to use colours in console output in Scala or Java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无人接听 2024-09-25 12:17:12

尝试...

scala> Console.BLUE
res0: java.lang.String =

好吧,好吧,文字变成了蓝色。诚实的!

scala> Console.YELLOW_B
res2: java.lang.String =

你可以看到背景是,嗯,黄色。

Try...

scala> Console.BLUE
res0: java.lang.String =

OK, well, the text has gone blue. Honest!

scala> Console.YELLOW_B
res2: java.lang.String =

And you can see the background is, um, yellow.

萌吟 2024-09-25 12:17:12

只是为了扩展 oxbow_lakes 的答案:在 scala 2.9.2 解释器中,我必须显式打印蓝色字符串:

scala> println(Console.BLUE + " now it's really blue!")

Just to extend the answer from oxbow_lakes: in scala 2.9.2 interpreter I had to explicitly print the BLUE string:

scala> println(Console.BLUE + " now it's really blue!")
魔法唧唧 2024-09-25 12:17:12

示例代码来自 JavaWorld

import java.awt.Color;
import enigma.console.*;
import enigma.core.Enigma;
public class Main
{
    public static void main(String[] args)
    {
        TextAttributes attrs = new TextAttributes(Color.BLUE, Color.WHITE);
        s_console.setTextAttributes(attrs);
        System.out.println("Hello World!");
    }
    private static final Console s_console;
    static
    {
        s_console = Enigma.getConsole("Hellow World!");
    }
}

访问上面的内容链接以获取更多详细信息和方法。

Sample code from JavaWorld

import java.awt.Color;
import enigma.console.*;
import enigma.core.Enigma;
public class Main
{
    public static void main(String[] args)
    {
        TextAttributes attrs = new TextAttributes(Color.BLUE, Color.WHITE);
        s_console.setTextAttributes(attrs);
        System.out.println("Hello World!");
    }
    private static final Console s_console;
    static
    {
        s_console = Enigma.getConsole("Hellow World!");
    }
}

Visit the above link for more details and approaches.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文