vTerm: fix bug with new xterm.js

This commit is contained in:
DanyLE 2023-01-04 09:55:18 +01:00
parent 5dc066c3f7
commit a4fc0119be
8 changed files with 7 additions and 6 deletions

View File

@ -455,7 +455,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/vTerm/README.md",
"category": "System",
"author": "Xuan Sang LE",
"version": "0.1.19-a",
"version": "0.1.20-a",
"dependencies": ["Antunnel@0.2.1-b","xTerm@5.1.0-r"],
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/vTerm/build/release/vTerm.zip"
},

View File

@ -12,6 +12,7 @@ VTerm depends on the server side **tunnel** plugin and the AntOS **Antunnel**
client side package
## Change logs
- v0.1.20-fix bug with new xterm.js
- v0.1.19-a Use the new xterm.js libraries v5.1.0
- v0.1.18-a support AntOS v2.0.x
- v0.1.17-a update dependencies to latest

View File

@ -12,6 +12,7 @@ VTerm depends on the server side **tunnel** plugin and the AntOS **Antunnel**
client side package
## Change logs
- v0.1.20-fix bug with new xterm.js
- v0.1.19-a Use the new xterm.js libraries v5.1.0
- v0.1.18-a support AntOS v2.0.x
- v0.1.17-a update dependencies to latest

View File

