繁体   English   中英

使用 Console.WriteLine (C#) 或 printfn (F#) 编写粗体文本?

[英]Write boldface text using Console.WriteLine (C#) or printfn (F#)?

有没有使用Console.WriteLine ( C# ) 或printfn ( F# ) 编写粗体文本的快速方法?

如果不是粗体,也许是其他类型的视觉差异化因素,比如带下划线的文字?

您可以设置Console.ForegroundColor 单击链接,MSDN中提供了一个非常好的示例。

字体和样式不是基于每个单词提供的。 要获得粗体,斜体,下划线或大小,您必须更改控制台中的所有文本。

Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Test Text");

Console.ForegroundColor = ConsoleColor.Blue;
Console.BackgroundColor = ConsoleColor.White;
Console.WriteLine("Test Text 2");

Console.ResetColor(); // To return colors back

查看 Manuel Riezebosch 的图书馆https://github.com/riezebosch/Crayon 该库使用 ANSI 代码使粗体、下划线、反转、暗淡装饰器在控制台 output 上工作。

using static Crayon.Output;

Console.WriteLine(Green($"green {Red($"{Bold("bold")} red")} green"));
Console.WriteLine(Bold().Green().Text($"starting green {Red("then red")} must be green again"));

需要注意的一点是,虽然 ANSI 代码可以直接在 Linux 和 Mac 终端上运行,但在 Windows 10 上需要明确启用,这是由库完成的。 https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM