Skip to content
Snippets Groups Projects
Commit c2b25b09 authored by mcmlxxix's avatar mcmlxxix
Browse files

use InputLine.attr getter/setter instead of colors.bg/fg. persist control-a...

use InputLine.attr getter/setter instead of colors.bg/fg. persist control-a through multiple Frame.putmsg() calls. add auto_clear setting to Inputline
parent 828671cd
No related branches found
No related tags found
No related merge requests found
...@@ -118,6 +118,7 @@ function Frame(x,y,width,height,attr,parent) { ...@@ -118,6 +118,7 @@ function Frame(x,y,width,height,attr,parent) {
display:undefined, display:undefined,
data:[], data:[],
open:false, open:false,
ctrl_a:false,
id:0 id:0
} }
var settings = { var settings = {
...@@ -707,7 +708,6 @@ function Frame(x,y,width,height,attr,parent) { ...@@ -707,7 +708,6 @@ function Frame(x,y,width,height,attr,parent) {
if(str == undefined) if(str == undefined)
return; return;
str = str.toString().split(''); str = str.toString().split('');
var control_a = false;
var curattr = attr; var curattr = attr;
if(!curattr) if(!curattr)
curattr = this.attr; curattr = this.attr;
...@@ -715,7 +715,7 @@ function Frame(x,y,width,height,attr,parent) { ...@@ -715,7 +715,7 @@ function Frame(x,y,width,height,attr,parent) {
while(str.length > 0) { while(str.length > 0) {
var ch = str.shift(); var ch = str.shift();
if(control_a) { if(properties.ctrl_a) {
var k = ch; var k = ch;
if(k) if(k)
k = k.toUpperCase(); k = k.toUpperCase();
...@@ -804,12 +804,12 @@ function Frame(x,y,width,height,attr,parent) { ...@@ -804,12 +804,12 @@ function Frame(x,y,width,height,attr,parent) {
pos.x+=ch.charCodeAt(0)-127; pos.x+=ch.charCodeAt(0)-127;
break; break;
} }
control_a = false; properties.ctrl_a = false;
} }
else { else {
switch(ch) { switch(ch) {
case '\1': /* CTRL-A code */ case '\1': /* CTRL-A code */
control_a = true; properties.ctrl_a = true;
break; break;
case '\7': /* Beep */ case '\7': /* Beep */
break; break;
......
...@@ -8,13 +8,15 @@ function InputLine(frame,text) { ...@@ -8,13 +8,15 @@ function InputLine(frame,text) {
var properties = { var properties = {
frame:undefined, frame:undefined,
text:undefined, text:undefined,
attr:undefined,
buffer:[] buffer:[]
}; };
var settings = { var settings = {
show_border:true, show_border:true,
show_title:true, show_title:true,
auto_clear:true,
timeout:10, timeout:10,
max_buffer:200 max_buffer:200,
}; };
/* protected properties */ /* protected properties */
...@@ -22,12 +24,26 @@ function InputLine(frame,text) { ...@@ -22,12 +24,26 @@ function InputLine(frame,text) {
return properties.frame; return properties.frame;
}); });
this.__defineGetter__("max_buffer",function() { this.__defineGetter__("max_buffer",function() {
return properties.max_buffer; return settings.max_buffer;
}); });
this.__defineSetter__("max_buffer",function(num) { this.__defineSetter__("max_buffer",function(num) {
if(num > 0 && num < 10000) if(num > 0 && num < 10000)
settings.max_buffer = Number(num); 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() { this.__defineGetter__("timeout",function() {
return properties.timeout; return properties.timeout;
}); });
...@@ -40,12 +56,6 @@ function InputLine(frame,text) { ...@@ -40,12 +56,6 @@ function InputLine(frame,text) {
return properties.buffer; return properties.buffer;
}); });
/* public properties */
this.colors = {
bg:BG_BLUE,
fg:WHITE
};
/* public methods */ /* public methods */
this.clear = function() { this.clear = function() {
reset(); reset();
...@@ -97,8 +107,7 @@ function InputLine(frame,text) { ...@@ -97,8 +107,7 @@ function InputLine(frame,text) {
return bufferKey(key); return bufferKey(key);
} }
} }
this.init = function(x,y,w,h,frame) { this.init = function(x,y,w,h,frame,attr) {
var attr = this.colors.bg + this.colors.fg;
properties.frame = new Frame(x,y,w,h,attr,frame); properties.frame = new Frame(x,y,w,h,attr,frame);
properties.frame.v_scroll = false; properties.frame.v_scroll = false;
properties.frame.h_scroll = true; properties.frame.h_scroll = true;
...@@ -120,7 +129,7 @@ function InputLine(frame,text) { ...@@ -120,7 +129,7 @@ function InputLine(frame,text) {
if(properties.buffer.length>properties.frame.width) if(properties.buffer.length>properties.frame.width)
printBuffer(); printBuffer();
else else
properties.frame.putmsg(key); properties.frame.putmsg(key,properties.frame.attr);
return undefined; return undefined;
} }
function backspace() { function backspace() {
...@@ -162,6 +171,7 @@ function InputLine(frame,text) { ...@@ -162,6 +171,7 @@ function InputLine(frame,text) {
} }
} }
var cmd=properties.buffer; var cmd=properties.buffer;
if(settings.auto_clear)
reset(); reset();
return cmd; return cmd;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment