mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
lint JSON and Typescript as well
This commit is contained in:
292
example/app.ts
292
example/app.ts
@ -1,14 +1,18 @@
|
|||||||
import { ZigJS } from 'zig-js';
|
import { ZigJS } from "zig-js";
|
||||||
|
|
||||||
const zjs = new ZigJS();
|
const zjs = new ZigJS();
|
||||||
const importObject = {
|
const importObject = {
|
||||||
module: {},
|
module: {},
|
||||||
env: {
|
env: {
|
||||||
memory: new WebAssembly.Memory({ initial: 25, maximum: 65536, shared: true }),
|
memory: new WebAssembly.Memory({
|
||||||
|
initial: 25,
|
||||||
|
maximum: 65536,
|
||||||
|
shared: true,
|
||||||
|
}),
|
||||||
log: (ptr: number, len: number) => {
|
log: (ptr: number, len: number) => {
|
||||||
const arr = new Uint8ClampedArray(zjs.memory.buffer, ptr, len);
|
const arr = new Uint8ClampedArray(zjs.memory.buffer, ptr, len);
|
||||||
const data = arr.slice();
|
const data = arr.slice();
|
||||||
const str = new TextDecoder('utf-8').decode(data);
|
const str = new TextDecoder("utf-8").decode(data);
|
||||||
console.log(str);
|
console.log(str);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -16,158 +20,170 @@ const importObject = {
|
|||||||
...zjs.importObject(),
|
...zjs.importObject(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const url = new URL('ghostty-wasm.wasm', import.meta.url);
|
const url = new URL("ghostty-wasm.wasm", import.meta.url);
|
||||||
fetch(url.href).then(response =>
|
fetch(url.href)
|
||||||
response.arrayBuffer()
|
.then((response) => response.arrayBuffer())
|
||||||
).then(bytes =>
|
.then((bytes) => WebAssembly.instantiate(bytes, importObject))
|
||||||
WebAssembly.instantiate(bytes, importObject)
|
.then((results) => {
|
||||||
).then(results => {
|
const memory = importObject.env.memory;
|
||||||
const memory = importObject.env.memory;
|
const {
|
||||||
const {
|
malloc,
|
||||||
malloc,
|
free,
|
||||||
free,
|
config_new,
|
||||||
config_new,
|
config_free,
|
||||||
config_free,
|
config_load_string,
|
||||||
config_load_string,
|
config_finalize,
|
||||||
config_finalize,
|
face_new,
|
||||||
face_new,
|
face_free,
|
||||||
face_free,
|
face_render_glyph,
|
||||||
face_render_glyph,
|
face_debug_canvas,
|
||||||
face_debug_canvas,
|
deferred_face_new,
|
||||||
deferred_face_new,
|
deferred_face_free,
|
||||||
deferred_face_free,
|
deferred_face_load,
|
||||||
deferred_face_load,
|
deferred_face_face,
|
||||||
deferred_face_face,
|
group_new,
|
||||||
group_new,
|
group_free,
|
||||||
group_free,
|
group_add_face,
|
||||||
group_add_face,
|
group_init_sprite_face,
|
||||||
group_init_sprite_face,
|
group_index_for_codepoint,
|
||||||
group_index_for_codepoint,
|
group_render_glyph,
|
||||||
group_render_glyph,
|
group_cache_new,
|
||||||
group_cache_new,
|
group_cache_free,
|
||||||
group_cache_free,
|
group_cache_index_for_codepoint,
|
||||||
group_cache_index_for_codepoint,
|
group_cache_render_glyph,
|
||||||
group_cache_render_glyph,
|
group_cache_atlas_greyscale,
|
||||||
group_cache_atlas_greyscale,
|
group_cache_atlas_color,
|
||||||
group_cache_atlas_color,
|
atlas_new,
|
||||||
atlas_new,
|
atlas_free,
|
||||||
atlas_free,
|
atlas_debug_canvas,
|
||||||
atlas_debug_canvas,
|
shaper_new,
|
||||||
shaper_new,
|
shaper_free,
|
||||||
shaper_free,
|
shaper_test,
|
||||||
shaper_test,
|
} = results.instance.exports;
|
||||||
} = results.instance.exports;
|
// Give us access to the zjs value for debugging.
|
||||||
// Give us access to the zjs value for debugging.
|
globalThis.zjs = zjs;
|
||||||
globalThis.zjs = zjs;
|
console.log(zjs);
|
||||||
console.log(zjs);
|
|
||||||
|
|
||||||
// Initialize our zig-js memory
|
// Initialize our zig-js memory
|
||||||
zjs.memory = memory;
|
zjs.memory = memory;
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
const makeStr = (str) => {
|
const makeStr = (str) => {
|
||||||
const utf8 = new TextEncoder().encode(str);
|
const utf8 = new TextEncoder().encode(str);
|
||||||
const ptr = malloc(utf8.byteLength);
|
const ptr = malloc(utf8.byteLength);
|
||||||
new Uint8Array(memory.buffer, ptr).set(utf8);
|
new Uint8Array(memory.buffer, ptr).set(utf8);
|
||||||
return { ptr: ptr, len: utf8.byteLength };
|
return { ptr: ptr, len: utf8.byteLength };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create our config
|
// Create our config
|
||||||
const config = config_new();
|
const config = config_new();
|
||||||
const config_str = makeStr("font-family = monospace");
|
const config_str = makeStr("font-family = monospace");
|
||||||
config_load_string(config, config_str.ptr, config_str.len);
|
config_load_string(config, config_str.ptr, config_str.len);
|
||||||
config_finalize(config);
|
config_finalize(config);
|
||||||
free(config_str.ptr);
|
free(config_str.ptr);
|
||||||
|
|
||||||
// Create our atlas
|
// Create our atlas
|
||||||
// const atlas = atlas_new(512, 0 /* greyscale */);
|
// const atlas = atlas_new(512, 0 /* greyscale */);
|
||||||
|
|
||||||
// Create some memory for our string
|
// Create some memory for our string
|
||||||
const font_name = makeStr("monospace");
|
const font_name = makeStr("monospace");
|
||||||
|
|
||||||
// Initialize our deferred face
|
// Initialize our deferred face
|
||||||
// const df = deferred_face_new(font_ptr, font.byteLength, 0 /* text */);
|
// const df = deferred_face_new(font_ptr, font.byteLength, 0 /* text */);
|
||||||
//deferred_face_load(df, 72 /* size */);
|
//deferred_face_load(df, 72 /* size */);
|
||||||
//const face = deferred_face_face(df);
|
//const face = deferred_face_face(df);
|
||||||
|
|
||||||
// Initialize our font face
|
// Initialize our font face
|
||||||
//const face = face_new(font_ptr, font.byteLength, 72 /* size in px */);
|
//const face = face_new(font_ptr, font.byteLength, 72 /* size in px */);
|
||||||
//free(font_ptr);
|
//free(font_ptr);
|
||||||
|
|
||||||
// Create our group
|
// Create our group
|
||||||
const group = group_new(32 /* size */);
|
const group = group_new(32 /* size */);
|
||||||
group_add_face(group, 0 /* regular */, deferred_face_new(font_name.ptr, font_name.len, 0 /* text */));
|
group_add_face(
|
||||||
group_add_face(group, 0 /* regular */, deferred_face_new(font_name.ptr, font_name.len, 1 /* emoji */));
|
group,
|
||||||
|
0 /* regular */,
|
||||||
|
deferred_face_new(font_name.ptr, font_name.len, 0 /* text */),
|
||||||
|
);
|
||||||
|
group_add_face(
|
||||||
|
group,
|
||||||
|
0 /* regular */,
|
||||||
|
deferred_face_new(font_name.ptr, font_name.len, 1 /* emoji */),
|
||||||
|
);
|
||||||
|
|
||||||
// Initialize our sprite font, without this we just use the browser.
|
// Initialize our sprite font, without this we just use the browser.
|
||||||
group_init_sprite_face(group);
|
group_init_sprite_face(group);
|
||||||
|
|
||||||
// Create our group cache
|
// Create our group cache
|
||||||
const group_cache = group_cache_new(group);
|
const group_cache = group_cache_new(group);
|
||||||
|
|
||||||
// Render a glyph
|
// Render a glyph
|
||||||
// for (let i = 33; i <= 126; i++) {
|
// for (let i = 33; i <= 126; i++) {
|
||||||
// const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
// const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
||||||
// group_cache_render_glyph(group_cache, font_idx, i, 0);
|
// group_cache_render_glyph(group_cache, font_idx, i, 0);
|
||||||
// //face_render_glyph(face, atlas, i);
|
// //face_render_glyph(face, atlas, i);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// const emoji = ["🐏","🌞","🌚","🍱","💿","🐈","📃","📀","🕡","🙃"];
|
// const emoji = ["🐏","🌞","🌚","🍱","💿","🐈","📃","📀","🕡","🙃"];
|
||||||
// for (let i = 0; i < emoji.length; i++) {
|
// for (let i = 0; i < emoji.length; i++) {
|
||||||
// const cp = emoji[i].codePointAt(0);
|
// const cp = emoji[i].codePointAt(0);
|
||||||
// const font_idx = group_cache_index_for_codepoint(group_cache, cp, 0, -1 /* best choice */);
|
// const font_idx = group_cache_index_for_codepoint(group_cache, cp, 0, -1 /* best choice */);
|
||||||
// group_cache_render_glyph(group_cache, font_idx, cp, 0);
|
// group_cache_render_glyph(group_cache, font_idx, cp, 0);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
for (let i = 0x2500; i <= 0x257F; i++) {
|
for (let i = 0x2500; i <= 0x257f; i++) {
|
||||||
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
||||||
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
||||||
}
|
}
|
||||||
for (let i = 0x2580; i <= 0x259f; i++) {
|
for (let i = 0x2580; i <= 0x259f; i++) {
|
||||||
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
||||||
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
||||||
}
|
}
|
||||||
for (let i = 0x2800; i <= 0x28FF; i++) {
|
for (let i = 0x2800; i <= 0x28ff; i++) {
|
||||||
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
||||||
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
||||||
}
|
}
|
||||||
for (let i = 0x1FB00; i <= 0x1FB3B; i++) {
|
for (let i = 0x1fb00; i <= 0x1fb3b; i++) {
|
||||||
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
||||||
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
||||||
}
|
}
|
||||||
for (let i = 0x1FB3C; i <= 0x1FB6B; i++) {
|
for (let i = 0x1fb3c; i <= 0x1fb6b; i++) {
|
||||||
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
const font_idx = group_cache_index_for_codepoint(group_cache, i, 0, -1);
|
||||||
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
group_cache_render_glyph(group_cache, font_idx, i, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//face_render_glyph(face, atlas, "橋".codePointAt(0));
|
//face_render_glyph(face, atlas, "橋".codePointAt(0));
|
||||||
//face_render_glyph(face, atlas, "p".codePointAt(0));
|
//face_render_glyph(face, atlas, "p".codePointAt(0));
|
||||||
|
|
||||||
// Debug our canvas
|
// Debug our canvas
|
||||||
//face_debug_canvas(face);
|
//face_debug_canvas(face);
|
||||||
|
|
||||||
// Let's try shaping
|
// Let's try shaping
|
||||||
const shaper = shaper_new(120);
|
const shaper = shaper_new(120);
|
||||||
//const input = makeStr("hello🐏");
|
//const input = makeStr("hello🐏");
|
||||||
const input = makeStr("hello🐏👍🏽");
|
const input = makeStr("hello🐏👍🏽");
|
||||||
shaper_test(shaper, group_cache, input.ptr, input.len);
|
shaper_test(shaper, group_cache, input.ptr, input.len);
|
||||||
|
|
||||||
const cp = 1114112;
|
const cp = 1114112;
|
||||||
const font_idx = group_cache_index_for_codepoint(group_cache, cp, 0, -1 /* best choice */);
|
const font_idx = group_cache_index_for_codepoint(
|
||||||
group_cache_render_glyph(group_cache, font_idx, cp, -1);
|
group_cache,
|
||||||
|
cp,
|
||||||
|
0,
|
||||||
|
-1 /* best choice */,
|
||||||
|
);
|
||||||
|
group_cache_render_glyph(group_cache, font_idx, cp, -1);
|
||||||
|
|
||||||
// Debug our atlas canvas
|
// Debug our atlas canvas
|
||||||
{
|
{
|
||||||
const atlas = group_cache_atlas_greyscale(group_cache);
|
const atlas = group_cache_atlas_greyscale(group_cache);
|
||||||
const id = atlas_debug_canvas(atlas);
|
const id = atlas_debug_canvas(atlas);
|
||||||
document.getElementById("atlas-canvas").append(zjs.deleteValue(id));
|
document.getElementById("atlas-canvas").append(zjs.deleteValue(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const atlas = group_cache_atlas_color(group_cache);
|
const atlas = group_cache_atlas_color(group_cache);
|
||||||
const id = atlas_debug_canvas(atlas);
|
const id = atlas_debug_canvas(atlas);
|
||||||
document.getElementById("atlas-color-canvas").append(zjs.deleteValue(id));
|
document.getElementById("atlas-color-canvas").append(zjs.deleteValue(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
//face_free(face);
|
//face_free(face);
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"colors" : [
|
"colors": [
|
||||||
{
|
{
|
||||||
"idiom" : "universal"
|
"idiom": "universal"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info": {
|
||||||
"author" : "xcode",
|
"author": "xcode",
|
||||||
"version" : 1
|
"version": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,68 +1,68 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images": [
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_256x256x32 6.png",
|
"filename": "Ghostty_256x256x32 6.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "1x",
|
"scale": "1x",
|
||||||
"size" : "16x16"
|
"size": "16x16"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_256x256x32 5.png",
|
"filename": "Ghostty_256x256x32 5.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "2x",
|
"scale": "2x",
|
||||||
"size" : "16x16"
|
"size": "16x16"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_256x256x32 4.png",
|
"filename": "Ghostty_256x256x32 4.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "1x",
|
"scale": "1x",
|
||||||
"size" : "32x32"
|
"size": "32x32"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_256x256x32 3.png",
|
"filename": "Ghostty_256x256x32 3.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "2x",
|
"scale": "2x",
|
||||||
"size" : "32x32"
|
"size": "32x32"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_256x256x32 2.png",
|
"filename": "Ghostty_256x256x32 2.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "1x",
|
"scale": "1x",
|
||||||
"size" : "128x128"
|
"size": "128x128"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_256x256x32 1.png",
|
"filename": "Ghostty_256x256x32 1.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "2x",
|
"scale": "2x",
|
||||||
"size" : "128x128"
|
"size": "128x128"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_256x256x32.png",
|
"filename": "Ghostty_256x256x32.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "1x",
|
"scale": "1x",
|
||||||
"size" : "256x256"
|
"size": "256x256"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_512x512x32.png",
|
"filename": "Ghostty_512x512x32.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "2x",
|
"scale": "2x",
|
||||||
"size" : "256x256"
|
"size": "256x256"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_512x512x32 1.png",
|
"filename": "Ghostty_512x512x32 1.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "1x",
|
"scale": "1x",
|
||||||
"size" : "512x512"
|
"size": "512x512"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Ghostty_512x512x32 2.png",
|
"filename": "Ghostty_512x512x32 2.png",
|
||||||
"idiom" : "mac",
|
"idiom": "mac",
|
||||||
"scale" : "2x",
|
"scale": "2x",
|
||||||
"size" : "512x512"
|
"size": "512x512"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info": {
|
||||||
"author" : "xcode",
|
"author": "xcode",
|
||||||
"version" : 1
|
"version": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images": [
|
||||||
{
|
{
|
||||||
"filename" : "199110421-9ff5fc30-a244-441e-9882-26070662adf9.png",
|
"filename": "199110421-9ff5fc30-a244-441e-9882-26070662adf9.png",
|
||||||
"idiom" : "universal",
|
"idiom": "universal",
|
||||||
"scale" : "1x"
|
"scale": "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "199110421-9ff5fc30-a244-441e-9882-26070662adf9 1.png",
|
"filename": "199110421-9ff5fc30-a244-441e-9882-26070662adf9 1.png",
|
||||||
"idiom" : "universal",
|
"idiom": "universal",
|
||||||
"scale" : "2x"
|
"scale": "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "199110421-9ff5fc30-a244-441e-9882-26070662adf9 2.png",
|
"filename": "199110421-9ff5fc30-a244-441e-9882-26070662adf9 2.png",
|
||||||
"idiom" : "universal",
|
"idiom": "universal",
|
||||||
"scale" : "3x"
|
"scale": "3x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info": {
|
||||||
"author" : "xcode",
|
"author": "xcode",
|
||||||
"version" : 1
|
"version": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"info" : {
|
"info": {
|
||||||
"author" : "xcode",
|
"author": "xcode",
|
||||||
"version" : 1
|
"version": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user