Skip to content

Commit

Permalink
Add ConsoleKey.None and ConsoleModifiers.None (dotnet#83114)
Browse files Browse the repository at this point in the history
This fixes dotnet#79868.
  • Loading branch information
terrajobst authored Mar 8, 2023
1 parent 3a36040 commit 9624a79
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/libraries/System.Console/ref/System.Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public enum ConsoleColor
}
public enum ConsoleKey
{
None = 0,
Backspace = 8,
Tab = 9,
Clear = 12,
Expand Down Expand Up @@ -389,6 +390,7 @@ public enum ConsoleKey
[System.FlagsAttribute]
public enum ConsoleModifiers
{
None = 0,
Alt = 1,
Shift = 2,
Control = 4,
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Console/src/System/ConsoleKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace System
{
public enum ConsoleKey
{
None = 0x0,
Backspace = 0x8,
Tab = 0x9,
Clear = 0xC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace System
[Flags]
public enum ConsoleModifiers
{
None = 0,
Alt = 1,
Shift = 2,
Control = 4
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Console/src/System/IO/KeyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static bool TryParseTerminalInputSequence(char[] buffer, TerminalFormatS
}

Dictionary<ReadOnlyMemory<char>, ConsoleKeyInfo> terminfoDb = terminalFormatStrings.KeyFormatToConsoleKey; // the most important source of truth
ConsoleModifiers modifiers = 0;
ConsoleModifiers modifiers = ConsoleModifiers.None;
ConsoleKey key;

// Is it a three character sequence? (examples: '^[[H' (Home), '^[OP' (F1))
Expand Down
14 changes: 12 additions & 2 deletions src/libraries/System.Console/tests/ConsoleKeyInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ public class ConsoleKeyInfoTests
public void Ctor_DefaultCtor_PropertiesReturnDefaults()
{
ConsoleKeyInfo cki = new ConsoleKeyInfo();
Assert.Equal(default(ConsoleKey), cki.Key);
Assert.Equal(ConsoleKey.None, cki.Key);
Assert.Equal(default(char), cki.KeyChar);
Assert.Equal(default(ConsoleModifiers), cki.Modifiers);
Assert.Equal(ConsoleModifiers.None, cki.Modifiers);
}

[Fact]
public void Ctor_ValueCtor_ReturnsNoneForDefault()
{
ConsoleKeyInfo cki = new ConsoleKeyInfo(';', default(ConsoleKey), false, false, false);

Assert.Equal(ConsoleKey.None, cki.Key);
Assert.Equal(';', cki.KeyChar);
Assert.Equal(ConsoleModifiers.None, cki.Modifiers);
}

[Theory]
Expand Down

0 comments on commit 9624a79

Please sign in to comment.