mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Add net ansi sequences
This commit is contained in:
@@ -49,11 +49,10 @@ public class NetInputProcessor : InputProcessor<ConsoleKeyInfo>
|
|||||||
private static string FormatConsoleKeyInfoForTestCase (ConsoleKeyInfo input)
|
private static string FormatConsoleKeyInfoForTestCase (ConsoleKeyInfo input)
|
||||||
{
|
{
|
||||||
string charLiteral = input.KeyChar == '\0' ? @"'\0'" : $"'{input.KeyChar}'";
|
string charLiteral = input.KeyChar == '\0' ? @"'\0'" : $"'{input.KeyChar}'";
|
||||||
var expectedLiteral = "new Rune('todo')";
|
|
||||||
|
|
||||||
return $"new ConsoleKeyInfo({charLiteral}, ConsoleKey.{input.Key}, "
|
return $"new ConsoleKeyInfo({charLiteral}, ConsoleKey.{input.Key}, "
|
||||||
+ $"{input.Modifiers.HasFlag (ConsoleModifiers.Shift).ToString ().ToLower ()}, "
|
+ $"{input.Modifiers.HasFlag (ConsoleModifiers.Shift).ToString ().ToLower ()}, "
|
||||||
+ $"{input.Modifiers.HasFlag (ConsoleModifiers.Alt).ToString ().ToLower ()}, "
|
+ $"{input.Modifiers.HasFlag (ConsoleModifiers.Alt).ToString ().ToLower ()}, "
|
||||||
+ $"{input.Modifiers.HasFlag (ConsoleModifiers.Control).ToString ().ToLower ()}), {expectedLiteral}";
|
+ $"{input.Modifiers.HasFlag (ConsoleModifiers.Control).ToString ().ToLower ()}),";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,29 +225,50 @@ public class GuiTestContext : IDisposable
|
|||||||
|
|
||||||
private GuiTestContext Click (WindowsConsole.ButtonState btn, int screenX, int screenY)
|
private GuiTestContext Click (WindowsConsole.ButtonState btn, int screenX, int screenY)
|
||||||
{
|
{
|
||||||
// TODO: Support net style ansi escape sequence generation for arrow keys
|
switch (_driver)
|
||||||
|
{
|
||||||
|
case V2TestDriver.V2Win:
|
||||||
|
|
||||||
_winInput.InputBuffer.Enqueue (
|
_winInput.InputBuffer.Enqueue (
|
||||||
new ()
|
new ()
|
||||||
{
|
{
|
||||||
EventType = WindowsConsole.EventType.Mouse,
|
EventType = WindowsConsole.EventType.Mouse,
|
||||||
MouseEvent = new ()
|
MouseEvent = new ()
|
||||||
{
|
{
|
||||||
ButtonState = btn,
|
ButtonState = btn,
|
||||||
MousePosition = new ((short)screenX, (short)screenY)
|
MousePosition = new ((short)screenX, (short)screenY)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_winInput.InputBuffer.Enqueue (
|
_winInput.InputBuffer.Enqueue (
|
||||||
new ()
|
new ()
|
||||||
{
|
{
|
||||||
EventType = WindowsConsole.EventType.Mouse,
|
EventType = WindowsConsole.EventType.Mouse,
|
||||||
MouseEvent = new ()
|
MouseEvent = new ()
|
||||||
{
|
{
|
||||||
ButtonState = WindowsConsole.ButtonState.NoButtonPressed,
|
ButtonState = WindowsConsole.ButtonState.NoButtonPressed,
|
||||||
MousePosition = new ((short)screenX, (short)screenY)
|
MousePosition = new ((short)screenX, (short)screenY)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
|
case V2TestDriver.V2Net:
|
||||||
|
|
||||||
|
int netButton = btn switch
|
||||||
|
{
|
||||||
|
WindowsConsole.ButtonState.Button1Pressed => 0,
|
||||||
|
WindowsConsole.ButtonState.Button2Pressed => 1,
|
||||||
|
WindowsConsole.ButtonState.Button3Pressed => 2,
|
||||||
|
WindowsConsole.ButtonState.RightmostButtonPressed => 2,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(btn))
|
||||||
|
};
|
||||||
|
foreach (var k in NetSequences.Click(netButton,screenX,screenY))
|
||||||
|
{
|
||||||
|
SendNetKey (k);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException ();
|
||||||
|
}
|
||||||
|
|
||||||
WaitIteration ();
|
WaitIteration ();
|
||||||
|
|
||||||
@@ -260,11 +281,13 @@ public class GuiTestContext : IDisposable
|
|||||||
{
|
{
|
||||||
case V2TestDriver.V2Win:
|
case V2TestDriver.V2Win:
|
||||||
SendWindowsKey (ConsoleKeyMapping.VK.DOWN);
|
SendWindowsKey (ConsoleKeyMapping.VK.DOWN);
|
||||||
|
WaitIteration ();
|
||||||
break;
|
break;
|
||||||
case V2TestDriver.V2Net:
|
case V2TestDriver.V2Net:
|
||||||
// TODO: Support ansi sequence
|
foreach (var k in NetSequences.Down)
|
||||||
|
{
|
||||||
throw new NotImplementedException ("Coming soon");
|
SendNetKey (k);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException ();
|
throw new ArgumentOutOfRangeException ();
|
||||||
@@ -277,21 +300,63 @@ public class GuiTestContext : IDisposable
|
|||||||
|
|
||||||
public GuiTestContext Right ()
|
public GuiTestContext Right ()
|
||||||
{
|
{
|
||||||
SendWindowsKey (ConsoleKeyMapping.VK.RIGHT);
|
switch (_driver)
|
||||||
|
{
|
||||||
|
case V2TestDriver.V2Win:
|
||||||
|
SendWindowsKey (ConsoleKeyMapping.VK.RIGHT);
|
||||||
|
WaitIteration ();
|
||||||
|
break;
|
||||||
|
case V2TestDriver.V2Net:
|
||||||
|
foreach (var k in NetSequences.Right)
|
||||||
|
{
|
||||||
|
SendNetKey (k);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException ();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiTestContext Left ()
|
public GuiTestContext Left ()
|
||||||
{
|
{
|
||||||
SendWindowsKey (ConsoleKeyMapping.VK.LEFT);
|
switch (_driver)
|
||||||
|
{
|
||||||
|
case V2TestDriver.V2Win:
|
||||||
|
SendWindowsKey (ConsoleKeyMapping.VK.LEFT);
|
||||||
|
WaitIteration ();
|
||||||
|
break;
|
||||||
|
case V2TestDriver.V2Net:
|
||||||
|
foreach (var k in NetSequences.Left)
|
||||||
|
{
|
||||||
|
SendNetKey (k);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException ();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiTestContext Up ()
|
public GuiTestContext Up ()
|
||||||
{
|
{
|
||||||
SendWindowsKey (ConsoleKeyMapping.VK.UP);
|
switch (_driver)
|
||||||
|
{
|
||||||
|
case V2TestDriver.V2Win:
|
||||||
|
SendWindowsKey (ConsoleKeyMapping.VK.UP);
|
||||||
|
WaitIteration ();
|
||||||
|
break;
|
||||||
|
case V2TestDriver.V2Net:
|
||||||
|
foreach (var k in NetSequences.Up)
|
||||||
|
{
|
||||||
|
SendNetKey (k);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException ();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -354,7 +419,6 @@ public class GuiTestContext : IDisposable
|
|||||||
private void SendNetKey (ConsoleKeyInfo consoleKeyInfo)
|
private void SendNetKey (ConsoleKeyInfo consoleKeyInfo)
|
||||||
{
|
{
|
||||||
_netInput.InputBuffer.Enqueue (consoleKeyInfo);
|
_netInput.InputBuffer.Enqueue (consoleKeyInfo);
|
||||||
WaitIteration ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
53
TerminalGuiFluentTesting/NetSequences.cs
Normal file
53
TerminalGuiFluentTesting/NetSequences.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
namespace TerminalGuiFluentTesting;
|
||||||
|
class NetSequences
|
||||||
|
{
|
||||||
|
public static ConsoleKeyInfo [] Down = new []
|
||||||
|
{
|
||||||
|
new ConsoleKeyInfo('\x1B', ConsoleKey.Enter, false, false, false),
|
||||||
|
new ConsoleKeyInfo('[', ConsoleKey.None, false, false, false),
|
||||||
|
new ConsoleKeyInfo('B', ConsoleKey.None, false, false, false),
|
||||||
|
};
|
||||||
|
|
||||||
|
public static ConsoleKeyInfo [] Up = new []
|
||||||
|
{
|
||||||
|
new ConsoleKeyInfo('\x1B', ConsoleKey.Enter, false, false, false),
|
||||||
|
new ConsoleKeyInfo('[', ConsoleKey.None, false, false, false),
|
||||||
|
new ConsoleKeyInfo('A', ConsoleKey.None, false, false, false),
|
||||||
|
};
|
||||||
|
|
||||||
|
public static ConsoleKeyInfo [] Left = new []
|
||||||
|
{
|
||||||
|
new ConsoleKeyInfo('\x1B', ConsoleKey.Enter, false, false, false),
|
||||||
|
new ConsoleKeyInfo('[', ConsoleKey.None, false, false, false),
|
||||||
|
new ConsoleKeyInfo('D', ConsoleKey.None, false, false, false),
|
||||||
|
};
|
||||||
|
|
||||||
|
public static ConsoleKeyInfo [] Right = new []
|
||||||
|
{
|
||||||
|
new ConsoleKeyInfo('\x1B', ConsoleKey.Enter, false, false, false),
|
||||||
|
new ConsoleKeyInfo('[', ConsoleKey.None, false, false, false),
|
||||||
|
new ConsoleKeyInfo('C', ConsoleKey.None, false, false, false),
|
||||||
|
};
|
||||||
|
|
||||||
|
public static IEnumerable<ConsoleKeyInfo> Click (int button, int screenX, int screenY)
|
||||||
|
{
|
||||||
|
// Adjust for 1-based coordinates
|
||||||
|
int adjustedX = screenX + 1;
|
||||||
|
int adjustedY = screenY + 1;
|
||||||
|
|
||||||
|
// Mouse press sequence
|
||||||
|
var sequence = $"\x1B[<{button};{adjustedX};{adjustedY}M";
|
||||||
|
foreach (char c in sequence)
|
||||||
|
{
|
||||||
|
yield return new ConsoleKeyInfo (c, ConsoleKey.None, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mouse release sequence
|
||||||
|
sequence = $"\x1B[<{button};{adjustedX};{adjustedY}m";
|
||||||
|
foreach (char c in sequence)
|
||||||
|
{
|
||||||
|
yield return new ConsoleKeyInfo (c, ConsoleKey.None, false, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -81,7 +81,7 @@ public class BasicFluentAssertionTests
|
|||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(V2TestDriver.V2Win)]
|
[InlineData(V2TestDriver.V2Win)]
|
||||||
//[InlineData (V2TestDriver.V2Net)] // TODO
|
[InlineData (V2TestDriver.V2Net)]
|
||||||
public void ContextMenu_OpenSubmenu (V2TestDriver v2TestDriver)
|
public void ContextMenu_OpenSubmenu (V2TestDriver v2TestDriver)
|
||||||
{
|
{
|
||||||
var clicked = false;
|
var clicked = false;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
"UICatalog --driver v2net": {
|
"UICatalog --driver v2net": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "--driver v2net"
|
"commandLineArgs": "--driver v2net -dl Trace"
|
||||||
},
|
},
|
||||||
"WSL: UICatalog": {
|
"WSL: UICatalog": {
|
||||||
"commandName": "Executable",
|
"commandName": "Executable",
|
||||||
|
|||||||
Reference in New Issue
Block a user