@cannbot-ai/install-helper 0.0.2-beta.26 → 0.0.2-beta.28

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/dist/index.js CHANGED
@@ -552,24 +552,63 @@ import chalk2 from "chalk";
552
552
  var selectTheme = {
553
553
  helpMode: "never"
554
554
  };
555
+ function isCJK(code) {
556
+ return code >= 11904 && code <= 40959 || code >= 63744 && code <= 64255 || code >= 65072 && code <= 65103 || code >= 65280 && code <= 65519 || code >= 13312 && code <= 19903 || code >= 131072 && code <= 173791 || code >= 173824 && code <= 177983 || code >= 177984 && code <= 178207 || code >= 178208 && code <= 183983;
557
+ }
558
+ function isEmoji(code) {
559
+ return code >= 127744 && code <= 129791 || code >= 9728 && code <= 10175;
560
+ }
561
+ function getDisplayWidth2(str) {
562
+ let width = 0;
563
+ for (const ch of str) {
564
+ const code = ch.codePointAt(0);
565
+ if (isCJK(code) || isEmoji(code)) {
566
+ width += 2;
567
+ } else {
568
+ width += 1;
569
+ }
570
+ }
571
+ return width;
572
+ }
555
573
  function wrapDescription(text) {
556
574
  const prefix = " \u{1F4A1} ";
557
575
  const indent = " ";
558
576
  const cols = process.stdout.columns || 120;
559
- const maxLen = Math.max(20, cols - prefix.length - 1);
560
- const words = text.split(/(\s+)/);
577
+ const maxLen = Math.max(20, cols - getDisplayWidth2(prefix) - 2);
578
+ const tokens = [];
579
+ let i = 0;
580
+ while (i < text.length) {
581
+ const code = text[i].codePointAt(0);
582
+ if (isCJK(code)) {
583
+ tokens.push({ text: text[i], width: 2 });
584
+ i++;
585
+ } else {
586
+ let j = i;
587
+ while (j < text.length) {
588
+ const c = text[j].codePointAt(0);
589
+ if (isCJK(c)) break;
590
+ j++;
591
+ }
592
+ const word = text.slice(i, j);
593
+ tokens.push({ text: word, width: getDisplayWidth2(word) });
594
+ i = j;
595
+ }
596
+ }
561
597
  const lines = [];
562
598
  let line = "";
563
- for (const word of words) {
564
- if ((line + word).length > maxLen && line) {
599
+ let lineWidth = 0;
600
+ for (const token of tokens) {
601
+ if (lineWidth + token.width > maxLen && line) {
565
602
  lines.push(line.trimEnd());
566
- line = word.trimStart();
603
+ line = token.text;
604
+ lineWidth = token.width;
567
605
  } else {
568
- line += word;
606
+ line += token.text;
607
+ lineWidth += token.width;
569
608
  }
570
609
  }
571
610
  if (line) lines.push(line.trimEnd());
572
- return lines.map((l, i) => chalk2.cyan(i === 0 ? prefix + l : indent + l)).join("\n");
611
+ return lines.map((l, i2) => chalk2.cyan(i2 === 0 ? prefix + l : indent + l)).join("\n");
573
612
  }
574
613
  var checkboxTheme = {
575
614
  icon: {
@@ -3189,7 +3228,7 @@ function createCLI() {
3189
3228
  setLanguage(config.language);
3190
3229
  }
3191
3230
  const program2 = new Command();
3192
- program2.name("install-helper").description("CANNBot Install Helper - Interactive installer for CANN operator development skills").version("0.0.2-beta.26");
3231
+ program2.name("install-helper").description("CANNBot Install Helper - Interactive installer for CANN operator development skills").version("0.0.2-beta.28");
3193
3232
  program2.command("init", { isDefault: false }).description("Run interactive installation wizard").action(async () => {
3194
3233
  await initCommand();
3195
3234
  });