您可以自定义@info 颜色吗?

Can you have custom @info colors?

在 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 不容易实现,我将不得不创建自己的打印功能?

你可以自己写

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

现在: