ExampleDemoKeyStrokesAttribute.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. namespace Terminal.Gui.Examples;
  2. /// <summary>
  3. /// Defines keystrokes to be automatically injected when the example is run in demo or test mode.
  4. /// Apply this attribute to an assembly to specify automated input sequences for demonstration or testing purposes.
  5. /// </summary>
  6. /// <remarks>
  7. /// <para>
  8. /// Multiple instances of this attribute can be applied to a single assembly to define a sequence
  9. /// of keystroke injections. The <see cref="Order"/> property controls the execution sequence.
  10. /// </para>
  11. /// </remarks>
  12. /// <example>
  13. /// <code>
  14. /// [assembly: ExampleDemoKeyStrokes(RepeatKey = "CursorDown", RepeatCount = 5, Order = 1, DelayMs = 100)]
  15. /// [assembly: ExampleDemoKeyStrokes(KeyStrokes = new[] { "Enter" }, Order = 2, DelayMs = 200)]
  16. /// </code>
  17. /// </example>
  18. [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
  19. public class ExampleDemoKeyStrokesAttribute : System.Attribute
  20. {
  21. /// <summary>
  22. /// Gets or sets an array of keystroke names to inject.
  23. /// Each string should be a valid key name that can be parsed by <see cref="Input.Key.TryParse"/>.
  24. /// </summary>
  25. public string []? KeyStrokes { get; set; }
  26. /// <summary>
  27. /// Gets or sets the name of a single key to repeat multiple times.
  28. /// This is a convenience for repeating the same keystroke.
  29. /// </summary>
  30. public string? RepeatKey { get; set; }
  31. /// <summary>
  32. /// Gets or sets the number of times to repeat <see cref="RepeatKey"/>.
  33. /// Only used when <see cref="RepeatKey"/> is specified.
  34. /// </summary>
  35. public int RepeatCount { get; set; } = 1;
  36. /// <summary>
  37. /// Gets or sets the delay in milliseconds before injecting these keystrokes.
  38. /// </summary>
  39. public int DelayMs { get; set; } = 0;
  40. /// <summary>
  41. /// Gets or sets the order in which this keystroke sequence should be executed
  42. /// relative to other <see cref="ExampleDemoKeyStrokesAttribute"/> instances.
  43. /// </summary>
  44. public int Order { get; set; } = 0;
  45. }