[Proposal]: String/Character escape sequence \e
as a short-hand for \u001b
(<ESCAPE>
) (VS 17.9, .NET 9)
#8656
Replies: 11 comments
-
Championing. Hoping to take as an exceedingly cheap change/QOL improvement to the language for console developers. |
Beta Was this translation helpful? Give feedback.
-
Wouldn't this be a breaking change? The meaning of any existing string containing I don't think it's a significant breaking change, but I thought this was worth mentioning. |
Beta Was this translation helpful? Give feedback.
-
Unrecognized escape sequences are illegal. It's safe to add new escape sequences. var s = "foo\ebar"; // error CS1009: Unrecognized escape sequence |
Beta Was this translation helpful? Give feedback.
-
I would def reject thsi if |
Beta Was this translation helpful? Give feedback.
-
Damnit @HaloFour :D |
Beta Was this translation helpful? Give feedback.
-
I stand corrected! Thanks @HaloFour and @CyrusNajmabadi. |
Beta Was this translation helpful? Give feedback.
-
The LDM has approved the proposed specification for implementation. The issue is in the Any Time milestone, which means that it is approved for community implementation if anyone wants to do so. The C# team itself is unlikely to dedicate time to implementing this ourselves. |
Beta Was this translation helpful? Give feedback.
-
@Unknown6656 if you want to work on an implementation here, i'm very happy to help out :) I can also do this myself, but i'm not sure when i'll have time for it. |
Beta Was this translation helpful? Give feedback.
-
Closing this issue, as it has been implemented by @CyrusNajmabadi and merged into roslyn's Minimal working example: https://sharplab.io/#v2:EYLgtghglgdgNAFxAJwK4wD4AECMA6XATgApjYEBKAcgB0BTKigbiA== : System.Console.WriteLine((int)'\e');
// output: "27" Thank you, @CyrusNajmabadi for all your work! ❤️ |
Beta Was this translation helpful? Give feedback.
-
Shouldn't the issue remain open until the specification work is complete? |
Beta Was this translation helpful? Give feedback.
-
@HaloFour ah fair enough, you're absolutely right! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Initial discussion: #7394
Initial approval: @CyrusNajmabadi
Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-13.0/esc-escape-sequence.md
String/Character escape sequence
\e
Summary
An addition of the string/character escape sequence
\e
as a shortcut/short-hand replacement for the character code point0x1b
, commonly known as theESCAPE
(orESC
) character. This character is currently accessible using one of the following escape sequences:\u001b
\U0000001b
\x1b
(not recommended, see the picture attached at the bottom.)With the implementation of this proposal, the following assertions should be true:
Motivation
Although the
System.Console
class exposes quite a few possibilities to interact with the Terminal, it by far does not support every functionalities or features. Predominant among these are 24bit color support, bold, italic, underlined, or blinking text, as well as a few other features.However, these can be emulated by printing (a series of) so-called VT100/ANSI escape codes to the
System.Console.Out
stream (A reference of ANSI escape sequences can be found in the section Attachments and References of this proposal). Each VT100 escape sequence starts with the character0x1b
(ASCIIESC
), followed by a series of characters, such as:which result in the following output in

wt.exe
andcmd.exe
:Due to the recurring usage
\u001b
, a shorter abbreviation such as\e
would be welcome. This is comparable to how\n
can be used as an abbreviation for\u000a
.A further motivation for this proposal is the recurrent usage of the sequence
\u001b
inside of ESC/POS commands when interacting with (thermal) printers, as e.g. referenced in the following documents and articles (thanks @jnm2 !):Detailed design
I propose the language syntax specification to be changed as follows in section 6.4.5.5:
As well as the addition of the last line to the following table in the specifications:
Drawbacks
Every new language feature request brings added complexity to the compiler. However, I shall argue that the implementation of this specific feature mainly involves variation of existing code concerning the parsing of existing escape sequences such as
\v
,\f
, or\a
. Furthermore, a certain complexity involves the adaptation of Roslyn's unit tests to accommodate this feature.Alternatives
The usage of the escape character
0x1b
can be implemented using traditional methods, amongst which are:\u001b
\U0000001b
\x1b
(not recommended, see the picture attached at the bottom.)$(char)0x1b
(char)0x1b
to a constant variable/field and its usage inside of interpolated strings instead of the direct utilization of the proposed sequence\e
.Unresolved questions
\x1b
,\u001b
, etc. towards\e
?Design meetings
Attachments and References
\x1b
instead of\u001b
:Beta Was this translation helpful? Give feedback.
All reactions