pjj 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/colorText.mjs +11 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pjj",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "description": "禁止在项目的根目录执行 npm publish,防止意外发布。该脚本命令需在 `prepublishOnly` ` 钩子中配置",
6
6
  "license": "ISC",
7
7
  "dependencies": {
package/src/colorText.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { dog } from './dog.mjs';
1
2
  import { truncateStringWithChar, strInTerminalLength, pen } from 'color-pen';
2
3
  import { noColor } from './command.mjs';
3
4
  import { dataStore } from './data-store.mjs';
@@ -13,10 +14,18 @@ import { getRandomInt } from 'a-js-tools';
13
14
  */
14
15
  function colorText(str) {
15
16
  const { screenWith, safeWidth } = dataStore;
17
+ dog('开始计算文本长度');
16
18
  /** 安全区空白 */
17
19
  const blankSpace = ' '.repeat(safeWidth);
18
- const computerStr = `${blankSpace}${truncateStringWithChar(str, screenWith)}${blankSpace}`;
19
- strInTerminalLength(computerStr);
20
+ dog('空白长度为', safeWidth);
21
+ let computerStr = `${blankSpace}${truncateStringWithChar(str, screenWith)}${blankSpace}`;
22
+ dog('计算完毕字符串为', computerStr);
23
+ const strLen = strInTerminalLength(computerStr);
24
+ dog.warn('现在字符串的长度为:', strLen);
25
+ dog.warn('终端共可显示长度为:', screenWith);
26
+ if (strLen < screenWith) {
27
+ computerStr += ' ';
28
+ }
20
29
  return computerStr
21
30
  .split('')
22
31
  .map(char => noColor ? char : pen.number(getRandomInt(1, 225)).bgBlack(char))