From 4baa505b4dfef92453ae4ceff4cdb554c7ccf47e Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Wed, 22 Nov 2023 09:25:13 +1000 Subject: [PATCH] change the term tty create/destroy functions to something a bit more unixy --- clite/commands.js | 4 ++-- clite/core.js | 7 ++++--- readme.txt | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/clite/commands.js b/clite/commands.js index 264451f..f3c2975 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -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': diff --git a/clite/core.js b/clite/core.js index 6857bf9..a81f4a9 100644 --- a/clite/core.js +++ b/clite/core.js @@ -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(); }, diff --git a/readme.txt b/readme.txt index 5098cc9..c1e9db4 100644 --- a/readme.txt +++ b/readme.txt @@ -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: