Skip to content

Commit 16ea2ec

Browse files
committed
Add image demo test for kitty
1 parent eb0f538 commit 16ea2ec

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

demo/client/components/window/addonImageWindow.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,30 @@ export class AddonImageWindow extends BaseWindow implements IControlWindow {
5151
container.appendChild(document.createElement('br'));
5252
container.appendChild(document.createElement('br'));
5353

54-
const dl = document.createElement('dl');
55-
const dt = document.createElement('dt');
56-
dt.textContent = 'Image Test';
57-
dl.appendChild(dt);
58-
this._addDdWithButton(dl, 'image-demo1', 'snake (sixel)');
59-
this._addDdWithButton(dl, 'image-demo2', 'oranges (sixel)');
60-
this._addDdWithButton(dl, 'image-demo3', 'palette (iip)');
61-
container.appendChild(dl);
54+
// Sixel demos
55+
const dlSixel = document.createElement('dl');
56+
const dtSixel = document.createElement('dt');
57+
dtSixel.textContent = 'Sixel';
58+
dlSixel.appendChild(dtSixel);
59+
this._addDdWithButton(dlSixel, 'image-demo1', 'snake');
60+
this._addDdWithButton(dlSixel, 'image-demo2', 'oranges');
61+
container.appendChild(dlSixel);
62+
63+
// IIP demos
64+
const dlIip = document.createElement('dl');
65+
const dtIip = document.createElement('dt');
66+
dtIip.textContent = 'IIP (iTerm)';
67+
dlIip.appendChild(dtIip);
68+
this._addDdWithButton(dlIip, 'image-demo3', 'palette');
69+
container.appendChild(dlIip);
70+
71+
// Kitty demos
72+
const dlKitty = document.createElement('dl');
73+
const dtKitty = document.createElement('dt');
74+
dtKitty.textContent = 'Kitty';
75+
dlKitty.appendChild(dtKitty);
76+
this._addDdWithButton(dlKitty, 'image-demo-kitty1', 'palette');
77+
container.appendChild(dlKitty);
6278

6379
this._initImageAddonExposed();
6480
}
@@ -125,12 +141,25 @@ export class AddonImageWindow extends BaseWindow implements IControlWindow {
125141
this._terminal.write(`\x1b]1337;File=inline=1;size=${data.length}:${btoa(sdata)}\x1b\\`);
126142
});
127143

144+
const kittyDemo = (url: string) => () => fetch(url)
145+
.then(resp => resp.arrayBuffer())
146+
.then(buffer => {
147+
const data = new Uint8Array(buffer);
148+
let sdata = '';
149+
for (let i = 0; i < data.length; ++i) sdata += String.fromCharCode(data[i]);
150+
const payload = btoa(sdata);
151+
this._terminal.write('\r\n');
152+
this._terminal.write(`\x1b_Ga=T,f=100;${payload}\x1b\\`);
153+
});
154+
128155
document.getElementById('image-demo1')!.addEventListener('click',
129156
sixelDemo('https://raw.githubusercontent.com/saitoha/libsixel/master/images/snake.six'));
130157
document.getElementById('image-demo2')!.addEventListener('click',
131158
sixelDemo('https://raw.githubusercontent.com/jerch/node-sixel/master/testfiles/test2.sixel'));
132159
document.getElementById('image-demo3')!.addEventListener('click',
133160
iipDemo('https://raw.githubusercontent.com/jerch/node-sixel/master/palette.png'));
161+
document.getElementById('image-demo-kitty1')!.addEventListener('click',
162+
kittyDemo('https://raw.githubusercontent.com/jerch/node-sixel/master/palette.png'));
134163

135164
// demo for image retrieval API
136165
this._terminal.element!.addEventListener('click', (ev: MouseEvent) => {

0 commit comments

Comments
 (0)