2024-09-03 18:33:35 +02:00
|
|
|
ISOTerminal.addEventListener('init', function(){
|
|
|
|
if( typeof Terminal != 'undefined' ) this.xtermInit()
|
|
|
|
})
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
ISOTerminal.addEventListener('runISO', function(e){
|
|
|
|
let opts = e.detail
|
|
|
|
opts.serial_container_xtermjs = opts.screen_container
|
|
|
|
delete opts.screen_container
|
|
|
|
})
|
|
|
|
|
2024-09-03 18:33:35 +02:00
|
|
|
ISOTerminal.prototype.xtermInit = function(){
|
2024-09-16 13:28:28 +02:00
|
|
|
this.serial_input = 0 // set input to serial line 0
|
2024-09-03 18:33:35 +02:00
|
|
|
let isoterm = this
|
|
|
|
// monkeypatch Xterm (which V86 initializes) so we can add our own constructor args
|
|
|
|
window._Terminal = window.Terminal
|
|
|
|
window.Terminal = function(opts){
|
|
|
|
const term = new window._Terminal({ ...opts,
|
|
|
|
cursorBlink:true,
|
2024-09-17 18:59:38 +02:00
|
|
|
onSelectionChange: function(e){ console.log("selectchange") },
|
2024-09-16 13:28:28 +02:00
|
|
|
letterSpacing: 0
|
2024-09-03 18:33:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
term.onSelectionChange( () => {
|
|
|
|
document.execCommand('copy')
|
|
|
|
term.select(0, 0, 0)
|
|
|
|
isoterm.emit('status','copied to clipboard')
|
|
|
|
})
|
2024-09-23 22:31:28 +02:00
|
|
|
|
|
|
|
term.onRender( () => {
|
2024-09-24 16:27:48 +02:00
|
|
|
// xterm relies on requestAnimationFrame (which does not called in immersive mode)
|
2024-09-24 11:53:23 +02:00
|
|
|
let _window = term._core._coreBrowserService._window
|
2024-09-25 15:58:40 +02:00
|
|
|
if( !_window._XRSH_proxied ){ // patch the planet!
|
2024-09-24 11:53:23 +02:00
|
|
|
|
2024-09-25 15:58:40 +02:00
|
|
|
//_window.requestAnimationFrameAFRAME = function(cb){
|
|
|
|
// if( term.tid != null ) clearTimeout(term.tid)
|
|
|
|
// term.tid = setTimeout( function(){
|
|
|
|
// console.log("render")
|
|
|
|
// cb()
|
|
|
|
// term.tid = null
|
|
|
|
// },100)
|
|
|
|
//}
|
2024-10-01 19:07:03 +02:00
|
|
|
this.i = 0
|
2024-09-25 15:58:40 +02:00
|
|
|
const requestAnimationFrameAFRAME = AFRAME.utils.throttleLeadingAndTrailing(
|
2024-10-01 19:07:03 +02:00
|
|
|
function(cb){ cb() }
|
|
|
|
,150
|
2024-09-25 15:58:40 +02:00
|
|
|
)
|
2024-09-24 11:53:23 +02:00
|
|
|
|
|
|
|
// we proxy the _window object of xterm, and reroute
|
|
|
|
// requestAnimationFrame to requestAnimationFrameAFRAME
|
2024-09-25 15:58:40 +02:00
|
|
|
_window_new = new Proxy(_window,{
|
2024-09-24 11:53:23 +02:00
|
|
|
get(me,k){
|
2024-09-25 15:58:40 +02:00
|
|
|
if( k == '_XRSH_proxied' ) return true
|
2024-09-24 11:53:23 +02:00
|
|
|
if( k == 'requestAnimationFrame' ){
|
2024-09-25 15:58:40 +02:00
|
|
|
return requestAnimationFrameAFRAME.bind(me)
|
2024-09-24 11:53:23 +02:00
|
|
|
}
|
2024-09-25 15:58:40 +02:00
|
|
|
return typeof me[k] == 'function' ? me[k].bind(me) : me[k]
|
2024-09-24 11:53:23 +02:00
|
|
|
},
|
|
|
|
set(me,k,v){
|
|
|
|
me[k] = v
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
})
|
2024-09-25 15:58:40 +02:00
|
|
|
term._core._coreBrowserService._window = _window_new
|
2024-09-23 22:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2024-09-03 18:33:35 +02:00
|
|
|
return term
|
|
|
|
}
|
|
|
|
|
2024-09-23 22:31:28 +02:00
|
|
|
|
2024-09-03 18:33:35 +02:00
|
|
|
this.addEventListener('emulator-started', function(){
|
|
|
|
this.emulator.serial_adapter.term.element.querySelector('.xterm-viewport').style.background = 'transparent'
|
2024-09-06 18:02:54 +02:00
|
|
|
// toggle immersive with ESCAPE
|
|
|
|
//document.body.addEventListener('keydown', (e) => e.key == 'Escape' && this.emulator.serial_adapter.term.blur() )
|
2024-09-03 18:33:35 +02:00
|
|
|
})
|
2024-09-16 13:28:28 +02:00
|
|
|
|
|
|
|
const resize = (w,h) => {
|
|
|
|
setTimeout( () => {
|
2024-09-23 22:31:28 +02:00
|
|
|
if( isoterm?.emulator?.serial_adapter?.term ){
|
|
|
|
isoterm.xtermAutoResize(isoterm.emulator.serial_adapter.term, isoterm.instance,-3)
|
|
|
|
}
|
2024-09-16 13:28:28 +02:00
|
|
|
},800) // wait for resize anim
|
|
|
|
}
|
|
|
|
isoterm.instance.addEventListener('window.onresize', resize )
|
|
|
|
isoterm.instance.addEventListener('window.onmaximize', resize )
|
2024-09-03 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISOTerminal.prototype.xtermAutoResize = function(term,instance,rowoffset){
|
|
|
|
if( !term.element ) return
|
|
|
|
|
|
|
|
const defaultScrollWidth = 24;
|
|
|
|
const MINIMUM_COLS = 2;
|
|
|
|
const MINIMUM_ROWS = 2;
|
|
|
|
|
|
|
|
const dims = term._core._renderService.dimensions;
|
|
|
|
const scrollbarWidth = (term.options.scrollback === 0
|
|
|
|
? 0
|
|
|
|
: (term.options.overviewRuler?.width || defaultScrollWidth ));
|
|
|
|
|
|
|
|
const parentElementStyle = window.getComputedStyle(instance.dom);
|
|
|
|
const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
|
|
|
|
const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));
|
|
|
|
const elementStyle = window.getComputedStyle(term.element);
|
|
|
|
const elementPadding = {
|
|
|
|
top: parseInt(elementStyle.getPropertyValue('padding-top')),
|
|
|
|
bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),
|
|
|
|
right: parseInt(elementStyle.getPropertyValue('padding-right')),
|
|
|
|
left: parseInt(elementStyle.getPropertyValue('padding-left'))
|
|
|
|
};
|
|
|
|
const elementPaddingVer = elementPadding.top + elementPadding.bottom;
|
|
|
|
const elementPaddingHor = elementPadding.right + elementPadding.left;
|
|
|
|
const availableHeight = parentElementHeight - elementPaddingVer;
|
|
|
|
const availableWidth = parentElementWidth - elementPaddingHor - scrollbarWidth;
|
|
|
|
const geometry = {
|
|
|
|
cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / dims.css.cell.width)),
|
|
|
|
rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / dims.css.cell.height))
|
|
|
|
};
|
|
|
|
term.resize(geometry.cols, geometry.rows + (rowoffset||0) );
|
|
|
|
}
|