@seflless/ghosttown 1.2.0 → 1.2.2
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/bin/{ascii.ts → ascii.js} +19 -19
- package/bin/ghosttown.js +1 -1
- package/package.json +2 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { PNG } from 'pngjs';
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
const PNGSync =
|
|
4
|
+
// Access sync API from PNG
|
|
5
|
+
const PNGSync = PNG.sync;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts RGB color to ANSI 256-color code.
|
|
9
9
|
* Uses the standard 256-color palette mapping.
|
|
10
10
|
*/
|
|
11
|
-
function rgbToAnsi256(r
|
|
11
|
+
function rgbToAnsi256(r, g, b) {
|
|
12
12
|
// Standard 16 colors (0-15) are handled specially
|
|
13
13
|
// Colors 16-231 are a 6x6x6 color cube
|
|
14
14
|
// Colors 232-255 are grayscale
|
|
@@ -36,14 +36,14 @@ function rgbToAnsi256(r: number, g: number, b: number): number {
|
|
|
36
36
|
/**
|
|
37
37
|
* Generates ANSI escape code for foreground color using 256-color palette.
|
|
38
38
|
*/
|
|
39
|
-
function ansiColorCode(color256
|
|
39
|
+
function ansiColorCode(color256) {
|
|
40
40
|
return `\x1b[38;5;${color256}m`;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Resets ANSI color formatting.
|
|
45
45
|
*/
|
|
46
|
-
function ansiReset()
|
|
46
|
+
function ansiReset() {
|
|
47
47
|
return '\x1b[0m';
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -56,18 +56,14 @@ const SOLID_CHAR = '█';
|
|
|
56
56
|
/**
|
|
57
57
|
* Converts an image file to ASCII art with ANSI colors.
|
|
58
58
|
*
|
|
59
|
-
* @param imagePath - Path to the image file (PNG supported)
|
|
60
|
-
* @param options - Optional configuration
|
|
61
|
-
* @
|
|
59
|
+
* @param {string} imagePath - Path to the image file (PNG supported)
|
|
60
|
+
* @param {Object} options - Optional configuration
|
|
61
|
+
* @param {number} [options.maxWidth=80] - Maximum width in characters
|
|
62
|
+
* @param {number} [options.maxHeight=24] - Maximum height in characters
|
|
63
|
+
* @param {number} [options.transparentThreshold=128] - Alpha threshold below which pixel is considered transparent
|
|
64
|
+
* @returns {Promise<string>} ASCII art string with ANSI color codes
|
|
62
65
|
*/
|
|
63
|
-
export async function asciiArt(
|
|
64
|
-
imagePath: string,
|
|
65
|
-
options: {
|
|
66
|
-
maxWidth?: number;
|
|
67
|
-
maxHeight?: number;
|
|
68
|
-
transparentThreshold?: number; // Alpha threshold below which pixel is considered transparent
|
|
69
|
-
} = {}
|
|
70
|
-
): Promise<string> {
|
|
66
|
+
export async function asciiArt(imagePath, options = {}) {
|
|
71
67
|
const {
|
|
72
68
|
maxWidth = 80,
|
|
73
69
|
maxHeight = 24,
|
|
@@ -89,12 +85,12 @@ export async function asciiArt(
|
|
|
89
85
|
const outputWidth = Math.max(1, Math.floor(width * scale));
|
|
90
86
|
const outputHeight = Math.max(1, Math.floor(height * scale));
|
|
91
87
|
|
|
92
|
-
const result
|
|
88
|
+
const result = [];
|
|
93
89
|
|
|
94
90
|
// Process each output row
|
|
95
91
|
for (let outY = 0; outY < outputHeight; outY++) {
|
|
96
92
|
let line = '';
|
|
97
|
-
let lastColor
|
|
93
|
+
let lastColor = null;
|
|
98
94
|
|
|
99
95
|
// Process each output column
|
|
100
96
|
for (let outX = 0; outX < outputWidth; outX++) {
|
|
@@ -145,7 +141,11 @@ export async function asciiArt(
|
|
|
145
141
|
}
|
|
146
142
|
|
|
147
143
|
// If running directly, execute the function
|
|
148
|
-
|
|
144
|
+
const isMainModule =
|
|
145
|
+
import.meta.url === `file://${process.argv[1]}` ||
|
|
146
|
+
process.argv[1]?.endsWith('/ascii.js');
|
|
147
|
+
|
|
148
|
+
if (isMainModule) {
|
|
149
149
|
const imagePath = process.argv[2] || 'demo/images/ghosts.png';
|
|
150
150
|
asciiArt(imagePath)
|
|
151
151
|
.then((art) => {
|
package/bin/ghosttown.js
CHANGED
|
@@ -30,7 +30,7 @@ import pty from '@lydell/node-pty';
|
|
|
30
30
|
// WebSocket server
|
|
31
31
|
import { WebSocketServer } from 'ws';
|
|
32
32
|
// ASCII art generator
|
|
33
|
-
import { asciiArt } from './ascii.
|
|
33
|
+
import { asciiArt } from './ascii.js';
|
|
34
34
|
|
|
35
35
|
const __filename = fileURLToPath(import.meta.url);
|
|
36
36
|
const __dirname = path.dirname(__filename);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seflless/ghosttown",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Web-based terminal emulator using Ghostty's VT100 parser via WebAssembly",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/ghostty-web.umd.cjs",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@lydell/node-pty": "^1.0.1",
|
|
71
|
+
"pngjs": "^7.0.0",
|
|
71
72
|
"ws": "^8.18.0"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|