ExampleDemoKeyStrokesAttribute.cs 2.2 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. /// <para>
  12. /// Keystrokes can include special "SetDelay:nnn" entries to change the delay between subsequent keys.
  13. /// The default delay is 100ms. For example: KeyStrokes = ["SetDelay:500", "Enter", "SetDelay:100", "Tab"]
  14. /// </para>
  15. /// </remarks>
  16. /// <example>
  17. /// <code>
  18. /// [assembly: ExampleDemoKeyStrokes(RepeatKey = "CursorDown", RepeatCount = 5, Order = 1)]
  19. /// [assembly: ExampleDemoKeyStrokes(KeyStrokes = ["SetDelay:500", "Enter", "SetDelay:100", "Esc"], Order = 2)]
  20. /// </code>
  21. /// </example>
  22. [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
  23. public class ExampleDemoKeyStrokesAttribute : System.Attribute
  24. {
  25. /// <summary>
  26. /// Gets or sets an array of keystroke names to inject.
  27. /// Each string should be a valid key name that can be parsed by <see cref="Input.Key.TryParse"/>,
  28. /// or a special "SetDelay:nnn" command to change the delay between subsequent keys.
  29. /// </summary>
  30. public string []? KeyStrokes { get; set; }
  31. /// <summary>
  32. /// Gets or sets the name of a single key to repeat multiple times.
  33. /// This is a convenience for repeating the same keystroke.
  34. /// </summary>
  35. public string? RepeatKey { get; set; }
  36. /// <summary>
  37. /// Gets or sets the number of times to repeat <see cref="RepeatKey"/>.
  38. /// Only used when <see cref="RepeatKey"/> is specified.
  39. /// </summary>
  40. public int RepeatCount { get; set; } = 1;
  41. /// <summary>
  42. /// Gets or sets the order in which this keystroke sequence should be executed
  43. /// relative to other <see cref="ExampleDemoKeyStrokesAttribute"/> instances.
  44. /// </summary>
  45. public int Order { get; set; } = 0;
  46. }