xterm.dart icon indicating copy to clipboard operation
xterm.dart copied to clipboard

sz一个无权限的文件后,终端显示异常

Open itzhoujun opened this issue 1 year ago • 2 comments

sz一个无权限的文件后,再输入其他字符时,显示有点异常。比如说我输入了5个字符,终端页面只会展示2个。

itzhoujun avatar Jun 25 '24 11:06 itzhoujun

找到问题了。是zmodem协议上未处理abort sequence: class ZModemAbortSequence implements ZModemPacket { const ZModemAbortSequence();

static final abortSequence = Uint8List.fromList([ consts.CAN, consts.CAN, consts.CAN, consts.CAN, consts.CAN, ]);

@override Uint8List encode() { return abortSequence; } }

itzhoujun avatar Jul 08 '24 11:07 itzhoujun

参考处理方式: 修改zmodem模块

  bool _findSubSeq(Uint8List origin, Uint8List subSeq) {
    // 如果 b 是空数组,直接返回 true
    if (subSeq.isEmpty) return true;

    // 如果 a 的长度小于 b 的长度,直接返回 false
    if (origin.length < subSeq.length) return false;

    // 遍历 a 数组,检查是否存在连续的子序列与 b 相等
    for (int i = 0; i <= origin.length - subSeq.length; i++) {
      bool match = true;
      for (int j = 0; j < subSeq.length; j++) {
        if (origin[i + j] != subSeq[j]) {
          match = false;
          break;
        }
      }
      if (match) return true;
    }

    return false;
  }
   Iterable<ZModemEvent> receive(Uint8List data) sync* {
    if (_findSubSeq(data, ZModemAbortSequence.abortSequence)) {
      yield ZSessionAbortedEvent();
    }
   // other code ....
    }

itzhoujun avatar Jul 08 '24 11:07 itzhoujun