|
@@ -9,10 +9,6 @@ namespace Terminal.Gui.Drivers;
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
|
{
|
|
{
|
|
|
- private readonly FakeInput? _input;
|
|
|
|
|
- private readonly IOutput? _output;
|
|
|
|
|
- private readonly ISizeMonitor? _sizeMonitor;
|
|
|
|
|
-
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// Creates a new FakeComponentFactory with optional output capture.
|
|
/// Creates a new FakeComponentFactory with optional output capture.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -26,12 +22,9 @@ public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
|
_sizeMonitor = sizeMonitor;
|
|
_sizeMonitor = sizeMonitor;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
|
|
- public override ISizeMonitor CreateSizeMonitor (IOutput consoleOutput, IOutputBuffer outputBuffer)
|
|
|
|
|
- {
|
|
|
|
|
- return _sizeMonitor ?? new SizeMonitorImpl (consoleOutput);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private readonly FakeInput? _input;
|
|
|
|
|
+ private readonly IOutput? _output;
|
|
|
|
|
+ private readonly ISizeMonitor? _sizeMonitor;
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
|
public override IInput<ConsoleKeyInfo> CreateInput ()
|
|
public override IInput<ConsoleKeyInfo> CreateInput ()
|
|
@@ -40,7 +33,7 @@ public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
|
FakeInput fakeInput = _input ?? new FakeInput ();
|
|
FakeInput fakeInput = _input ?? new FakeInput ();
|
|
|
|
|
|
|
|
// Check for test context in environment variable
|
|
// Check for test context in environment variable
|
|
|
- string? contextJson = Environment.GetEnvironmentVariable (ExampleContext.EnvironmentVariableName);
|
|
|
|
|
|
|
+ string? contextJson = Environment.GetEnvironmentVariable (ExampleContext.ENVIRONMENT_VARIABLE_NAME);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty (contextJson))
|
|
if (!string.IsNullOrEmpty (contextJson))
|
|
|
{
|
|
{
|
|
@@ -50,7 +43,7 @@ public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
|
{
|
|
{
|
|
|
foreach (string keyStr in context.KeysToInject)
|
|
foreach (string keyStr in context.KeysToInject)
|
|
|
{
|
|
{
|
|
|
- if (Input.Key.TryParse (keyStr, out Input.Key? key) && key is { })
|
|
|
|
|
|
|
+ if (Key.TryParse (keyStr, out Key? key) && key is { })
|
|
|
{
|
|
{
|
|
|
ConsoleKeyInfo consoleKeyInfo = ConvertKeyToConsoleKeyInfo (key);
|
|
ConsoleKeyInfo consoleKeyInfo = ConvertKeyToConsoleKeyInfo (key);
|
|
|
fakeInput.AddInput (consoleKeyInfo);
|
|
fakeInput.AddInput (consoleKeyInfo);
|
|
@@ -62,7 +55,19 @@ public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
|
return fakeInput;
|
|
return fakeInput;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static ConsoleKeyInfo ConvertKeyToConsoleKeyInfo (Input.Key key)
|
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
|
+ public override IInputProcessor CreateInputProcessor (ConcurrentQueue<ConsoleKeyInfo> inputBuffer) { return new FakeInputProcessor (inputBuffer); }
|
|
|
|
|
+
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
|
+ public override IOutput CreateOutput () { return _output ?? new FakeOutput (); }
|
|
|
|
|
+
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
|
+ public override ISizeMonitor CreateSizeMonitor (IOutput consoleOutput, IOutputBuffer outputBuffer)
|
|
|
|
|
+ {
|
|
|
|
|
+ return _sizeMonitor ?? new SizeMonitorImpl (consoleOutput);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static ConsoleKeyInfo ConvertKeyToConsoleKeyInfo (Key key)
|
|
|
{
|
|
{
|
|
|
ConsoleModifiers modifiers = 0;
|
|
ConsoleModifiers modifiers = 0;
|
|
|
|
|
|
|
@@ -86,71 +91,71 @@ public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
|
|
|
|
|
|
// Map KeyCode to ConsoleKey
|
|
// Map KeyCode to ConsoleKey
|
|
|
ConsoleKey consoleKey = baseKeyCode switch
|
|
ConsoleKey consoleKey = baseKeyCode switch
|
|
|
- {
|
|
|
|
|
- KeyCode.A => ConsoleKey.A,
|
|
|
|
|
- KeyCode.B => ConsoleKey.B,
|
|
|
|
|
- KeyCode.C => ConsoleKey.C,
|
|
|
|
|
- KeyCode.D => ConsoleKey.D,
|
|
|
|
|
- KeyCode.E => ConsoleKey.E,
|
|
|
|
|
- KeyCode.F => ConsoleKey.F,
|
|
|
|
|
- KeyCode.G => ConsoleKey.G,
|
|
|
|
|
- KeyCode.H => ConsoleKey.H,
|
|
|
|
|
- KeyCode.I => ConsoleKey.I,
|
|
|
|
|
- KeyCode.J => ConsoleKey.J,
|
|
|
|
|
- KeyCode.K => ConsoleKey.K,
|
|
|
|
|
- KeyCode.L => ConsoleKey.L,
|
|
|
|
|
- KeyCode.M => ConsoleKey.M,
|
|
|
|
|
- KeyCode.N => ConsoleKey.N,
|
|
|
|
|
- KeyCode.O => ConsoleKey.O,
|
|
|
|
|
- KeyCode.P => ConsoleKey.P,
|
|
|
|
|
- KeyCode.Q => ConsoleKey.Q,
|
|
|
|
|
- KeyCode.R => ConsoleKey.R,
|
|
|
|
|
- KeyCode.S => ConsoleKey.S,
|
|
|
|
|
- KeyCode.T => ConsoleKey.T,
|
|
|
|
|
- KeyCode.U => ConsoleKey.U,
|
|
|
|
|
- KeyCode.V => ConsoleKey.V,
|
|
|
|
|
- KeyCode.W => ConsoleKey.W,
|
|
|
|
|
- KeyCode.X => ConsoleKey.X,
|
|
|
|
|
- KeyCode.Y => ConsoleKey.Y,
|
|
|
|
|
- KeyCode.Z => ConsoleKey.Z,
|
|
|
|
|
- KeyCode.D0 => ConsoleKey.D0,
|
|
|
|
|
- KeyCode.D1 => ConsoleKey.D1,
|
|
|
|
|
- KeyCode.D2 => ConsoleKey.D2,
|
|
|
|
|
- KeyCode.D3 => ConsoleKey.D3,
|
|
|
|
|
- KeyCode.D4 => ConsoleKey.D4,
|
|
|
|
|
- KeyCode.D5 => ConsoleKey.D5,
|
|
|
|
|
- KeyCode.D6 => ConsoleKey.D6,
|
|
|
|
|
- KeyCode.D7 => ConsoleKey.D7,
|
|
|
|
|
- KeyCode.D8 => ConsoleKey.D8,
|
|
|
|
|
- KeyCode.D9 => ConsoleKey.D9,
|
|
|
|
|
- KeyCode.Enter => ConsoleKey.Enter,
|
|
|
|
|
- KeyCode.Esc => ConsoleKey.Escape,
|
|
|
|
|
- KeyCode.Space => ConsoleKey.Spacebar,
|
|
|
|
|
- KeyCode.Tab => ConsoleKey.Tab,
|
|
|
|
|
- KeyCode.Backspace => ConsoleKey.Backspace,
|
|
|
|
|
- KeyCode.Delete => ConsoleKey.Delete,
|
|
|
|
|
- KeyCode.Home => ConsoleKey.Home,
|
|
|
|
|
- KeyCode.End => ConsoleKey.End,
|
|
|
|
|
- KeyCode.PageUp => ConsoleKey.PageUp,
|
|
|
|
|
- KeyCode.PageDown => ConsoleKey.PageDown,
|
|
|
|
|
- KeyCode.CursorUp => ConsoleKey.UpArrow,
|
|
|
|
|
- KeyCode.CursorDown => ConsoleKey.DownArrow,
|
|
|
|
|
- KeyCode.CursorLeft => ConsoleKey.LeftArrow,
|
|
|
|
|
- KeyCode.CursorRight => ConsoleKey.RightArrow,
|
|
|
|
|
- KeyCode.F1 => ConsoleKey.F1,
|
|
|
|
|
- KeyCode.F2 => ConsoleKey.F2,
|
|
|
|
|
- KeyCode.F3 => ConsoleKey.F3,
|
|
|
|
|
- KeyCode.F4 => ConsoleKey.F4,
|
|
|
|
|
- KeyCode.F5 => ConsoleKey.F5,
|
|
|
|
|
- KeyCode.F6 => ConsoleKey.F6,
|
|
|
|
|
- KeyCode.F7 => ConsoleKey.F7,
|
|
|
|
|
- KeyCode.F8 => ConsoleKey.F8,
|
|
|
|
|
- KeyCode.F9 => ConsoleKey.F9,
|
|
|
|
|
- KeyCode.F10 => ConsoleKey.F10,
|
|
|
|
|
- KeyCode.F11 => ConsoleKey.F11,
|
|
|
|
|
- KeyCode.F12 => ConsoleKey.F12,
|
|
|
|
|
- _ => (ConsoleKey)0
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ KeyCode.A => ConsoleKey.A,
|
|
|
|
|
+ KeyCode.B => ConsoleKey.B,
|
|
|
|
|
+ KeyCode.C => ConsoleKey.C,
|
|
|
|
|
+ KeyCode.D => ConsoleKey.D,
|
|
|
|
|
+ KeyCode.E => ConsoleKey.E,
|
|
|
|
|
+ KeyCode.F => ConsoleKey.F,
|
|
|
|
|
+ KeyCode.G => ConsoleKey.G,
|
|
|
|
|
+ KeyCode.H => ConsoleKey.H,
|
|
|
|
|
+ KeyCode.I => ConsoleKey.I,
|
|
|
|
|
+ KeyCode.J => ConsoleKey.J,
|
|
|
|
|
+ KeyCode.K => ConsoleKey.K,
|
|
|
|
|
+ KeyCode.L => ConsoleKey.L,
|
|
|
|
|
+ KeyCode.M => ConsoleKey.M,
|
|
|
|
|
+ KeyCode.N => ConsoleKey.N,
|
|
|
|
|
+ KeyCode.O => ConsoleKey.O,
|
|
|
|
|
+ KeyCode.P => ConsoleKey.P,
|
|
|
|
|
+ KeyCode.Q => ConsoleKey.Q,
|
|
|
|
|
+ KeyCode.R => ConsoleKey.R,
|
|
|
|
|
+ KeyCode.S => ConsoleKey.S,
|
|
|
|
|
+ KeyCode.T => ConsoleKey.T,
|
|
|
|
|
+ KeyCode.U => ConsoleKey.U,
|
|
|
|
|
+ KeyCode.V => ConsoleKey.V,
|
|
|
|
|
+ KeyCode.W => ConsoleKey.W,
|
|
|
|
|
+ KeyCode.X => ConsoleKey.X,
|
|
|
|
|
+ KeyCode.Y => ConsoleKey.Y,
|
|
|
|
|
+ KeyCode.Z => ConsoleKey.Z,
|
|
|
|
|
+ KeyCode.D0 => ConsoleKey.D0,
|
|
|
|
|
+ KeyCode.D1 => ConsoleKey.D1,
|
|
|
|
|
+ KeyCode.D2 => ConsoleKey.D2,
|
|
|
|
|
+ KeyCode.D3 => ConsoleKey.D3,
|
|
|
|
|
+ KeyCode.D4 => ConsoleKey.D4,
|
|
|
|
|
+ KeyCode.D5 => ConsoleKey.D5,
|
|
|
|
|
+ KeyCode.D6 => ConsoleKey.D6,
|
|
|
|
|
+ KeyCode.D7 => ConsoleKey.D7,
|
|
|
|
|
+ KeyCode.D8 => ConsoleKey.D8,
|
|
|
|
|
+ KeyCode.D9 => ConsoleKey.D9,
|
|
|
|
|
+ KeyCode.Enter => ConsoleKey.Enter,
|
|
|
|
|
+ KeyCode.Esc => ConsoleKey.Escape,
|
|
|
|
|
+ KeyCode.Space => ConsoleKey.Spacebar,
|
|
|
|
|
+ KeyCode.Tab => ConsoleKey.Tab,
|
|
|
|
|
+ KeyCode.Backspace => ConsoleKey.Backspace,
|
|
|
|
|
+ KeyCode.Delete => ConsoleKey.Delete,
|
|
|
|
|
+ KeyCode.Home => ConsoleKey.Home,
|
|
|
|
|
+ KeyCode.End => ConsoleKey.End,
|
|
|
|
|
+ KeyCode.PageUp => ConsoleKey.PageUp,
|
|
|
|
|
+ KeyCode.PageDown => ConsoleKey.PageDown,
|
|
|
|
|
+ KeyCode.CursorUp => ConsoleKey.UpArrow,
|
|
|
|
|
+ KeyCode.CursorDown => ConsoleKey.DownArrow,
|
|
|
|
|
+ KeyCode.CursorLeft => ConsoleKey.LeftArrow,
|
|
|
|
|
+ KeyCode.CursorRight => ConsoleKey.RightArrow,
|
|
|
|
|
+ KeyCode.F1 => ConsoleKey.F1,
|
|
|
|
|
+ KeyCode.F2 => ConsoleKey.F2,
|
|
|
|
|
+ KeyCode.F3 => ConsoleKey.F3,
|
|
|
|
|
+ KeyCode.F4 => ConsoleKey.F4,
|
|
|
|
|
+ KeyCode.F5 => ConsoleKey.F5,
|
|
|
|
|
+ KeyCode.F6 => ConsoleKey.F6,
|
|
|
|
|
+ KeyCode.F7 => ConsoleKey.F7,
|
|
|
|
|
+ KeyCode.F8 => ConsoleKey.F8,
|
|
|
|
|
+ KeyCode.F9 => ConsoleKey.F9,
|
|
|
|
|
+ KeyCode.F10 => ConsoleKey.F10,
|
|
|
|
|
+ KeyCode.F11 => ConsoleKey.F11,
|
|
|
|
|
+ KeyCode.F12 => ConsoleKey.F12,
|
|
|
|
|
+ _ => 0
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
var keyChar = '\0';
|
|
var keyChar = '\0';
|
|
|
Rune rune = key.AsRune;
|
|
Rune rune = key.AsRune;
|
|
@@ -162,13 +167,4 @@ public class FakeComponentFactory : ComponentFactoryImpl<ConsoleKeyInfo>
|
|
|
|
|
|
|
|
return new (keyChar, consoleKey, key.IsShift, key.IsAlt, key.IsCtrl);
|
|
return new (keyChar, consoleKey, key.IsShift, key.IsAlt, key.IsCtrl);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
|
|
- public override IInputProcessor CreateInputProcessor (ConcurrentQueue<ConsoleKeyInfo> inputBuffer) { return new FakeInputProcessor (inputBuffer); }
|
|
|
|
|
-
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
|
|
- public override IOutput CreateOutput ()
|
|
|
|
|
- {
|
|
|
|
|
- return _output ?? new FakeOutput ();
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|