Skip to content

Commit 6cfeaef

Browse files
milestone 3.3E: basic support for keyboard/handcontrols in terminal
1 parent 6f04818 commit 6cfeaef

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

com/isoterminal/feat/term.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ ISOTerminal.prototype.TermInit = function(){
1313
rows: aEntity.rows,
1414
el_or_id: el,
1515
scrollback: aEntity.rows*3,
16-
fontSize: null //
16+
fontSize: null,
1717
//rainbow: [Term.COLOR_MAGENTA, Term.COLOR_CYAN ],
18-
//xr: AFRAME.scenes[0].renderer.xr,
18+
isWebXRKeyboard: () => AFRAME.scenes[0].renderer.xr.isPresenting && AFRAME.scenes[0].renderer.xr.getSession().isSystemKeyboardSupported, // naive way
1919
//map: {
2020
// 'ArrowRight': { ch: false, ctrl: '\x1b\x66' }, // this triggers ash-shell forward-word
2121
// 'ArrowLeft': { ch: false, ctrl: '\x1b\x62' } // backward-word

com/isoterminal/term.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function Term(options)
3131
{
3232
}
3333

34+
this.options = options
3435
width = options.cols ? options.cols : 80;
3536
height = options.rows ? options.rows : 25;
3637
scrollback = options.scrollback ? options.scrollback : 0;
@@ -101,6 +102,9 @@ function Term(options)
101102
this.linux_console = true;
102103

103104
this.textarea_has_focus = false;
105+
106+
// remember last data (to help WebXRKeyboard decide whether onblur should imply 'enter')
107+
this.last = { keydown: '', input: '', inputValue: ''}
104108
}
105109

106110
Term.prototype.setKeyHandler = function(handler)
@@ -1154,6 +1158,7 @@ Term.prototype.keyDownHandler = function (ev)
11541158
}
11551159
break;
11561160
}
1161+
this.last.keydown = str
11571162
// console.log("keydown: keycode=" + ev.keyCode + " charcode=" + ev.charCode + " str=" + str + " ctrl=" + ev.ctrlKey + " alt=" + ev.altKey + " meta=" + ev.metaKey);
11581163
if (str) {
11591164
if (ev.stopPropagation)
@@ -1204,7 +1209,13 @@ Term.prototype.to_utf8 = function(s)
12041209
Term.prototype.inputHandler = function (ev)
12051210
{
12061211
var str;
1207-
str = this.textarea_el.value;
1212+
// edge-case: Meta's WebXRKeyboard implementation requires us to use .value
1213+
str = this.last.input = this.textarea_el.value.split("").pop();
1214+
// edge-case: detect backspace based on length-change [Meta's WebXRKeyboard]
1215+
if( (this.textarea_el.value.length + 1) == this.last.inputValue.length ){
1216+
str = '\b'
1217+
}
1218+
this.last.inputValue = this.textarea_el.value
12081219
if (str) {
12091220
this.textarea_el.value = "";
12101221
this.show_cursor();
@@ -1243,6 +1254,7 @@ Term.prototype.blurHandler = function (ev)
12431254
/* allow unloading the page */
12441255
window.onbeforeunload = null;
12451256
this.textarea_has_focus = false;
1257+
if( this.last.keydown != "\n" && this.last.input && this.options.isWebXRKeyboard() ) this.handler("\n")
12461258
};
12471259

12481260
Term.prototype.pasteHandler = function (ev)

0 commit comments

Comments
 (0)