@barekey/cli 0.5.6 → 0.5.8
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 +18 -3
- package/package.json +1 -1
- package/src/output/avatar.ts +21 -3
package/dist/output/avatar.js
CHANGED
|
@@ -2,6 +2,9 @@ import { Jimp } from "jimp";
|
|
|
2
2
|
import pc from "picocolors";
|
|
3
3
|
const DEFAULT_AVATAR_COLUMNS = 10;
|
|
4
4
|
const DEFAULT_AVATAR_ROWS = 5;
|
|
5
|
+
const EMAIL_HEX = "#AAAAAA";
|
|
6
|
+
const BULLET_HEX = "#555555";
|
|
7
|
+
const PLAN_HEX = "#FFAA00";
|
|
5
8
|
function supportsAnsiAvatar() {
|
|
6
9
|
if (!process.stdout.isTTY) {
|
|
7
10
|
return false;
|
|
@@ -36,6 +39,18 @@ function foregroundColor(pixel) {
|
|
|
36
39
|
function backgroundColor(pixel) {
|
|
37
40
|
return `\u001b[48;2;${pixel.red};${pixel.green};${pixel.blue}m`;
|
|
38
41
|
}
|
|
42
|
+
function parseHexColor(hex) {
|
|
43
|
+
const normalized = hex.replace(/^#/, "");
|
|
44
|
+
return {
|
|
45
|
+
red: Number.parseInt(normalized.slice(0, 2), 16),
|
|
46
|
+
green: Number.parseInt(normalized.slice(2, 4), 16),
|
|
47
|
+
blue: Number.parseInt(normalized.slice(4, 6), 16),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function truecolorText(hex, value) {
|
|
51
|
+
const { red, green, blue } = parseHexColor(hex);
|
|
52
|
+
return `\u001b[38;2;${red};${green};${blue}m${value}\u001b[39m`;
|
|
53
|
+
}
|
|
39
54
|
function renderPixelPair(top, bottom) {
|
|
40
55
|
const topOpaque = isOpaque(top);
|
|
41
56
|
const bottomOpaque = isOpaque(bottom);
|
|
@@ -119,11 +134,11 @@ export async function formatWhoamiWithAvatar(input) {
|
|
|
119
134
|
const firstLine = `Signed in as ${pc.bold(input.displayName)}`;
|
|
120
135
|
const secondSegments = [];
|
|
121
136
|
if (input.email !== null && input.email.length > 0) {
|
|
122
|
-
secondSegments.push(
|
|
137
|
+
secondSegments.push(truecolorText(EMAIL_HEX, input.email));
|
|
123
138
|
}
|
|
124
|
-
const formattedPlan =
|
|
139
|
+
const formattedPlan = truecolorText(PLAN_HEX, formatPlanLabel(input.plan));
|
|
125
140
|
if (secondSegments.length > 0) {
|
|
126
|
-
secondSegments.push(
|
|
141
|
+
secondSegments.push(truecolorText(BULLET_HEX, "•"));
|
|
127
142
|
}
|
|
128
143
|
secondSegments.push(formattedPlan);
|
|
129
144
|
const textLines = [firstLine, secondSegments.join(" ")].filter((line) => line.length > 0);
|
package/package.json
CHANGED
package/src/output/avatar.ts
CHANGED
|
@@ -11,6 +11,10 @@ type Rgba = {
|
|
|
11
11
|
alpha: number;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const EMAIL_HEX = "#AAAAAA";
|
|
15
|
+
const BULLET_HEX = "#555555";
|
|
16
|
+
const PLAN_HEX = "#FFAA00";
|
|
17
|
+
|
|
14
18
|
function supportsAnsiAvatar(): boolean {
|
|
15
19
|
if (!process.stdout.isTTY) {
|
|
16
20
|
return false;
|
|
@@ -54,6 +58,20 @@ function backgroundColor(pixel: Rgba): string {
|
|
|
54
58
|
return `\u001b[48;2;${pixel.red};${pixel.green};${pixel.blue}m`;
|
|
55
59
|
}
|
|
56
60
|
|
|
61
|
+
function parseHexColor(hex: string): { red: number; green: number; blue: number } {
|
|
62
|
+
const normalized = hex.replace(/^#/, "");
|
|
63
|
+
return {
|
|
64
|
+
red: Number.parseInt(normalized.slice(0, 2), 16),
|
|
65
|
+
green: Number.parseInt(normalized.slice(2, 4), 16),
|
|
66
|
+
blue: Number.parseInt(normalized.slice(4, 6), 16),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function truecolorText(hex: string, value: string): string {
|
|
71
|
+
const { red, green, blue } = parseHexColor(hex);
|
|
72
|
+
return `\u001b[38;2;${red};${green};${blue}m${value}\u001b[39m`;
|
|
73
|
+
}
|
|
74
|
+
|
|
57
75
|
function renderPixelPair(top: Rgba, bottom: Rgba): string {
|
|
58
76
|
const topOpaque = isOpaque(top);
|
|
59
77
|
const bottomOpaque = isOpaque(bottom);
|
|
@@ -167,12 +185,12 @@ export async function formatWhoamiWithAvatar(input: {
|
|
|
167
185
|
const secondSegments: Array<string> = [];
|
|
168
186
|
|
|
169
187
|
if (input.email !== null && input.email.length > 0) {
|
|
170
|
-
secondSegments.push(
|
|
188
|
+
secondSegments.push(truecolorText(EMAIL_HEX, input.email));
|
|
171
189
|
}
|
|
172
190
|
|
|
173
|
-
const formattedPlan =
|
|
191
|
+
const formattedPlan = truecolorText(PLAN_HEX, formatPlanLabel(input.plan));
|
|
174
192
|
if (secondSegments.length > 0) {
|
|
175
|
-
secondSegments.push(
|
|
193
|
+
secondSegments.push(truecolorText(BULLET_HEX, "•"));
|
|
176
194
|
}
|
|
177
195
|
secondSegments.push(formattedPlan);
|
|
178
196
|
|