From 4d0e5333b1b83cbfe223da7d3c4782019bd19d0c Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Fri, 19 Mar 2010 08:00:49 +0000
Subject: [PATCH] Add support for control code handling... current just TAB,
 CR, LF, BS, and FF are supported.

---
 src/ZuulTerm/chrome/content/Term.js | 38 ++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/ZuulTerm/chrome/content/Term.js b/src/ZuulTerm/chrome/content/Term.js
index 2b2e62bde1..77253a900e 100644
--- a/src/ZuulTerm/chrome/content/Term.js
+++ b/src/ZuulTerm/chrome/content/Term.js
@@ -1,6 +1,6 @@
 var connection=null;
 
-function UpdateTerm(data)
+function writeText(data)
 {
 	var term=document.getElementById("frame").contentDocument.getElementById("terminal");
 	var win=document.getElementById("frame").contentWindow;
@@ -9,6 +9,42 @@ function UpdateTerm(data)
 	win.scroll(0, term.clientHeight);
 }
 
+function handleCtrl(byte)
+{
+	var term=document.getElementById("frame").contentDocument.getElementById("terminal");
+	var win=document.getElementById("frame").contentWindow;
+
+	switch(byte) {
+		case '\n':
+		case '\t':
+		case '\r':
+			writeText(byte);
+			break;
+		case '\b':
+			term.innerHTML = term.innerHTML.replace(/[^\x00-\x1F]$/,'');
+			break;
+		case '\x0c':	// Formfeed -- clear screen
+			term.innerHTML = '';
+			break;
+	}
+}
+
+function UpdateTerm(data)
+{
+	while(data.length) {
+		data=data.replace(/^([^\x00-\x1F]*)/, function(matched, text) {
+			writeText(text);
+			return '';
+		});
+		if(data.length) {
+			while(data.charCodeAt(0) < 32) {
+				handleCtrl(data.substr(0,1));
+				data=data.substr(1);
+			}
+		}
+	}
+}
+
 function doTerm(host, port)
 {
 	var ConnOpt=document.getElementById("MainConnectionMenu-connect").disabled=true;
-- 
GitLab