From c2b25b09be4277aa81ca5c9eebdca51067539716 Mon Sep 17 00:00:00 2001
From: mcmlxxix <>
Date: Tue, 4 Sep 2012 20:06:46 +0000
Subject: [PATCH] use InputLine.attr getter/setter instead of colors.bg/fg.
 persist control-a through multiple Frame.putmsg() calls. add auto_clear
 setting to Inputline

---
 exec/load/frame.js     |  8 ++++----
 exec/load/inputline.js | 34 ++++++++++++++++++++++------------
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/exec/load/frame.js b/exec/load/frame.js
index 3dd0f5ade4..5c2dafb3ce 100644
--- a/exec/load/frame.js
+++ b/exec/load/frame.js
@@ -118,6 +118,7 @@ function Frame(x,y,width,height,attr,parent) {
 		display:undefined,
 		data:[],
 		open:false,
+		ctrl_a:false,
 		id:0
 	}
 	var settings = {
@@ -707,7 +708,6 @@ function Frame(x,y,width,height,attr,parent) {
 		if(str == undefined)
 			return;
 		str = str.toString().split('');
-		var control_a = false;
 		var curattr = attr;
 		if(!curattr)
 			curattr = this.attr;
@@ -715,7 +715,7 @@ function Frame(x,y,width,height,attr,parent) {
 
 		while(str.length > 0) {
 			var ch = str.shift();
-			if(control_a) {
+			if(properties.ctrl_a) {
 				var k = ch;
 				if(k)
 					k = k.toUpperCase();
@@ -804,12 +804,12 @@ function Frame(x,y,width,height,attr,parent) {
 						pos.x+=ch.charCodeAt(0)-127;
 					break;
 				}
-				control_a = false;
+				properties.ctrl_a = false;
 			}
 			else {
 				switch(ch) {
 				case '\1':		/* CTRL-A code */
-					control_a = true;
+					properties.ctrl_a = true;
 					break;
 				case '\7':		/* Beep */
 					break;
diff --git a/exec/load/inputline.js b/exec/load/inputline.js
index 6fd3f33e9a..e062a3928f 100644
--- a/exec/load/inputline.js
+++ b/exec/load/inputline.js
@@ -8,13 +8,15 @@ function InputLine(frame,text) {
 	var properties = {
 		frame:undefined,
 		text:undefined,
+		attr:undefined,
 		buffer:[]
 	};
 	var settings = {
 		show_border:true,
 		show_title:true,
+		auto_clear:true,
 		timeout:10,
-		max_buffer:200
+		max_buffer:200,
 	};
 	
 	/* protected properties */
@@ -22,12 +24,26 @@ function InputLine(frame,text) {
 		return properties.frame;
 	});
 	this.__defineGetter__("max_buffer",function() {
-		return properties.max_buffer;
+		return settings.max_buffer;
 	});
 	this.__defineSetter__("max_buffer",function(num) {
 		if(num > 0 && num < 10000)
 			settings.max_buffer = Number(num);
 	});
+	this.__defineGetter__("auto_clear",function() {
+		return settings.auto_clear;
+	});
+	this.__defineSetter__("auto_clear",function(bool) {
+		if(typeof bool == "boolean")
+			settings.auto_clear = bool;
+	});
+	this.__defineGetter__("attr",function() {
+		return properties.frame.attr;
+	});
+	this.__defineSetter__("attr",function(num) {
+		if(num >= 0 && num < 512)
+			properties.frame.attr = Number(num);
+	});
 	this.__defineGetter__("timeout",function() {
 		return properties.timeout;
 	});
@@ -40,12 +56,6 @@ function InputLine(frame,text) {
 		return properties.buffer;
 	});
 	
-	/* public properties */
-	this.colors = {
-		bg:BG_BLUE,
-		fg:WHITE
-	};
-	
 	/* public methods */
 	this.clear = function() {
 		reset();
@@ -97,8 +107,7 @@ function InputLine(frame,text) {
 			return bufferKey(key);
 		}
 	}
-	this.init = function(x,y,w,h,frame) {
-		var attr = this.colors.bg + this.colors.fg;
+	this.init = function(x,y,w,h,frame,attr) {
 		properties.frame = new Frame(x,y,w,h,attr,frame);
 		properties.frame.v_scroll = false;
 		properties.frame.h_scroll = true;
@@ -120,7 +129,7 @@ function InputLine(frame,text) {
 		if(properties.buffer.length>properties.frame.width) 
 			printBuffer();
 		 else 
-			properties.frame.putmsg(key);
+			properties.frame.putmsg(key,properties.frame.attr);
 		return undefined;
 	}
 	function backspace() {
@@ -162,7 +171,8 @@ function InputLine(frame,text) {
 			}
 		}
 		var cmd=properties.buffer;
-		reset();
+		if(settings.auto_clear)
+			reset();
 		return cmd;
 	}
 	function init(frame,text) {
-- 
GitLab