cell_offset.dart 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:xterm/src/core/buffer/range.dart';
  2. class CellOffset {
  3. final int x;
  4. final int y;
  5. const CellOffset(this.x, this.y);
  6. bool isEqual(CellOffset other) {
  7. return other.x == x && other.y == y;
  8. }
  9. bool isBefore(CellOffset other) {
  10. return y < other.y || (y == other.y && x < other.x);
  11. }
  12. bool isAfter(CellOffset other) {
  13. return y > other.y || (y == other.y && x > other.x);
  14. }
  15. bool isBeforeOrSame(CellOffset other) {
  16. return y < other.y || (y == other.y && x <= other.x);
  17. }
  18. bool isAfterOrSame(CellOffset other) {
  19. return y > other.y || (y == other.y && x >= other.x);
  20. }
  21. bool isAtSameRow(CellOffset other) {
  22. return y == other.y;
  23. }
  24. bool isAtSameColumn(CellOffset other) {
  25. return x == other.x;
  26. }
  27. bool isWithin(BufferRange range) {
  28. return range.contains(this);
  29. }
  30. @override
  31. String toString() => 'CellOffset($x, $y)';
  32. @override
  33. int get hashCode => x.hashCode ^ y.hashCode;
  34. @override
  35. bool operator ==(Object other) =>
  36. identical(this, other) ||
  37. other is CellOffset &&
  38. runtimeType == other.runtimeType &&
  39. x == other.x &&
  40. y == other.y;
  41. }