CommandContext.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. public CommandContext (Command command, Key? key)
  20. {
  21. Command = command;
  22. Key = key;
  23. }
  24. /// <summary>
  25. /// The <see cref="Command"/> that is being invoked.
  26. /// </summary>
  27. public Command Command { get; set; }
  28. /// <summary>
  29. /// The <see cref="Key"/> that is being invoked. This is the key that was pressed to invoke the <see cref="Command"/>.
  30. /// </summary>
  31. public Key? Key { get; set; }
  32. }