jsgotty 1.2.0 → 1.4.0
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/LICENSES/MIT-jsmdcui.txt +22 -0
- package/NOTICE +5 -0
- package/README.en.md +21 -0
- package/README.md +21 -0
- package/client-modes.mjs +117 -0
- package/client.mjs +100 -10
- package/clipboard-powershell.js +18 -0
- package/clipboard.js +148 -0
- package/gotty.js +13 -0
- package/package.json +1 -1
- package/static/css/index.css +14 -1
- package/static/js/gotty.js +107 -8
- package/static/js/kitty.js +115 -7
- package/terminal-modes.js +332 -0
- package/tests/client-exit.test.mjs +45 -0
- package/tests/client-modes.test.mjs +105 -0
- package/tests/clipboard-browser.test.js +81 -0
- package/tests/clipboard.test.js +75 -0
- package/tests/manual/zoom-collector.cjs +55 -0
- package/tests/manual/zoom-debug.js +39 -0
- package/tests/manual-touch-diagnostics.js +33 -0
- package/tests/manual-touch-diagnostics.mjs +22 -0
- package/tests/nested-cli-pty.test.mjs +116 -0
- package/tests/reconnect-modes-browser.test.js +144 -0
- package/tests/reconnect-modes.md +44 -0
- package/tests/reconnect-modes.test.js +166 -0
- package/tests/touch-drag-browser.test.js +106 -0
- package/tests/wheel-browser.test.js +60 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Opt-in real bundled-xterm integration; no browser/dependency downloads.
|
|
2
|
+
// CHROMIUM_HEADLESS=/path/to/chromium-headless-shell node --test tests/touch-drag-browser.test.js
|
|
3
|
+
const test=require('node:test');
|
|
4
|
+
const assert=require('node:assert/strict');
|
|
5
|
+
const fs=require('node:fs');
|
|
6
|
+
const path=require('node:path');
|
|
7
|
+
const http=require('node:http');
|
|
8
|
+
const {spawn}=require('node:child_process');
|
|
9
|
+
const {once}=require('node:events');
|
|
10
|
+
const WebSocket=require('ws');
|
|
11
|
+
const root=path.join(__dirname,'../static');
|
|
12
|
+
test('touch double-tap drag and image-menu right click use bundled xterm', {skip:!process.env.CHROMIUM_HEADLESS,timeout:60000},async()=>{
|
|
13
|
+
const bundle=fs.readFileSync(path.join(root,'js/gotty.js'),'utf8').replace('(i.nc = void 0));','(i.nc = void 0)); window.TestGoTTYXterm = i(634).GoTTYXterm;');
|
|
14
|
+
const server=http.createServer((req,res)=>{
|
|
15
|
+
if(req.url==='/index.css'){res.setHeader('Content-Type','text/css');res.end(fs.readFileSync(path.join(root,'css/index.css')));}
|
|
16
|
+
else if(req.url==='/bundle.js'){res.setHeader('Content-Type','text/javascript');res.end(bundle);}
|
|
17
|
+
else if(req.url==='/gestures.js'){
|
|
18
|
+
const source=fs.readFileSync(path.join(root,'js/kitty.js'),'utf8');
|
|
19
|
+
res.setHeader('Content-Type','text/javascript');
|
|
20
|
+
res.end(source.slice(source.indexOf(' function reportTouchMouse('),source.indexOf(' function ensureContextMenu('))+source.slice(source.indexOf(' function ensureContextMenu('),source.indexOf(' function bindImageContextMenu('))+source.slice(source.indexOf(' function bindImageContextMenu('),source.indexOf(' function bindImageContextMenu(')+source.slice(source.indexOf(' function bindImageContextMenu(')).indexOf('\n function ',5))+'\nbindTouchScrolling();bindImageContextMenu();');
|
|
21
|
+
}
|
|
22
|
+
else if(req.url==='/keyboard.js'){res.setHeader('Content-Type','text/javascript');res.end(fs.readFileSync(path.join(root,'js/kitty-keyboard.js')));}
|
|
23
|
+
else res.end('<!doctype html><div id="terminal"><div id="fixture" style="width:800px;height:600px"></div></div><link rel="stylesheet" href="/index.css"><script src="/keyboard.js"></script><script src="/bundle.js"></script><script>window.wrapper=new TestGoTTYXterm(document.getElementById("fixture"));window.sent=[];wrapper.onInput(b=>sent.push(new TextDecoder().decode(b)));wrapper.kittyKeyboard.android=true;</script>');
|
|
24
|
+
});
|
|
25
|
+
server.listen(0,'127.0.0.1');await once(server,'listening');
|
|
26
|
+
const child=spawn(process.env.CHROMIUM_HEADLESS,['--no-sandbox','--disable-gpu','--remote-debugging-port=0','http://127.0.0.1:'+server.address().port],{detached:true,stdio:['ignore','ignore','pipe']});
|
|
27
|
+
let ws;
|
|
28
|
+
try{
|
|
29
|
+
const endpoint=await new Promise((resolve,reject)=>{let log='';const timer=setTimeout(()=>reject(Error('Browser startup timeout: '+log)),15000);child.on('error',reject);child.on('exit',code=>{clearTimeout(timer);reject(Error('Browser exited '+code+': '+log));});child.stderr.on('data',b=>{log+=b;const m=log.match(/DevTools listening on (ws:\/\/[^\s]+)/);if(m){clearTimeout(timer);resolve(m[1]);}});});
|
|
30
|
+
const u=new URL(endpoint);let tab;
|
|
31
|
+
for(let i=0;i<50;i++){tab=(await (await fetch('http://'+u.host+'/json/list')).json()).find(x=>x.type==='page');if(tab)break;await new Promise(r=>setTimeout(r,100));}
|
|
32
|
+
ws=new WebSocket(tab.webSocketDebuggerUrl);await once(ws,'open');let id=0;const pending=new Map();ws.on('message',data=>{const m=JSON.parse(data);if(pending.has(m.id)){const {resolve,reject}=pending.get(m.id);pending.delete(m.id);m.error?reject(m.error):resolve(m.result);}});
|
|
33
|
+
const call=(method,params)=>new Promise((resolve,reject)=>{pending.set(++id,{resolve,reject});ws.send(JSON.stringify({id,method,params}));});
|
|
34
|
+
for(let i=0;i<50;i++){const r=await call('Runtime.evaluate',{expression:'Boolean(window.wrapper)',returnByValue:true});if(r.result.value)break;await new Promise(r=>setTimeout(r,100));}
|
|
35
|
+
const result=await call('Runtime.evaluate',{awaitPromise:true,returnByValue:true,expression:`(async()=>{
|
|
36
|
+
const term=wrapper.term;
|
|
37
|
+
const write=s=>new Promise(r=>term.write(s,r));
|
|
38
|
+
const equal=(a,b)=>{if(JSON.stringify(a)!==JSON.stringify(b))throw Error(JSON.stringify({actual:a,expected:b}));};
|
|
39
|
+
await write('\\x1b[?1002h\\x1b[?1006h');
|
|
40
|
+
const terminal=document.getElementById('fixture');terminal.__gottyXterm=term;
|
|
41
|
+
const screen=term.element.querySelector('.xterm-screen'), rect=screen.getBoundingClientRect();
|
|
42
|
+
const state={placements:new Map()};
|
|
43
|
+
const xtermElements=()=>({screen});
|
|
44
|
+
const DEFAULT_TOUCH_SCROLL_THRESHOLD=24;
|
|
45
|
+
const removePlacementNode=node=>node.remove();
|
|
46
|
+
eval(await (await fetch('/gestures.js')).text());
|
|
47
|
+
const touch=(type,x=30,y=30,count=1)=>{
|
|
48
|
+
const point=new Touch({identifier:1,target:screen,clientX:rect.left+x,clientY:rect.top+y});
|
|
49
|
+
const touches=type==='touchend'||type==='touchcancel'?[]:count===1?[point]:[point,new Touch({identifier:2,target:screen,clientX:rect.left+x+30,clientY:rect.top+y})];
|
|
50
|
+
const event=new TouchEvent(type,{bubbles:true,cancelable:true,touches,changedTouches:[point]});
|
|
51
|
+
screen.dispatchEvent(event);return event.defaultPrevented;
|
|
52
|
+
};
|
|
53
|
+
const codes=()=>sent.map(s=>{const m=s.match(/<([0-9]+);[0-9]+;[0-9]+([Mm])/);return m?m[1]+m[2]:s;});
|
|
54
|
+
let focusCalls=0;const originalFocus=term._core.focus;term._core.focus=function(...args){focusCalls++;return originalFocus.apply(this,args);};
|
|
55
|
+
const firstTap=()=>{touch('touchstart');touch('touchend');
|
|
56
|
+
// Browser compatibility mouse sequence after an ordinary tap.
|
|
57
|
+
for(const type of ['mousedown','mouseup'])screen.dispatchEvent(new MouseEvent(type,{bubbles:true,clientX:rect.left+30,clientY:rect.top+30,button:0,buttons:type==='mousedown'?1:0}));};
|
|
58
|
+
sent.length=0;firstTap();equal(codes(),['0M','0m']);
|
|
59
|
+
const focusBeforeDrag=focusCalls;
|
|
60
|
+
if(!touch('touchstart'))throw Error('Second press must suppress compatibility click');
|
|
61
|
+
equal(codes(),['0M','0m','0M']); // still held, no premature release
|
|
62
|
+
touch('touchmove',80,70);touch('touchend',80,70);
|
|
63
|
+
equal(codes(),['0M','0m','0M','32M','0m']);
|
|
64
|
+
equal(focusCalls,focusBeforeDrag);
|
|
65
|
+
sent.length=0;firstTap();touch('touchstart');touch('touchend');
|
|
66
|
+
equal(codes(),['0M','0m','0M','0m']); // ordinary double click
|
|
67
|
+
for(const cancel of [()=>touch('touchcancel'),()=>touch('touchstart',30,30,2),()=>window.dispatchEvent(new Event('blur')),()=>state.cancelTouchGesture()]){
|
|
68
|
+
sent.length=0;firstTap();touch('touchstart');cancel();touch('touchend');equal(codes(),['0M','0m','0M','0m']);
|
|
69
|
+
}
|
|
70
|
+
sent.length=0;firstTap();touch('touchstart');
|
|
71
|
+
touch('touchmove',-200,-200);touch('touchend',-200,-200);
|
|
72
|
+
equal(codes(),['0M','0m','0M','32M','0m']); // release outside grid still reaches application
|
|
73
|
+
sent.length=0;touch('touchstart');touch('touchmove',30,90);touch('touchend',30,90);
|
|
74
|
+
if(!codes().length||codes().some(x=>!x.startsWith('64')))throw Error('Single touch must remain scrolling: '+codes());
|
|
75
|
+
sent.length=0;touch('touchstart');touch('touchmove',30,90);touch('touchend',30,90);
|
|
76
|
+
if(codes().some(x=>x==='0M'))throw Error('Scroll must not arm double tap');
|
|
77
|
+
// Use precisely the existing image context-menu path, with its original location.
|
|
78
|
+
const node=document.createElement('div');node.style.zIndex='0';node.getBoundingClientRect=()=>({left:0,top:0,right:1000,bottom:1000});state.placements.set('image',node);
|
|
79
|
+
screen.dispatchEvent(new MouseEvent('contextmenu',{bubbles:true,cancelable:true,clientX:rect.left+30,clientY:rect.top+30,button:2}));
|
|
80
|
+
if(state.contextMenu.root.hidden)throw Error('Menu missing');
|
|
81
|
+
const focusBeforeRight=focusCalls;
|
|
82
|
+
sent.length=0;state.contextMenu.rightButton.click();equal(focusCalls,focusBeforeRight);equal(codes(),['2M','2m']);
|
|
83
|
+
if(!state.contextMenu.root.hidden||!state.placements.has('image'))throw Error('Right click must hide menu and preserve image');
|
|
84
|
+
await write('\\x1b[?1002l');state.cancelTouchGesture();sent.length=0;
|
|
85
|
+
firstTap();touch('touchstart');touch('touchmove',80,70);touch('touchend');
|
|
86
|
+
if(codes().some(x=>/^[032][Mm]$/.test(x)))throw Error('No application mouse reporting outside mouse mode');
|
|
87
|
+
state.cancelTouchGesture();state.placements.clear();
|
|
88
|
+
term.focus();const textarea=term.textarea;
|
|
89
|
+
screen.dispatchEvent(new MouseEvent('contextmenu',{bubbles:true,cancelable:true,clientX:rect.left+30,clientY:rect.top+30,button:2}));
|
|
90
|
+
if(document.activeElement!==textarea)throw Error('Context menu must keep textarea focused for native paste');
|
|
91
|
+
const data=new DataTransfer();data.setData('text/plain','paste-check');sent.length=0;
|
|
92
|
+
textarea.dispatchEvent(new ClipboardEvent('paste',{bubbles:true,cancelable:true,clipboardData:data}));
|
|
93
|
+
if(!sent.join('').includes('paste-check'))throw Error('Paste stopped working');
|
|
94
|
+
equal(getComputedStyle(textarea).touchAction,'none');
|
|
95
|
+
equal(getComputedStyle(screen).touchAction,'manipulation');
|
|
96
|
+
touch('touchstart');
|
|
97
|
+
if(document.activeElement!==textarea)throw Error('Touch must not blur the input');
|
|
98
|
+
touch('touchend');
|
|
99
|
+
wrapper.close();return 'ok';
|
|
100
|
+
})()`});
|
|
101
|
+
assert.equal(result.exceptionDetails,undefined,JSON.stringify(result.exceptionDetails));assert.equal(result.result.value,'ok');
|
|
102
|
+
}finally{
|
|
103
|
+
ws?.close();if(child.pid){try{process.kill(-child.pid,'SIGTERM');}catch{}}
|
|
104
|
+
server.closeAllConnections();await new Promise(r=>server.close(r));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Opt-in real bundled-xterm integration; no browser/dependency downloads.
|
|
2
|
+
// CHROMIUM_HEADLESS=/path/to/chromium-headless-shell node --test tests/kitty-keyboard-browser.test.js
|
|
3
|
+
const test=require('node:test');
|
|
4
|
+
const assert=require('node:assert/strict');
|
|
5
|
+
const fs=require('node:fs');
|
|
6
|
+
const path=require('node:path');
|
|
7
|
+
const http=require('node:http');
|
|
8
|
+
const {spawn}=require('node:child_process');
|
|
9
|
+
const {once}=require('node:events');
|
|
10
|
+
const WebSocket=require('ws');
|
|
11
|
+
const root=path.join(__dirname,'../static');
|
|
12
|
+
test('shipped xterm reports horizontal, vertical and diagonal wheel events', {skip:!process.env.CHROMIUM_HEADLESS,timeout:60000},async()=>{
|
|
13
|
+
const bundle=fs.readFileSync(path.join(root,'js/gotty.js'),'utf8').replace('(i.nc = void 0));','(i.nc = void 0)); window.TestGoTTYXterm = i(634).GoTTYXterm;');
|
|
14
|
+
const server=http.createServer((req,res)=>{
|
|
15
|
+
if(req.url==='/bundle.js'){res.setHeader('Content-Type','text/javascript');res.end(bundle);}
|
|
16
|
+
else if(req.url==='/keyboard.js'){res.setHeader('Content-Type','text/javascript');res.end(fs.readFileSync(path.join(root,'js/kitty-keyboard.js')));}
|
|
17
|
+
else res.end('<!doctype html><div id="fixture" style="width:800px;height:600px"></div><script src="/keyboard.js"></script><script src="/bundle.js"></script><script>window.wrapper=new TestGoTTYXterm(document.getElementById("fixture"));window.sent=[];wrapper.onInput(b=>sent.push(new TextDecoder().decode(b)));wrapper.kittyKeyboard.android=true;</script>');
|
|
18
|
+
});
|
|
19
|
+
server.listen(0,'127.0.0.1');await once(server,'listening');
|
|
20
|
+
const child=spawn(process.env.CHROMIUM_HEADLESS,['--no-sandbox','--disable-gpu','--remote-debugging-port=0','http://127.0.0.1:'+server.address().port],{detached:true,stdio:['ignore','ignore','pipe']});
|
|
21
|
+
let ws;
|
|
22
|
+
try{
|
|
23
|
+
const endpoint=await new Promise((resolve,reject)=>{let log='';const timer=setTimeout(()=>reject(Error('Browser startup timeout: '+log)),15000);child.on('error',reject);child.on('exit',code=>{clearTimeout(timer);reject(Error('Browser exited '+code+': '+log));});child.stderr.on('data',b=>{log+=b;const m=log.match(/DevTools listening on (ws:\/\/[^\s]+)/);if(m){clearTimeout(timer);resolve(m[1]);}});});
|
|
24
|
+
const u=new URL(endpoint);let tab;
|
|
25
|
+
for(let i=0;i<50;i++){tab=(await (await fetch('http://'+u.host+'/json/list')).json()).find(x=>x.type==='page');if(tab)break;await new Promise(r=>setTimeout(r,100));}
|
|
26
|
+
ws=new WebSocket(tab.webSocketDebuggerUrl);await once(ws,'open');let id=0;const pending=new Map();ws.on('message',data=>{const m=JSON.parse(data);if(pending.has(m.id)){const {resolve,reject}=pending.get(m.id);pending.delete(m.id);m.error?reject(m.error):resolve(m.result);}});
|
|
27
|
+
const call=(method,params)=>new Promise((resolve,reject)=>{pending.set(++id,{resolve,reject});ws.send(JSON.stringify({id,method,params}));});
|
|
28
|
+
for(let i=0;i<50;i++){const r=await call('Runtime.evaluate',{expression:'Boolean(window.wrapper)',returnByValue:true});if(r.result.value)break;await new Promise(r=>setTimeout(r,100));}
|
|
29
|
+
const result=await call('Runtime.evaluate',{awaitPromise:true,returnByValue:true,expression:`(async()=>{
|
|
30
|
+
const term=wrapper.term;
|
|
31
|
+
const write=s=>new Promise(r=>term.write(s,r));
|
|
32
|
+
const equal=(a,b)=>{if(JSON.stringify(a)!==JSON.stringify(b))throw Error(JSON.stringify({actual:a,expected:b}));};
|
|
33
|
+
await write('\\x1b[?1002h\\x1b[?1006h');
|
|
34
|
+
const screen=term.element.querySelector('.xterm-screen'), rect=screen.getBoundingClientRect();
|
|
35
|
+
const wheel=(deltaX,deltaY,mods={})=>{
|
|
36
|
+
sent.length=0;
|
|
37
|
+
const event=new WheelEvent('wheel',{clientX:rect.left+20,clientY:rect.top+20,deltaX,deltaY,deltaMode:1,bubbles:true,cancelable:true,...mods});
|
|
38
|
+
screen.dispatchEvent(event);
|
|
39
|
+
if(term._core.coreMouseService.areMouseEventsActive&&!event.defaultPrevented)throw Error('Wheel default was not prevented');
|
|
40
|
+
return sent.map(s=>Number(s.match(/<([0-9]+);/)[1]));
|
|
41
|
+
};
|
|
42
|
+
equal(wheel(-1,0),[66]);equal(wheel(1,0),[67]);
|
|
43
|
+
equal(wheel(0,-1,{shiftKey:true}),[68]);equal(wheel(0,1,{shiftKey:true}),[69]);
|
|
44
|
+
equal(wheel(0,-1),[64]);equal(wheel(0,1),[65]);
|
|
45
|
+
equal(wheel(1,-1),[67,64]);
|
|
46
|
+
equal(wheel(-1,0,{shiftKey:true,altKey:true,ctrlKey:true}),[94]);
|
|
47
|
+
for(let bits=0;bits<8;bits++) {
|
|
48
|
+
const mods={shiftKey:!!(bits&1),altKey:!!(bits&2),ctrlKey:!!(bits&4)};
|
|
49
|
+
for(const [dx,dy,code] of [[0,-1,64],[0,1,65],[-1,0,66],[1,0,67]])
|
|
50
|
+
equal(wheel(dx,dy,mods),[code+(bits<<2)]);
|
|
51
|
+
}
|
|
52
|
+
await write('\\x1b[?1002l');equal(wheel(1,0),[]);
|
|
53
|
+
wrapper.close();return 'ok';
|
|
54
|
+
})()`});
|
|
55
|
+
assert.equal(result.exceptionDetails,undefined,JSON.stringify(result.exceptionDetails));assert.equal(result.result.value,'ok');
|
|
56
|
+
}finally{
|
|
57
|
+
ws?.close();if(child.pid){try{process.kill(-child.pid,'SIGTERM');}catch{}}
|
|
58
|
+
server.closeAllConnections();await new Promise(r=>server.close(r));
|
|
59
|
+
}
|
|
60
|
+
});
|