cell_attr.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import 'package:xterm/theme/terminal_color.dart';
  2. import 'package:xterm/utli/hash_values.dart';
  3. class CellAttr {
  4. CellAttr({
  5. this.fgColor,
  6. this.bgColor,
  7. this.bold = false,
  8. this.faint = false,
  9. this.italic = false,
  10. this.underline = false,
  11. this.blink = false,
  12. this.inverse = false,
  13. this.invisible = false,
  14. }) : hashCode = hashValues(
  15. fgColor,
  16. bgColor,
  17. bold,
  18. faint,
  19. italic,
  20. underline,
  21. blink,
  22. inverse,
  23. invisible,
  24. );
  25. final TerminalColor fgColor;
  26. final TerminalColor bgColor;
  27. final bool bold;
  28. final bool faint;
  29. final bool italic;
  30. final bool underline;
  31. final bool blink;
  32. final bool inverse;
  33. final bool invisible;
  34. @override
  35. final int hashCode;
  36. @override
  37. bool operator ==(Object other) => other.hashCode == hashCode;
  38. // CellAttr copy() {
  39. // return CellAttr(
  40. // fgColor: this.fgColor,
  41. // bgColor: this.bgColor,
  42. // bold: this.bold,
  43. // faint: this.faint,
  44. // italic: this.italic,
  45. // underline: this.underline,
  46. // blink: this.blink,
  47. // inverse: this.inverse,
  48. // invisible: this.invisible,
  49. // );
  50. // }
  51. // void reset({
  52. // @required fgColor,
  53. // bgColor,
  54. // bold = false,
  55. // faint = false,
  56. // italic = false,
  57. // underline = false,
  58. // blink = false,
  59. // inverse = false,
  60. // invisible = false,
  61. // }) {
  62. // this.fgColor = fgColor;
  63. // this.bgColor = bgColor;
  64. // this.bold = bold;
  65. // this.faint = faint;
  66. // this.italic = italic;
  67. // this.underline = underline;
  68. // this.blink = blink;
  69. // this.inverse = inverse;
  70. // this.invisible = invisible;
  71. // }
  72. CellAttr copyWith({
  73. TerminalColor fgColor,
  74. TerminalColor bgColor,
  75. bool bold,
  76. bool faint,
  77. bool italic,
  78. bool underline,
  79. bool blink,
  80. bool inverse,
  81. bool invisible,
  82. }) {
  83. return CellAttr(
  84. fgColor: fgColor ?? this.fgColor,
  85. bgColor: bgColor ?? this.bgColor,
  86. bold: bold ?? this.bold,
  87. faint: faint ?? this.faint,
  88. italic: italic ?? this.italic,
  89. underline: underline ?? this.underline,
  90. blink: blink ?? this.blink,
  91. inverse: inverse ?? this.inverse,
  92. invisible: invisible ?? this.invisible,
  93. );
  94. }
  95. }
  96. class CellAttrTemplate {
  97. CellAttrTemplate() {
  98. reset();
  99. }
  100. CellAttr _attr;
  101. set fgColor(TerminalColor value) {
  102. _attr = _attr.copyWith(fgColor: value);
  103. }
  104. set bgColor(TerminalColor value) {
  105. _attr = _attr.copyWith(bgColor: value);
  106. }
  107. set bold(bool value) {
  108. _attr = _attr.copyWith(bold: value);
  109. }
  110. set faint(bool value) {
  111. _attr = _attr.copyWith(faint: value);
  112. }
  113. set italic(bool value) {
  114. _attr = _attr.copyWith(italic: value);
  115. }
  116. set underline(bool value) {
  117. _attr = _attr.copyWith(underline: value);
  118. }
  119. set blink(bool value) {
  120. _attr = _attr.copyWith(blink: value);
  121. }
  122. set inverse(bool value) {
  123. _attr = _attr.copyWith(inverse: value);
  124. }
  125. set invisible(bool value) {
  126. _attr = _attr.copyWith(invisible: value);
  127. }
  128. CellAttr get value => _attr;
  129. void reset() {
  130. _attr = CellAttr();
  131. }
  132. void use(CellAttr attr) {
  133. _attr = attr;
  134. }
  135. }