尝试解决中文问题
This commit is contained in:
parent
18f6885d3e
commit
5f34a33c57
2 changed files with 33 additions and 10 deletions
18
src/index.ts
18
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
`
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue