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

initial rewrite for frame support

parent 71037fea
No related branches found
No related tags found
No related merge requests found
bbs.command_str='';
load("str_cmds.js"); load("str_cmds.js");
full_redraw=false; load("funclib.js");
load("frame.js");
function InputLine(x,y,w,max,bg,fg,title) function InputLine(frame,text) {
{ /* private properties */
this.x=1; var properties = {
this.y=24; frame:undefined,
this.width=79; text:undefined,
this.max_buffer=200; buffer:[]
};
var settings = {
show_border:true,
show_title:true,
timeout:50,
max_buffer:200
};
this.bg=BG_BLACK; /* protected properties */
this.fg=LIGHTGRAY; this.__defineGetter__("frame",function() {
this.buffer=""; return properties.frame;
});
this.title_bg=BG_LIGHTGRAY; /* public properties */
this.title_fg=BLACK; this.colors = {
this.title=""; bg:BG_BLUE,
fg:WHITE
};
this.clear=function() /* public methods */
{ this.getkey = function(use_hotkeys) {
console.gotoxy(this.x + console.strlen(this.title),this.y); var key=console.inkey(K_NOCRLF|K_NOSPIN|K_NOECHO,settings.timeout);
console.attributes=this.bg; if(key == "")
console.write(format("%*s",this.width-console.strlen(this.title),"")); return undefined;
} if(use_hotkeys)
this.init=function(x,y,w,max,bg,fg,title)
{
if(x) this.x=x;
if(y) this.y=y;
if(w) this.width=w;
if(max) this.max_buffer=max;
if(bg) this.bg=bg;
if(fg) this.fg=fg;
if(title) this.title=title;
if(this.x + this.w > console.screen_columns) {
log("input line wider than screen. adjusting to fit.");
this.w=console.screen_columns-this.x-1;
}
if(this.x >= console.screen_columns || this.y > console.screen_rows) {
log("input line off the screen. using defaults.");
this.x=1;
this.y=1;
}
}
this.submit=function()
{
if(strlen(this.buffer)<1) return null;
if(this.buffer[0]==";") {
if(this.buffer.length>1 && (user.compare_ars("SYSOP") || bbs.sys_status&SS_TMPSYSOP)) {
console.clear();
str_cmds(this.buffer.substr(1));
this.reset();
this.clear();
full_redraw=true;
return null;
}
}
var command=this.buffer;
this.reset();
this.clear();
return command;
}
this.inkey=function(hotkeys)
{
var key=console.inkey(K_NOCRLF|K_NOSPIN|K_NOECHO);
if(!key)
return false;
if(hotkeys)
return key; return key;
switch(key) { switch(key) {
case '\x00': /* CTRL-@ (NULL) */ case '\x00': /* CTRL-@ (NULL) */
...@@ -91,7 +57,6 @@ function InputLine(x,y,w,max,bg,fg,title) ...@@ -91,7 +57,6 @@ function InputLine(x,y,w,max,bg,fg,title)
case '\x1a': /* CTRL-Z */ case '\x1a': /* CTRL-Z */
case '\x1c': /* CTRL-\ */ case '\x1c': /* CTRL-\ */
case '\x1f': /* CTRL-_ */ case '\x1f': /* CTRL-_ */
case '\x1b': /* ESC */
case KEY_UP: case KEY_UP:
case KEY_DOWN: case KEY_DOWN:
case KEY_LEFT: case KEY_LEFT:
...@@ -101,91 +66,84 @@ function InputLine(x,y,w,max,bg,fg,title) ...@@ -101,91 +66,84 @@ function InputLine(x,y,w,max,bg,fg,title)
return key; return key;
case '\x7f': /* DELETE */ case '\x7f': /* DELETE */
case '\b': case '\b':
this.backspace(); return backspace();
return false;
case '\r': case '\r':
case '\n': case '\n':
return this.submit(); return submit();
default: case '\x1b':
this.bufferKey(key);
return false;
}
}
this.backspace=function()
{
if(this.buffer.length>0) {
if(this.buffer.length<=this.getWidth()) {
this.getxy();
console.left();
console.attributes=this.bg;
console.write(" ");
this.buffer=this.buffer.substr(0,this.buffer.length-1);
} else {
this.buffer=this.buffer.substr(0,this.buffer.length-1);
console.gotoxy(this);
console.right(console.strlen(this.title));
this.printBuffer();
}
return true;
} else {
return false; return false;
default:
return bufferKey(key);
} }
} }
this.reset=function() this.init = function(x,y,w,h,frame) {
{ var attr = this.colors.bg + this.colors.fg;
this.buffer=""; properties.frame = new Frame(x,y,w,h,attr,frame);
properties.frame.v_scroll = false;
properties.frame.h_scroll = true;
properties.frame.open();
} }
this.getxy=function()
{ /* private functions */
console.gotoxy(this.x + console.strlen(this.title) + this.buffer.length,this.y); function bufferKey(key) {
if(properties.buffer.length >= settings.max_buffer)
return false;
properties.buffer+=key;
if(properties.buffer.length>properties.frame.width)
printBuffer();
else
properties.frame.putmsg(key);
return undefined;
} }
this.bufferKey=function(key) function backspace() {
{ if(properties.buffer.length == 0)
if(this.buffer.length >= this.max_buffer) {
return false; return false;
} else if(this.buffer.length>=this.getWidth()) { properties.buffer=properties.buffer.substr(0,properties.buffer.length-1);
this.buffer+=key; if(properties.buffer.length+1>=properties.frame.width)
console.gotoxy(this); printBuffer();
console.right(console.strlen(this.title)); else {
this.printBuffer(); properties.frame.left();
} else { properties.frame.putmsg(" ");
this.getxy(); properties.frame.left();
this.buffer+=key;
console.attributes=this.fg + this.bg;
console.write(key);
} }
return true; return undefined;
} }
this.getWidth=function() function printBuffer() {
{ properties.frame.clear();
return this.width-console.strlen(this.title); var overrun=properties.buffer.length-properties.frame.width;
if(overrun > 0) {
var truncated=properties.buffer.substr(overrun);
properties.frame.putmsg(truncated);
}
else {
properties.frame.putmsg(properties.buffer);
}
} }
this.draw=function() function reset() {
{ properties.buffer = [];
console.gotoxy(this); properties.frame.clear();
this.printTitle();
// if(this.x + this.width == console.screen_columns && this.y == console.screen_rows)
// console.cleartoeol(this.bg);
this.printBuffer();
} }
this.printTitle=function() function submit() {
{ // if(strlen(properties.buffer)<1)
if(this.title.length > 0) { // return null;
console.attributes=this.title_fg + this.title_bg; if(properties.buffer[0]==";") {
console.write(this.title); if(properties.buffer.length>1 && (user.compare_ars("SYSOP") || bbs.sys_status&SS_TMPSYSOP)) {
str_cmds(properties.buffer.substr(1));
reset();
return null;
}
} }
var cmd=properties.buffer;
reset();
return cmd;
} }
this.printBuffer=function() function init(frame,text) {
{ if(frame instanceof Frame) {
console.attributes=this.fg+this.bg; properties.frame=frame;
if(this.buffer.length>this.getWidth()) { }
var overrun=this.buffer.length-this.getWidth(); if(text) {
var truncated=this.buffer.substr(overrun); properties.text = text;
console.write(truncated);
} else {
console.write(printPadded(this.buffer,this.getWidth()));
} }
} }
init.apply(this,arguments);
this.init(x,y,w,max,bg,fg,title);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment