cursor.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import 'package:xterm/core/cell.dart';
  2. class CursorStyle {
  3. int foreground;
  4. int background;
  5. int attrs;
  6. CursorStyle({this.foreground = 0, this.background = 0, this.attrs = 0});
  7. static final empty = CursorStyle();
  8. void setBold() {
  9. attrs |= CellAttr.bold;
  10. }
  11. void setFaint() {
  12. attrs |= CellAttr.faint;
  13. }
  14. void setItalic() {
  15. attrs |= CellAttr.italic;
  16. }
  17. void setUnderline() {
  18. attrs |= CellAttr.underline;
  19. }
  20. void setBlink() {
  21. attrs |= CellAttr.blink;
  22. }
  23. void setInverse() {
  24. attrs |= CellAttr.inverse;
  25. }
  26. void setInvisible() {
  27. attrs |= CellAttr.invisible;
  28. }
  29. void setStrikethrough() {
  30. attrs |= CellAttr.strikethrough;
  31. }
  32. void unsetBold() {
  33. attrs &= ~CellAttr.bold;
  34. }
  35. void unsetFaint() {
  36. attrs &= ~CellAttr.faint;
  37. }
  38. void unsetItalic() {
  39. attrs &= ~CellAttr.italic;
  40. }
  41. void unsetUnderline() {
  42. attrs &= ~CellAttr.underline;
  43. }
  44. void unsetBlink() {
  45. attrs &= ~CellAttr.blink;
  46. }
  47. void unsetInverse() {
  48. attrs &= ~CellAttr.inverse;
  49. }
  50. void unsetInvisible() {
  51. attrs &= ~CellAttr.invisible;
  52. }
  53. void unsetStrikethrough() {
  54. attrs &= ~CellAttr.strikethrough;
  55. }
  56. bool get isBold => (attrs & CellAttr.bold) != 0;
  57. bool get isFaint => (attrs & CellAttr.faint) != 0;
  58. bool get isItalis => (attrs & CellAttr.italic) != 0;
  59. bool get isUnderline => (attrs & CellAttr.underline) != 0;
  60. bool get isBlink => (attrs & CellAttr.blink) != 0;
  61. bool get isInverse => (attrs & CellAttr.inverse) != 0;
  62. bool get isInvisible => (attrs & CellAttr.invisible) != 0;
  63. void setForegroundColor16(int color) {
  64. foreground = color | CellColor.named;
  65. }
  66. void setForegroundColor256(int color) {
  67. foreground = color | CellColor.palette;
  68. }
  69. void setForegroundColorRgb(int r, int g, int b) {
  70. foreground = (r << 16) | (g << 8) | b | CellColor.rgb;
  71. }
  72. void resetForegroundColor() {
  73. foreground = 0; // | CellColor.normal;
  74. }
  75. void setBackgroundColor16(int color) {
  76. background = color | CellColor.named;
  77. }
  78. void setBackgroundColor256(int color) {
  79. background = color | CellColor.palette;
  80. }
  81. void setBackgroundColorRgb(int r, int g, int b) {
  82. background = (r << 16) | (g << 8) | b | CellColor.rgb;
  83. }
  84. void resetBackgroundColor() {
  85. background = 0; // | CellColor.normal;
  86. }
  87. void reset() {
  88. foreground = 0;
  89. background = 0;
  90. attrs = 0;
  91. }
  92. }
  93. class CursorPosition {
  94. int x;
  95. int y;
  96. CursorPosition(this.x, this.y);
  97. }