gpt4 book ai didi

colors - 如何在 flutter 中调用带有彩色文本的 print() 到 android studio 控制台

转载 作者:IT老高 更新时间:2023-10-28 12:35:03 30 4
gpt4 key购买 nike

我需要一个带有彩色字符串的调试输出,比如 node.js 粉笔。

我试图找到包,但没有合适的包。

最佳答案

虽然这在 Android Studio 中不起作用,但它是 supported in VS Code :

enter image description here

void main() {
print('This is a normal message.');
printWarning('This is a warning.');
printError('This is an error.');
}

void printWarning(String text) {
print('\x1B[33m$text\x1B[0m');
}

void printError(String text) {
print('\x1B[31m$text\x1B[0m');
}

ANSI转义码说明

如果您不熟悉格式,ANSI 转义码字符串会非常令人困惑。

enter image description here

这里是把Hello变成红色的字符串:

\x1B[31mHello\x1B[0m

为了清晰起见,这里又添加了空格:

\x1B  [31m  Hello  \x1B  [0m

意思:

  • \x1B:ANSI 转义序列起始标记
  • [31m:红色的转义序列
  • [0m:用于重置的转义序列(停止使文本变为红色)

以下是其他颜色:

Black:   \x1B[30m
Red: \x1B[31m
Green: \x1B[32m
Yellow: \x1B[33m
Blue: \x1B[34m
Magenta: \x1B[35m
Cyan: \x1B[36m
White: \x1B[37m
Reset: \x1B[0m

通过这些链接了解更多信息:

关于colors - 如何在 flutter 中调用带有彩色文本的 print() 到 android studio 控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54018071/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com