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.
- package/package.json +1 -1
- package/src/colorText.mjs +11 -2
package/package.json
CHANGED
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
|
-
|
|
19
|
-
|
|
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))
|