codepet 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/codepet.js CHANGED
@@ -318,8 +318,8 @@ function renderSprite(character, variant) {
318
318
  }
319
319
  if (fs.existsSync(spritePath) && fs.existsSync(renderScript)) {
320
320
  try {
321
- const output = execSync(`${PYTHON} "${renderScript}" "${spritePath}" ${RENDER_WIDTH}`, { encoding: 'utf-8' });
322
- console.log(output);
321
+ // stdio: 'inherit' Python 直接写入终端(保留 ANSI 彩色)
322
+ execSync(`${PYTHON} "${renderScript}" "${spritePath}" ${RENDER_WIDTH}`, { stdio: 'inherit' });
323
323
  } catch (e) {}
324
324
  }
325
325
  }
@@ -487,8 +487,13 @@ function doPopup() {
487
487
  } else if (process.platform === 'win32') {
488
488
  // Windows: 弹新 PowerShell 窗口,自动开启 ANSI 彩色支持
489
489
  const script = path.join(__dirname, '..', 'scripts', 'polaroid.py').replace(/\\/g, '/');
490
- // Windows: cmd /c "start cmd /k ..." 是最可靠的弹窗方式
491
- execSync(`cmd /c "start cmd /k ${PYTHON} ${script} ${pet.character} ${scene} 40"`, { shell: true, stdio: 'ignore' });
490
+ // Windows: Node.js spawn 弹新 CMD 窗口(不依赖 shell 环境)
491
+ const { spawn } = require('child_process');
492
+ spawn('cmd', ['/c', 'start', 'cmd', '/k', PYTHON, script, pet.character, scene, '40'], {
493
+ detached: true,
494
+ stdio: 'ignore',
495
+ shell: false,
496
+ }).unref();
492
497
  } else {
493
498
  // Linux: 尝试终端弹窗
494
499
  const script = path.join(__dirname, '..', 'scripts', 'polaroid.py');
@@ -511,7 +516,7 @@ function doCard() {
511
516
  const cardScript = path.join(__dirname, '..', 'scripts', 'pet_card.py');
512
517
  if (fs.existsSync(cardScript)) {
513
518
  try {
514
- execSync(`${PYTHON} "${cardScript}"`, { encoding: 'utf-8', stdio: 'inherit' });
519
+ execSync(`${PYTHON} "${cardScript}"`, { stdio: 'inherit' });
515
520
  // 跨平台打开图片
516
521
  const cardPath = path.join(os.homedir(), '.codepet', 'card.png');
517
522
  const openCmd = process.platform === 'win32' ? 'start ""' : process.platform === 'darwin' ? 'open' : 'xdg-open';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codepet",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "在编程软件里养电子宠物 — 支持 Claude Code / Codex / Cursor / VS Code 等 10+ 平台",
5
5
  "main": "core/index.js",
6
6
  "bin": {
@@ -4,6 +4,12 @@
4
4
  import sys
5
5
  from PIL import Image
6
6
 
7
+ if sys.platform == 'win32':
8
+ try:
9
+ import ctypes
10
+ ctypes.windll.kernel32.SetConsoleMode(ctypes.windll.kernel32.GetStdHandle(-11), 7)
11
+ except: pass
12
+
7
13
  # 亮度到字符映射(从亮到暗)
8
14
  CHARS = " .:-=+*#%@█"
9
15