cell_attr.dart 3.2 KB

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