A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/dotnet/csharplang/issues/7400 below:

String/Character escape sequence `\e` as a short-hand for `\u001b` (`<ESCAPE>`) (VS 17.9, .NET 9) · Issue #7400 · dotnet/csharplang · GitHub

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 point 0x1b, commonly known as the ESCAPE (or ESC) character. This character is currently accessible using one of the following escape sequences:

With the implementation of this proposal, the following assertions should be true:

char escape_char = '\e';

Assert.IsTrue(escape_char == (char)0x1b, "...");
Assert.IsTrue(escape_char == '\u001b', "...");
Assert.IsTrue(escape_char == '\U0000001b', "...");
Assert.IsTrue(escape_char == '\x1b', "...");
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 character 0x1b (ASCII ESC), followed by a series of characters, such as:

Console.WriteLine("This is a regular text");
Console.WriteLine("\u001b[1mThis is a bold text\u001b[0m");
Console.WriteLine("\u001b[2mThis is a dimmed text\u001b[0m");
Console.WriteLine("\u001b[3mThis is an italic text\u001b[0m");
Console.WriteLine("\u001b[4mThis is an underlined text\u001b[0m");
Console.WriteLine("\u001b[5mThis is a blinking text\u001b[0m");
Console.WriteLine("\u001b[6mThis is a fast blinking text\u001b[0m");
Console.WriteLine("\u001b[7mThis is an inverted text\u001b[0m");
Console.WriteLine("\u001b[8mThis is a hidden text\u001b[0m");
Console.WriteLine("\u001b[9mThis is a crossed-out text\u001b[0m");
Console.WriteLine("\u001b[21mThis is a double-underlined text\u001b[0m");
Console.WriteLine("\u001b[38;2;255;0;0mThis is a red text\u001b[0m");
Console.WriteLine("\u001b[48;2;0;255;0mThis is a green background\u001b[0m");
Console.WriteLine("\u001b[38;2;0;0;255;48;2;255;255;0mThis is a blue text with a yellow background\u001b[0m");

which result in the following output in wt.exe and cmd.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:

fragment Simple_Escape_Sequence
-    : '\\\'' | '\\"' | '\\\\' | '\\0' | '\\a' | '\\b' | '\\f' | '\\n' | '\\r' | '\\t' | '\\v'
+    : '\\\'' | '\\"' | '\\\\' | '\\0' | '\\a' | '\\b' | '\\f' | '\\n' | '\\r' | '\\t' | '\\v' | '\\e'
    ;

As well as the addition of the last line to the following table in the specifications:

A simple escape sequence represents a Unicode character, as described in the table below.

Escape sequence Character name Unicode code point \' Single quote U+0027 ... ... ... \e Escape character U+001B

The type of a Character_Literal is char.

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:

Unresolved questions Design meetings Attachments and References

bernd5, CyrusNajmabadi, IS4Code, jnm2, ladipro and 16 morejnm2, Rekkonnect and SommerEngineeringRekkonnect and SommerEngineering


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4