@ -1 +1 @@
(function(){var t;(t=class extends this.OS.application.BaseApplication{constructor(t){super("vTerm",t)}main(){var t;return this.mterm=this.find("myterm"),this.term=new Terminal({cursorBlink:!0}),this.fitAddon=new FitAddon.FitAddon,this.term.loadAddon(this.fitAddon),this.term.setOption("fontSize","12"),this.term.open(this.mterm),this.sub=void 0,this.bindKey("CTRL-SHIFT-C",t=>(this.mctxHandle({id:"copy"}),this.term.focus())),this.bindKey("CTRL-SHIFT-V",t=>this.mctxHandle({id:"paste"})),this.term.onKey(t=>{if(this.sub)return this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t.key))}),this.on("focus",()=>this.term.focus()),this.mterm.contextmenuHandle=(t,e)=>(e.items=[{text:"__(Copy)",id:"copy"},{text:"__(Paste)",id:"paste"}],e.onmenuselect=t=>{if(t)return this.mctxHandle(t.data.item.data)},e.show(t)),this.resizeContent(),this.systemsetting.desktop.menu[this.name]||(this.systemsetting.desktop.menu[this.name]={text:"__(Open terminal)",app:"vTerm"}),this.on("resize",t=>this.resizeContent()),t=()=>Antunnel.tunnel?(this.tunnel=Antunnel.tunnel,this.openSession()):this._gui.pushService("Antunnel/AntunnelService").then(t=>{if(this.systemsetting.system.tunnel_uri)return Antunnel.init(this.systemsetting.system.tunnel_uri).then(t=>(this.notify(__("Tunnel now connected to the server at: {0}",this.systemsetting.system.tunnel_uri)),this.tunnel=Antunnel.tunnel,this.openSession())).catch(t=>(Antunnel.tunnel&&Antunnel.tunnel.close(),this.error(__("Unable to connect to the tunnel: {0}",t.toString()),t),this.quit()))}).catch(t=>(this.error(__("Unable to run Antunnel service: {0}",t.toString()),t),this.quit())),window.Antunnel?t():this._api.requires("pkg://Antunnel/main.js").then(()=>t()).catch(t=>(this.error(__("Unable to load Antunnel: {0}",t.toString()),t),this.quit()))}mctxHandle(t){var e,n;switch(t.id){case"paste":return e=t=>{if(t&&""!==t)return t=t.replace(/\n/g,"\r"),this.sub&&this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t)),this.term.focus()},this._api.getClipboard().then(t=>e(t)).catch(t=>(this.error(__("Unable to paste"),t),this.openDialog("TextDialog",{title:"Paste text"}).then(t=>e(t)).catch(t=>this.error(t.toString(),t))));case"copy":if(!(n=this.term.getSelection())||""===n)return;return this._api.setClipboard(n)}}resizeContent(){var t,e,n;if(this.fitAddon.fit(),e=this.term.cols,n=this.term.rows,this.sub)return(t=new Uint8Array(8)).set(Antunnel.Msg.bytes_of(e,4),0),t.set(Antunnel.Msg.bytes_of(n,4),4),this.sub.send(Antunnel.Msg.CTRL,t)}openSession(){return this.term.clear(),this.term.focus(),this.sub=new Antunnel.Subscriber("vterm"),this.sub.onopen=()=>(console.log("Subscribed"),this.resizeContent($(this.mterm).width(),$(this.mterm).height()),this.term.focus()),this.sub.onerror=t=>(this.error(__("Unable to connect to: vterm"),t),this.sub=void 0),this.sub.onmessage=t=>{if(this.term&&t.data)return this.term.write(new TextDecoder("utf-8").decode(t.data))},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Terminal connection closed")),this.quit()),this.tunnel.subscribe(this.sub)}cleanup(t){if(this.sub)return this.sub.close()}}).dependencies=["pkg://xTerm/main.js","pkg://xTerm/main.css","pkg://Antunnel/main.js"],this.OS.register("vTerm",t)}).call(this);
(function(){var t;(t=class extends this.OS.application.BaseApplication{constructor(t){super("vTerm",t)}main(){var t;return this.mterm=this.find("myterm"),this.term=new Terminal({cursorBlink:!0,fontSize:12}),this.fitAddon=new FitAddon.FitAddon,this.term.loadAddon(this.fitAddon),this.term.open(this.mterm),this.sub=void 0,this.bindKey("CTRL-SHIFT-C",t=>(this.mctxHandle({id:"copy"}),this.term.focus())),this.bindKey("CTRL-SHIFT-V",t=>this.mctxHandle({id:"paste"})),this.term.onKey(t=>{if(this.sub)return this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t.key))}),this.on("focus",()=>this.term.focus()),this.mterm.contextmenuHandle=(t,e)=>(e.items=[{text:"__(Copy)",id:"copy"},{text:"__(Paste)",id:"paste"}],e.onmenuselect=t=>{if(t)return this.mctxHandle(t.data.item.data)},e.show(t)),this.resizeContent(),this.systemsetting.desktop.menu[this.name]||(this.systemsetting.desktop.menu[this.name]={text:"__(Open terminal)",app:"vTerm"}),this.on("resize",t=>this.resizeContent()),t=()=>Antunnel.tunnel?(this.tunnel=Antunnel.tunnel,this.openSession()):this._gui.pushService("Antunnel/AntunnelService").then(t=>{if(this.systemsetting.system.tunnel_uri)return Antunnel.init(this.systemsetting.system.tunnel_uri).then(t=>(this.notify(__("Tunnel now connected to the server at: {0}",this.systemsetting.system.tunnel_uri)),this.tunnel=Antunnel.tunnel,this.openSession())).catch(t=>(Antunnel.tunnel&&Antunnel.tunnel.close(),this.error(__("Unable to connect to the tunnel: {0}",t.toString()),t),this.quit()))}).catch(t=>(this.error(__("Unable to run Antunnel service: {0}",t.toString()),t),this.quit())),window.Antunnel?t():this._api.requires("pkg://Antunnel/main.js").then(()=>t()).catch(t=>(this.error(__("Unable to load Antunnel: {0}",t.toString()),t),this.quit()))}mctxHandle(t){var e,n;switch(t.id){case"paste":return e=t=>{if(t&&""!==t)return t=t.replace(/\n/g,"\r"),this.sub&&this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t)),this.term.focus()},this._api.getClipboard().then(t=>e(t)).catch(t=>(this.error(__("Unable to paste"),t),this.openDialog("TextDialog",{title:"Paste text"}).then(t=>e(t)).catch(t=>this.error(t.toString(),t))));case"copy":if(!(n=this.term.getSelection())||""===n)return;return this._api.setClipboard(n)}}resizeContent(){var t,e,n;if(this.fitAddon.fit(),e=this.term.cols,n=this.term.rows,this.sub)return(t=new Uint8Array(8)).set(Antunnel.Msg.bytes_of(e,4),0),t.set(Antunnel.Msg.bytes_of(n,4),4),this.sub.send(Antunnel.Msg.CTRL,t)}openSession(){return this.term.clear(),this.term.focus(),this.sub=new Antunnel.Subscriber("vterm"),this.sub.onopen=()=>(console.log("Subscribed"),this.resizeContent($(this.mterm).width(),$(this.mterm).height()),this.term.focus()),this.sub.onerror=t=>(this.error(__("Unable to connect to: vterm"),t),this.sub=void 0),this.sub.onmessage=t=>{if(this.term&&t.data)return this.term.write(new TextDecoder("utf-8").decode(t.data))},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Terminal connection closed")),this.quit()),this.tunnel.subscribe(this.sub)}cleanup(t){if(this.sub)return this.sub.close()}}).dependencies=["pkg://xTerm/main.js","pkg://xTerm/main.css","pkg://Antunnel/main.js"],this.OS.register("vTerm",t)}).call(this);

View File

@ -7,7 +7,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1.19-a",
"version":"0.1.20-a",
"category":"System",
"iconclass":"bi bi-terminal-fill",
"mimes":["none"],

Binary file not shown.

View File

@ -22,10 +22,9 @@ class vTerm extends this.OS.application.BaseApplication
main: () ->
@mterm = @find "myterm"
@term = new Terminal { cursorBlink: true }
@term = new Terminal { cursorBlink: true, fontSize: 12 }
@fitAddon = new FitAddon.FitAddon()
@term.loadAddon(@fitAddon)
@term.setOption('fontSize', '12')
@term.open @mterm
@sub = undefined

View File

@ -7,7 +7,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1.19-a",
"version":"0.1.20-a",
"category":"System",
"iconclass":"bi bi-terminal-fill",
"mimes":["none"],