Skip to content

Commit

Permalink
Render app icon in the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Feb 15, 2024
1 parent 7484be7 commit 3ac5b4d
Show file tree
Hide file tree
Showing 4 changed files with 1,289 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-toes-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nx.js/nro': patch
---

Render app icon in the terminal
3 changes: 2 additions & 1 deletion packages/nro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@tootallnate/nro": "^0.1.0",
"@tootallnate/romfs": "^0.1.0",
"bytes": "^3.1.2",
"chalk": "^5.3.0"
"chalk": "^5.3.0",
"terminal-image": "^2.0.0"
},
"devDependencies": {
"@types/bytes": "^3.1.4",
Expand Down
15 changes: 8 additions & 7 deletions packages/nro/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { NACP } from '@tootallnate/nacp';
import { patchNACP } from '@nx.js/patch-nacp';
import * as NRO from '@tootallnate/nro';
import * as RomFS from '@tootallnate/romfs';
import terminalImage from 'terminal-image';

const cwd = process.cwd();
const packageRoot = new URL(`${pathToFileURL(cwd)}/`);
Expand All @@ -33,27 +34,27 @@ const nxjsNro = await NRO.decode(nxjsNroBlob);

// Icon
let icon = nxjsNro.icon;
console.log(chalk.bold('Loading Icon:'));
console.log(chalk.bold('Icon:'));
const iconName = 'icon.jpg';
try {
const iconUrl = new URL(iconName, packageRoot);
const iconData = readFileSync(iconUrl);
icon = new Blob([iconData]);
console.log(
` Using ${chalk.bold(`"${iconName}"`)} file (${bytes(
icon.size
).toLowerCase()})`
);
} catch (err: any) {
if (err.code !== 'ENOENT') {
throw err;
}
console.log(
` ⚠️ No ${chalk.bold(
`⚠️ No ${chalk.bold(
`"${iconName}"`
)} file found. Default nx.js icon will be used.`
);
}
console.log(
await terminalImage.buffer(Buffer.from(await icon!.arrayBuffer()), {
height: 12,
})
);

// NACP
const nacp = new NACP(await nxjsNro.nacp!.arrayBuffer());
Expand Down
Loading

0 comments on commit 3ac5b4d

Please sign in to comment.