向控制台输出添加文本装饰 [英] adding text decorations to console output
问题描述
我有一个c#.net 3.5应用程序,使用StreamWriter将文本写入控制台。有没有办法,我可以添加文本装饰,如下划线和删除线到打印到控制台的文本?可能使用ANSI转义序列?
I have a c# .net 3.5 application that writes text to the console using a StreamWriter. Is there a way I can add text decorations like underline and strikethrough to the text that is printed to the console? Possibly using ANSI escape sequences?
TextWriter writer = new StreamWriter(Console.OpenStandardOutput());
writer.WriteLine("some underlined text");
感谢您,
PaulH
Thanks, PaulH
推荐答案
Windows控制台不支持ANSI转义序列。据我所知,更改输出字符属性的唯一方法是在写入字符之前调用 SetConsoleTextAttribute
。或者,在.NET中,修改 Console.ForegroundColor
或 Console.BackgroundColor
属性。
The Windows console does not support ANSI escape sequences. To my knowledge, the only way to change the attributes of an output character is to call SetConsoleTextAttribute
before writing the character. Or, in .NET, modify the Console.ForegroundColor
or Console.BackgroundColor
attributes.
可以将这些属性设置为具有类型转换的自定义值(即,未由 ConsoleColor
定义的值)。但我不知道你会做什么好的。
It might be possible to set those properties to custom values (i.e. values not defined by ConsoleColor
) with a type cast. But I don't know what good that would do you.
我不知道我在Windows控制台上看到了删除文本,因为我看到下划线。我想这是可能的,但我不知道如何做。
I don't know that I've ever seen strikethrough text on a Windows console, and it's been years since I saw underline. I suppose it's possible, but I don't know how it's done.
这篇关于向控制台输出添加文本装饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!