@barekey/cli 0.5.3 → 0.5.5
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/output/avatar.js +6 -12
- package/package.json +1 -1
- package/src/output/avatar.ts +8 -14
package/dist/output/avatar.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Jimp } from "jimp";
|
|
2
|
-
const DEFAULT_AVATAR_COLUMNS =
|
|
2
|
+
const DEFAULT_AVATAR_COLUMNS = 8;
|
|
3
3
|
const DEFAULT_AVATAR_ROWS = 8;
|
|
4
4
|
function supportsAnsiAvatar() {
|
|
5
5
|
if (!process.stdout.isTTY) {
|
|
@@ -66,7 +66,6 @@ async function renderAvatarLines(imageUrl) {
|
|
|
66
66
|
w: DEFAULT_AVATAR_COLUMNS,
|
|
67
67
|
h: bitmapRows,
|
|
68
68
|
});
|
|
69
|
-
image.circle();
|
|
70
69
|
const { data, width, height } = image.bitmap;
|
|
71
70
|
const lines = [];
|
|
72
71
|
for (let y = 0; y < height; y += 2) {
|
|
@@ -78,23 +77,18 @@ async function renderAvatarLines(imageUrl) {
|
|
|
78
77
|
}
|
|
79
78
|
lines.push(`${line}\u001b[0m`);
|
|
80
79
|
}
|
|
81
|
-
while (lines.length > 0 && isBlankAvatarLine(lines[0] ?? "")) {
|
|
82
|
-
lines.shift();
|
|
83
|
-
}
|
|
84
|
-
while (lines.length > 0 && isBlankAvatarLine(lines[lines.length - 1] ?? "")) {
|
|
85
|
-
lines.pop();
|
|
86
|
-
}
|
|
87
80
|
return lines;
|
|
88
81
|
}
|
|
89
|
-
function isBlankAvatarLine(line) {
|
|
90
|
-
return line.replace(/\u001b\[[0-9;]*m/g, "").trim().length === 0;
|
|
91
|
-
}
|
|
92
82
|
function joinAvatarAndText(avatarLines, textLines) {
|
|
93
83
|
const totalRows = Math.max(avatarLines.length, textLines.length);
|
|
84
|
+
const textOffset = avatarLines.length > textLines.length
|
|
85
|
+
? Math.floor((avatarLines.length - textLines.length) / 2)
|
|
86
|
+
: 0;
|
|
94
87
|
const renderedRows = [];
|
|
95
88
|
for (let index = 0; index < totalRows; index += 1) {
|
|
96
89
|
const avatarLine = avatarLines[index] ?? " ".repeat(DEFAULT_AVATAR_COLUMNS);
|
|
97
|
-
const
|
|
90
|
+
const textIndex = index - textOffset;
|
|
91
|
+
const textLine = textIndex >= 0 && textIndex < textLines.length ? (textLines[textIndex] ?? "") : "";
|
|
98
92
|
renderedRows.push(textLine.length > 0 ? `${avatarLine} ${textLine}` : avatarLine);
|
|
99
93
|
}
|
|
100
94
|
return renderedRows.join("\n");
|
package/package.json
CHANGED
package/src/output/avatar.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Jimp } from "jimp";
|
|
2
2
|
|
|
3
|
-
const DEFAULT_AVATAR_COLUMNS =
|
|
3
|
+
const DEFAULT_AVATAR_COLUMNS = 8;
|
|
4
4
|
const DEFAULT_AVATAR_ROWS = 8;
|
|
5
5
|
|
|
6
6
|
type Rgba = {
|
|
@@ -92,7 +92,6 @@ async function renderAvatarLines(imageUrl: string): Promise<Array<string>> {
|
|
|
92
92
|
w: DEFAULT_AVATAR_COLUMNS,
|
|
93
93
|
h: bitmapRows,
|
|
94
94
|
});
|
|
95
|
-
image.circle();
|
|
96
95
|
|
|
97
96
|
const { data, width, height } = image.bitmap;
|
|
98
97
|
const lines: Array<string> = [];
|
|
@@ -107,30 +106,25 @@ async function renderAvatarLines(imageUrl: string): Promise<Array<string>> {
|
|
|
107
106
|
lines.push(`${line}\u001b[0m`);
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
while (lines.length > 0 && isBlankAvatarLine(lines[0] ?? "")) {
|
|
111
|
-
lines.shift();
|
|
112
|
-
}
|
|
113
|
-
while (lines.length > 0 && isBlankAvatarLine(lines[lines.length - 1] ?? "")) {
|
|
114
|
-
lines.pop();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
109
|
return lines;
|
|
118
110
|
}
|
|
119
111
|
|
|
120
|
-
function isBlankAvatarLine(line: string): boolean {
|
|
121
|
-
return line.replace(/\u001b\[[0-9;]*m/g, "").trim().length === 0;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
112
|
function joinAvatarAndText(
|
|
125
113
|
avatarLines: Array<string>,
|
|
126
114
|
textLines: Array<string>,
|
|
127
115
|
): string {
|
|
128
116
|
const totalRows = Math.max(avatarLines.length, textLines.length);
|
|
117
|
+
const textOffset =
|
|
118
|
+
avatarLines.length > textLines.length
|
|
119
|
+
? Math.floor((avatarLines.length - textLines.length) / 2)
|
|
120
|
+
: 0;
|
|
129
121
|
const renderedRows: Array<string> = [];
|
|
130
122
|
|
|
131
123
|
for (let index = 0; index < totalRows; index += 1) {
|
|
132
124
|
const avatarLine = avatarLines[index] ?? " ".repeat(DEFAULT_AVATAR_COLUMNS);
|
|
133
|
-
const
|
|
125
|
+
const textIndex = index - textOffset;
|
|
126
|
+
const textLine =
|
|
127
|
+
textIndex >= 0 && textIndex < textLines.length ? (textLines[textIndex] ?? "") : "";
|
|
134
128
|
renderedRows.push(textLine.length > 0 ? `${avatarLine} ${textLine}` : avatarLine);
|
|
135
129
|
}
|
|
136
130
|
|