IColorNameResolver.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Diagnostics.CodeAnalysis;
  2. namespace Terminal.Gui.Drawing;
  3. /// <summary>
  4. /// When implemented by a class, allows mapping <see cref="Color"/> to
  5. /// human understandable name (e.g. w3c color names) and vice versa.
  6. /// </summary>
  7. public interface IColorNameResolver
  8. {
  9. /// <summary>
  10. /// Returns the names of all known colors.
  11. /// </summary>
  12. /// <returns></returns>
  13. IEnumerable<string> GetColorNames ();
  14. /// <summary>
  15. /// Returns <see langword="true"/> if <paramref name="color"/> is a recognized
  16. /// color. In which case <paramref name="name"/> will be the name of the color and
  17. /// return value will be true otherwise false.
  18. /// </summary>
  19. /// <param name="color"></param>
  20. /// <param name="name"></param>
  21. /// <returns></returns>
  22. bool TryNameColor (Color color, [NotNullWhen(true)]out string? name);
  23. /// <summary>
  24. /// Returns <see langword="true"/> if <paramref name="name"/> is a recognized
  25. /// color. In which case <paramref name="color"/> will be the color the name corresponds
  26. /// to otherwise returns false.
  27. /// </summary>
  28. /// <param name="name"></param>
  29. /// <param name="color"></param>
  30. /// <returns></returns>
  31. bool TryParseColor (ReadOnlySpan<char> name, out Color color);
  32. }