reflow_strategy.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'package:xterm/buffer/buffer.dart';
  2. import 'package:xterm/buffer/buffer_line.dart';
  3. import 'package:xterm/utli/circular_list.dart';
  4. abstract class ReflowStrategy {
  5. final Buffer _buffer;
  6. ReflowStrategy(this._buffer);
  7. Buffer get buffer => _buffer;
  8. void reflow(int newCols, int newRows, int oldCols, int oldRows);
  9. static int getWrappedLineTrimmedLengthFromCircularList(
  10. CircularList<BufferLine> lines, int row, int cols) {
  11. return getWrappedLineTrimmedLengthFromLine(
  12. lines[row], row == lines.length - 1 ? null : lines[row + 1], cols);
  13. }
  14. static int getWrappedLineTrimmedLengthFromLines(
  15. List<BufferLine> lines, int row, int cols) {
  16. return getWrappedLineTrimmedLengthFromLine(
  17. lines[row], row == lines.length - 1 ? null : lines[row + 1], cols);
  18. }
  19. static int getWrappedLineTrimmedLengthFromLine(
  20. BufferLine? line, BufferLine? nextLine, int cols) {
  21. if (line == null) {
  22. return 0;
  23. }
  24. if (nextLine == null) {
  25. return line.getTrimmedLength(cols);
  26. }
  27. // Detect whether the following line starts with a wide character and the end of the current line
  28. // is null, if so then we can be pretty sure the null character should be excluded from the line
  29. // length]
  30. final endsInNull =
  31. !(line.cellHasContent(cols - 1)) && line.cellGetWidth(cols - 1) == 1;
  32. final followingLineStartsWithWide = nextLine.cellGetWidth(0) == 2;
  33. if (endsInNull && followingLineStartsWithWide) {
  34. return cols - 1;
  35. }
  36. return cols;
  37. }
  38. }