segment.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:xterm/core/buffer/position.dart';
  2. import 'package:xterm/core/buffer/range.dart';
  3. class BufferSegment {
  4. /// The range that this segment belongs to.
  5. final BufferRange range;
  6. /// The line that this segment resides on.
  7. final int line;
  8. /// The start position of this segment.
  9. final int? start;
  10. /// The end position of this segment. [null] if this segment is not closed.
  11. final int? end;
  12. const BufferSegment(this.range, this.line, this.start, this.end);
  13. bool isWithin(BufferPosition position) {
  14. if (position.y != line) {
  15. return false;
  16. }
  17. if (start != null && position.x < start!) {
  18. return false;
  19. }
  20. if (end != null && position.x > end!) {
  21. return false;
  22. }
  23. return true;
  24. }
  25. @override
  26. String toString() => 'Segment($line, $start, $end)';
  27. @override
  28. int get hashCode =>
  29. range.hashCode ^ line.hashCode ^ start.hashCode ^ end.hashCode;
  30. @override
  31. bool operator ==(Object other) =>
  32. identical(this, other) ||
  33. other is BufferSegment &&
  34. runtimeType == other.runtimeType &&
  35. range == other.range &&
  36. line == other.line &&
  37. start == other.start &&
  38. end == other.end;
  39. }