CommandContext.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Provides context for a <see cref="Command"/> that is being invoked.
  5. /// </summary
  6. /// <remarks>
  7. /// <para>
  8. /// To define a <see cref="Command"/> that is invoked with context,
  9. /// use <see cref="View.AddCommand(Command,Func{CommandContext,Nullable{bool}})"/>
  10. /// </para>
  11. /// </remarks>
  12. public record struct CommandContext
  13. {
  14. /// <summary>
  15. /// Initializes a new instance of <see cref="CommandContext"/> with the specified <see cref="Command"/>,
  16. /// </summary>
  17. /// <param name="command"></param>
  18. /// <param name="key"></param>
  19. /// <param name="keyBinding"></param>
  20. public CommandContext (Command command, Key? key, KeyBinding? keyBinding = null)
  21. {
  22. Command = command;
  23. Key = key;
  24. KeyBinding = keyBinding;
  25. }
  26. /// <summary>
  27. /// The <see cref="Command"/> that is being invoked.
  28. /// </summary>
  29. public Command Command { get; set; }
  30. /// <summary>
  31. /// The <see cref="Key"/> that is being invoked. This is the key that was pressed to invoke the <see cref="Command"/>.
  32. /// </summary>
  33. public Key? Key { get; set; }
  34. /// <summary>
  35. /// The KeyBinding that was used to invoke the <see cref="Command"/>, if any.
  36. /// </summary>
  37. public KeyBinding? KeyBinding { get; set; }
  38. }