fix: 1.清除 ANSI 控制碼。 2.清除殘留的 --More-- 文字

This commit is contained in:
swpa 2026-05-28 11:56:45 +08:00
parent e00642553f
commit a868d82bd5
1 changed files with 5 additions and 0 deletions

View File

@ -372,6 +372,11 @@ async def fetch_raw_config(host: str, username: str, password: str, config_type:
await process.stdin.drain() await process.stdin.drain()
# 簡單清理頭尾的雜訊 (例如指令本身的 echo) # 簡單清理頭尾的雜訊 (例如指令本身的 echo)
# 1. 清除 ANSI 控制碼 (如顏色、游標移動) 與退格鍵 \x08
cleaned_output = re.sub(r'\x1b\[[0-9;]*[a-zA-Z]|\x08', '', raw_output)
# 2. 清除殘留的 --More-- 文字
cleaned_output = re.sub(r'--More--', '', cleaned_output)
lines = raw_output.splitlines() lines = raw_output.splitlines()
clean_lines = [line for line in lines if not line.startswith(cmd) and not line.startswith("admin@")] clean_lines = [line for line in lines if not line.startswith(cmd) and not line.startswith("admin@")]
return "\n".join(clean_lines).strip() return "\n".join(clean_lines).strip()