【问题标题】:Can you have custom @info colors?你可以自定义@info 颜色吗?
【发布时间】:2021-04-26 04:12:52
【问题描述】:

在 Julia 中,我有一个需要进行很多计算的项目。接下来是它的外观的一小部分:

[ Info: Benders Solving with subtour constraints ---  ./Instances/tiny_instance_10.txt  ---
[ Info: Spent 0.039s in Benders decomposition
[ Info: Spent 0.035s in Master problem
[ Info: Spent 0.004s in subproblem
Objective : 47.80267061445823
[ Info: 4 Optimality Constraints created
[ Info: 4 Subtour Constraints created
[ Info: MILP Creating Model ---  ./Instances/tiny_instance_10.txt  ---

我主要使用@info在控制台输出数据。 [ Info: 是蓝绿色的,很好,我想知道是否有一种方便的方法可以得到其他颜色?考虑到我有很多带有@info 的行要打印,这会更好阅读。

类似:@info red "MyString"?

我在Julia documentation 中找不到。

我相信如果@info 不容易实现,我将不得不创建自己的打印功能?

【问题讨论】:

标签: string console output julia


【解决方案1】:

你可以自己写

macro myinfo(color, what)
    quote
        printstyled($what,color=$color)
    end
end

现在:

【讨论】:

    猜你喜欢
    • 2021-09-21
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多