change the term tty create/destroy functions to something a bit more unixy

This commit is contained in:
Lisa Milne 2023-11-22 09:25:13 +10:00
parent dec325f8b2
commit 4baa505b4d
3 changed files with 12 additions and 11 deletions

View file

@ -364,14 +364,14 @@ Options:
return;
}
var tty = term.createTTY();
var tty = term.opentty();
tty.setRaw(false);
tty.handleKeys(function(e) {
switch (e.key) {
case 'Escape':
case 'q':
term.closeTTY(tty);
term.closetty(tty);
io.exit(0);
break;
case 'Up':

View file

@ -1187,7 +1187,7 @@ clite.term = {
clear:function() { // clears the terminal
clite.term.clear(false);
},
createTTY:function() { // gets an empty element with key events (allows view/less to display content in a clean element)
opentty:function() { // gets an empty element with key events (allows view/less to display content in a clean element)
var tty = {
handleKeys:function(cb) {
this.data.cb = cb;
@ -1243,10 +1243,11 @@ clite.term = {
// TODO: shouldn't need the 0.8 thing, but urgh
tty.chars = parseInt((tty.data.el.offsetWidth/s.offsetWidth)*0.8);
tty.data.el.removeChild(s);
// TODO:
clite.term.events.refocus();
return tty;
},
closeTTY:function(tty) {
closetty:function(tty) {
try{
tty.data.el.parentNode.removeChild(tty.data.el);
clite.term.tty.data = null;
@ -1291,7 +1292,7 @@ clite.shell = {
if (pid > -1)
clite.proc.exit(pid);
if (clite.term.tty.data != null)
clite.term.api.closeTTY(clite.term.tty.data);
clite.term.api.closetty(clite.term.tty.data);
clite.shell.prompt.pop();
clite.term.events.refocus();
},

View file

@ -351,16 +351,16 @@ term: io.include('term')
Clears the current terminal, equivalent to running `clear' from
the shell.
createTTY()
Creates a new 'tty' with raw key events, for custom displays and
interactions. (The less command uses this).
opentty()
Creates a new blank terminal (tty) with raw key events, for
custom displays and interactions. (The less command uses this).
Returns a reference object for interacting with the new tty.
Returns null on error.
var tty = term.createTTY();
var tty = term.opentty();
closeTTY(tty)
Closes a tty opened with createTTY().
closetty(tty)
Closes a tty created with opentty().
Example Programs: