better js-to-terminal API
This commit is contained in:
parent
1f0710be78
commit
9698cafefd
3 changed files with 39 additions and 6 deletions
|
|
@ -100,6 +100,7 @@ if( typeof AFRAME != 'undefined '){
|
||||||
this.calculateDimension()
|
this.calculateDimension()
|
||||||
this.initHud()
|
this.initHud()
|
||||||
this.setupPasteDrop()
|
this.setupPasteDrop()
|
||||||
|
this.setupEvents()
|
||||||
|
|
||||||
fetch(this.data.iso,{method: 'HEAD'})
|
fetch(this.data.iso,{method: 'HEAD'})
|
||||||
.then( (res) => {
|
.then( (res) => {
|
||||||
|
|
@ -429,6 +430,21 @@ if( typeof AFRAME != 'undefined '){
|
||||||
this.rows = Math.floor( (this.data.height*0.93)/this.data.lineHeight)-1
|
this.rows = Math.floor( (this.data.height*0.93)/this.data.lineHeight)-1
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setupEvents: function(){
|
||||||
|
this.el.addEventListener('exec', (e) => this.term.exec( e.detail ) )
|
||||||
|
this.el.addEventListener('hook', (e) => this.term.hook( e.detail[0], e.detail[1] ) )
|
||||||
|
this.el.addEventListener('send', (e) => this.term.send( e.detail[0], e.detail[1] || 0 ) )
|
||||||
|
this.el.addEventListener('create_file', async (e) => await this.term.worker.create_file( e.detail[0], this.term.convert.toUint8Array(e.detail[1]) ) )
|
||||||
|
this.el.addEventListener('update_file', async (e) => await this.term.worker.update_file( e.detail[0], this.term.convert.toUint8Array(e.detail[1]) ) )
|
||||||
|
this.el.addEventListener('append_file', async (e) => await this.term.worker.append_file( e.detail[0], this.term.convert.toUint8Array(e.detail[1]) ) )
|
||||||
|
this.el.addEventListener('read_file', async (e) => {
|
||||||
|
const buf = await this.term.worker.read_file( e.detail[0] )
|
||||||
|
const str = new TextDecoder().decode(buf)
|
||||||
|
if( typeof e.detail[1] == 'function' ) e.detail[1](str)
|
||||||
|
else console.log(str)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
events:{
|
events:{
|
||||||
|
|
||||||
// combined AFRAME+DOM reactive events
|
// combined AFRAME+DOM reactive events
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,15 @@ if( typeof emulator != 'undefined' ){
|
||||||
]).then( () => {
|
]).then( () => {
|
||||||
|
|
||||||
localforage.getItem("state", async (err,stateBase64) => {
|
localforage.getItem("state", async (err,stateBase64) => {
|
||||||
if( stateBase64 && !err && confirm('continue last session?') ){
|
const askConfirm = () => {
|
||||||
|
try{
|
||||||
|
const scene = document.querySelector('a-scene');
|
||||||
|
if( scene.is('ar-mode') ) scene.exitAR()
|
||||||
|
if( scene.is('vr-mode') ) scene.exitVR()
|
||||||
|
}catch(e){}
|
||||||
|
return confirm('continue last session?')
|
||||||
|
}
|
||||||
|
if( stateBase64 && !err && askConfirm() ){
|
||||||
this.noboot = true // see feat/boot.js
|
this.noboot = true // see feat/boot.js
|
||||||
try{
|
try{
|
||||||
await this.worker.restore_state()
|
await this.worker.restore_state()
|
||||||
|
|
|
||||||
|
|
@ -72,13 +72,18 @@ ISOTerminal.prototype.TermInit = function(){
|
||||||
// as demonstrated in index.html
|
// as demonstrated in index.html
|
||||||
this.term.setKeyHandler( (ch) => {
|
this.term.setKeyHandler( (ch) => {
|
||||||
let erase = false
|
let erase = false
|
||||||
|
const isEnter = ch == '\n' || ch == '\r'
|
||||||
if( ch == '\x7F' ){
|
if( ch == '\x7F' ){
|
||||||
ch = "\b \b" // why does write() not just support \x7F ?
|
ch = "\b \b" // why does write() not just support \x7F ?
|
||||||
erase = true
|
erase = true
|
||||||
}
|
}
|
||||||
if( this.boot.menu.selected ){
|
if( this.boot.menu.selected ){
|
||||||
this.boot.menu.selected.keyHandler.call(this,ch)
|
if( isEnter ){
|
||||||
}else if( (ch == "\n" || ch == "\r") ){
|
this.boot.menu.selected.cmdHandler.call(this,this.lastCmd)
|
||||||
|
this.lastCmd = ""
|
||||||
|
}
|
||||||
|
else this.boot.menu.selected.keyHandler.call(this,ch)
|
||||||
|
}else if( isEnter ){
|
||||||
let menuitem = this.boot.menu.find( (m) => m.key == this.lastChar )
|
let menuitem = this.boot.menu.find( (m) => m.key == this.lastChar )
|
||||||
if( menuitem ){
|
if( menuitem ){
|
||||||
this.boot.menu.selected = menuitem
|
this.boot.menu.selected = menuitem
|
||||||
|
|
@ -88,10 +93,14 @@ ISOTerminal.prototype.TermInit = function(){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
this.term.write( ch )
|
ch.split("").map( (ch) => this.term.write( ch ) )
|
||||||
}
|
}
|
||||||
if( !erase ) this.lastChar = ch
|
if( !erase ){
|
||||||
|
this.lastChar = ch
|
||||||
|
this.lastCmd = this.lastCmd ? this.lastCmd + ch : ch
|
||||||
|
}else this.lastCmd = this.lastCmd ? this.lastCmd.substr(0, this.lastCmd.length-1) : ""
|
||||||
})
|
})
|
||||||
|
|
||||||
aEntity.el.addEventListener('focus', () => {
|
aEntity.el.addEventListener('focus', () => {
|
||||||
let textarea = el.querySelector("textarea")
|
let textarea = el.querySelector("textarea")
|
||||||
textarea.focus()
|
textarea.focus()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue