From 5f34a33c5749b11a16be811829c72bbb8638bed4 Mon Sep 17 00:00:00 2001 From: tsingliu <410869548@qq.com> Date: Sat, 7 Feb 2026 22:48:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=A7=A3=E5=86=B3=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 18 ++++++++++++++++-- src/tools/screenshot.ts | 25 +++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index cef1c9b..9452004 100644 --- a/src/index.ts +++ b/src/index.ts @@ -388,7 +388,16 @@ async function runChat(queryParts: string[], options: any) { try { while (true) { - const userInput = await rl.question(chalk.green('? ') + 'You > '); + let userInput: string; + try { + userInput = await rl.question(chalk.green('? ') + 'You > '); + } catch (err: any) { + if (err.code === 'ABORT_ERR') { + console.log(chalk.cyan("\nGoodbye!")); + break; + } + throw err; + } if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') { console.log(chalk.cyan("Goodbye!")); @@ -400,7 +409,12 @@ async function runChat(queryParts: string[], options: any) { await agent.chat(userInput); } } catch (err: any) { - console.error(chalk.red("Error in chat loop:"), err); + if (err.name === 'AbortError' || err.code === 'ABORT_ERR') { + // Handled inside loop mostly, but just in case + console.log(chalk.cyan("\nGoodbye!")); + } else { + console.error(chalk.red("Error in chat loop:"), err); + } } finally { rl.close(); } diff --git a/src/tools/screenshot.ts b/src/tools/screenshot.ts index d446800..d9aed69 100644 --- a/src/tools/screenshot.ts +++ b/src/tools/screenshot.ts @@ -7,15 +7,24 @@ import * as os from 'os'; const checkLinuxFonts = () => { if (os.platform() !== 'linux') return true; - const commonFontPaths = [ - '/usr/share/fonts/noto', - '/usr/share/fonts/opentype/noto', - '/usr/share/fonts/truetype/wqy', - '/usr/share/fonts/cjk', - '/usr/share/fonts/google-noto-cjk' // Arch/Manjaro sometimes + // Check for specific font files rather than just directories + const commonFontFiles = [ + '/usr/share/fonts/noto/NotoSansCJK-Regular.ttc', // Alpine / Some Debian + '/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', // Debian / Ubuntu + '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc', // ZenHei + '/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc' // Arch ]; - return commonFontPaths.some(path => fs.existsSync(path)); + // Also check if fc-list finds any CJK fonts (if available) + try { + const child_process = require('child_process'); + const output = child_process.execSync('fc-list :lang=zh', { stdio: 'pipe' }).toString(); + if (output.length > 0) return true; + } catch (e) { + // fc-list might not be installed or failed, fall back to file check + } + + return commonFontFiles.some(path => fs.existsSync(path)); }; export const ScreenshotTool: ToolModule = { @@ -93,7 +102,7 @@ export const ScreenshotTool: ToolModule = { await page.addStyleTag({ content: ` body, h1, h2, h3, h4, h5, h6, p, span, div, li, a, button, input, textarea { - font-family: "PingFang SC", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif !important; + font-family: "PingFang SC", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif !important; } ` });