TextStyle.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Text.Json.Serialization;
  2. namespace Terminal.Gui.Drawing;
  3. /// <summary>
  4. /// Defines non-color style flags for an <see cref="Attribute"/>.
  5. /// </summary>
  6. /// <remarks>
  7. /// <para>
  8. /// Only a subset of ANSI SGR (Select Graphic Rendition) styles are represented.
  9. /// Styles that are poorly supported, non-visual, or redundant with other APIs are omitted.
  10. /// </para>
  11. /// <para>
  12. /// Multiple styles can be combined using bitwise operations. Use <see cref="Attribute.Style"/>
  13. /// to get or set these styles on an <see cref="Attribute"/>.
  14. /// </para>
  15. /// <para>
  16. /// Note that <see cref="TextStyle.Bold"/> and <see cref="TextStyle.Faint"/> may be mutually exclusive depending on
  17. /// the user's terminal and its settings. For instance, if a terminal displays faint text as a darker color, and
  18. /// bold text as a lighter color, then both cannot
  19. /// be shown at the same time, and it will be up to the terminal to decide which to display.
  20. /// </para>
  21. /// </remarks>
  22. [Flags]
  23. [JsonConverter (typeof (JsonStringEnumConverter<TextStyle>))]
  24. public enum TextStyle : byte
  25. {
  26. /// <summary>
  27. /// No text style.
  28. /// </summary>
  29. /// <remarks>Corresponds to no active SGR styles.</remarks>
  30. None = 0b_0000_0000,
  31. /// <summary>
  32. /// Bold text.
  33. /// </summary>
  34. /// <remarks>
  35. /// SGR code: 1 (Bold). May be mutually exclusive with <see cref="TextStyle.Faint"/>, see <see cref="TextStyle"/>
  36. /// remarks.
  37. /// </remarks>
  38. Bold = 0b_0000_0001,
  39. /// <summary>
  40. /// Faint (dim) text.
  41. /// </summary>
  42. /// <remarks>
  43. /// SGR code: 2 (Faint). Not widely supported on all terminals. May be mutually exclusive with
  44. /// <see cref="TextStyle.Bold"/>, see
  45. /// <see cref="TextStyle"/> remarks.
  46. /// </remarks>
  47. Faint = 0b_0000_0010,
  48. /// <summary>
  49. /// Italic text.
  50. /// </summary>
  51. /// <remarks>SGR code: 3 (Italic). Some terminals may not support italic rendering.</remarks>
  52. Italic = 0b_0000_0100,
  53. /// <summary>
  54. /// Underlined text.
  55. /// </summary>
  56. /// <remarks>SGR code: 4 (Underline).</remarks>
  57. Underline = 0b_0000_1000,
  58. /// <summary>
  59. /// Slow blinking text.
  60. /// </summary>
  61. /// <remarks>SGR code: 5 (Slow Blink). Support varies; blinking is often disabled in modern terminals.</remarks>
  62. Blink = 0b_0001_0000,
  63. /// <summary>
  64. /// Reverse video (swaps foreground and background colors).
  65. /// </summary>
  66. /// <remarks>SGR code: 7 (Reverse Video).</remarks>
  67. Reverse = 0b_0010_0000,
  68. /// <summary>
  69. /// Strikethrough (crossed-out) text.
  70. /// </summary>
  71. /// <remarks>SGR code: 9 (Crossed-out / Strikethrough).</remarks>
  72. Strikethrough = 0b_0100_0000
  73. }