cleanup unnecesary code after terminal element addition.

This commit is contained in:
Christopher Jeffrey 2015-01-24 21:33:30 -08:00
parent 879a072353
commit 5bdfc18daf
2 changed files with 80 additions and 198 deletions

View File

@ -170,6 +170,10 @@ function reset() {
ball.angle = 'down';
ball.rtop = 1;
ball.rleft = 1;
if ((score.lwins + score.rwins) % 2 !== 0) {
ball.direction = 'left';
ball.rleft = table.width - 1;
}
lpaddle.rtop = 0;
rpaddle.rtop = 0;
@ -207,7 +211,7 @@ function startGame() {
if (lpaddle.rbottom > 0) lpaddle.rtop += lpaddle.speed;
if (!socket) if (rpaddle.rbottom > 0) rpaddle.rtop += rpaddle.speed;
if (lpaddle.rbottom < 0) lpaddle.rtop = table.height - lpaddle.height - 1;
if (rpaddle.rbottom < 0) rpaddle.rbottom = table.height - rpaddle.height - 1;
if (rpaddle.rbottom < 0) rpaddle.rtop = table.height - rpaddle.height - 1;
screen.render();
}
});

View File

@ -1497,7 +1497,7 @@ Screen.prototype.spawn = function(file, args, options) {
options.stdio = 'inherit';
program.lsaveCursor('spawn');
//program.csr(0, program.rows - 1);
// program.csr(0, program.rows - 1);
program.normalBuffer();
program.showCursor();
if (mouse) program.disableMouse();
@ -1516,7 +1516,7 @@ Screen.prototype.spawn = function(file, args, options) {
program.output.write = write;
program.alternateBuffer();
//program.csr(0, program.rows - 1);
// program.csr(0, program.rows - 1);
if (mouse) program.enableMouse();
screen.alloc();
@ -1702,13 +1702,6 @@ function Element(options) {
height: options.height
};
// if (options.position.left == null && options.position.right == null) {
// options.position.left = 0;
// }
// if (options.position.top == null && options.position.bottom == null) {
// options.position.top = 0;
// }
if (options.position.width === 'shrink'
|| options.position.height === 'shrink') {
if (options.position.width === 'shrink') {
@ -1800,7 +1793,7 @@ function Element(options) {
// TODO: Possibly move this to Node for screen.on('mouse', ...).
this.on('newListener', function fn(type) {
//type = type.split(' ').slice(1).join(' ');
// type = type.split(' ').slice(1).join(' ');
if (type === 'mouse'
|| type === 'click'
|| type === 'mouseover'
@ -1836,18 +1829,16 @@ function Element(options) {
if (this.style.hover) {
options.hoverEffects = this.style.hover;
//delete this.style.hover;
}
if (this.style.focus) {
options.focusEffects = this.style.focus;
//delete this.style.focus;
}
// if (options.effects) {
// if (options.effects.hover) options.hoverEffects = options.effects.hover;
// if (options.effects.focus) options.focusEffects = options.effects.focus;
// }
if (options.effects) {
if (options.effects.hover) options.hoverEffects = options.effects.hover;
if (options.effects.focus) options.focusEffects = options.effects.focus;
}
[['hoverEffects', 'mouseover', 'mouseout', '_htemp'],
['focusEffects', 'focus', 'blur', '_ftemp']].forEach(function(props) {
@ -2556,9 +2547,9 @@ Element.prototype._getWidth = function(get) {
&& this.position.left !== 'center') {
width -= this.parent.ileft;
}
//if (this.position.right != null) {
width -= this.parent.iright;
//}
// if (this.position.right != null) {
width -= this.parent.iright;
// }
}
}
@ -2600,9 +2591,9 @@ Element.prototype._getHeight = function(get) {
&& this.position.top !== 'center') {
height -= this.parent.itop;
}
//if (this.position.bottom != null) {
height -= this.parent.ibottom;
//}
// if (this.position.bottom != null) {
height -= this.parent.ibottom;
// }
}
}
@ -2652,9 +2643,9 @@ Element.prototype._getRight = function(get) {
if (this.position.right == null && this.position.left != null) {
right = this.screen.cols - (this._getLeft(get) + this._getWidth(get));
if (this.screen.autoPadding) {
//if (this.position.right != null) {
right += this.parent.iright;
//}
// if (this.position.right != null) {
right += this.parent.iright;
// }
}
return right;
}
@ -2662,9 +2653,9 @@ Element.prototype._getRight = function(get) {
right = (parent.right || 0) + (this.position.right || 0);
if (this.screen.autoPadding) {
//if (this.position.right != null) {
right += this.parent.iright;
//}
// if (this.position.right != null) {
right += this.parent.iright;
// }
}
return right;
@ -2713,9 +2704,9 @@ Element.prototype._getBottom = function(get) {
if (this.position.bottom == null && this.position.top != null) {
bottom = this.screen.rows - (this._getTop(get) + this._getHeight(get));
if (this.screen.autoPadding) {
//if (this.position.bottom != null) {
bottom += this.parent.ibottom;
//}
// if (this.position.bottom != null) {
bottom += this.parent.ibottom;
// }
}
return bottom;
}
@ -2723,9 +2714,9 @@ Element.prototype._getBottom = function(get) {
bottom = (parent.bottom || 0) + (this.position.bottom || 0);
if (this.screen.autoPadding) {
//if (this.position.bottom != null) {
bottom += this.parent.ibottom;
//}
// if (this.position.bottom != null) {
bottom += this.parent.ibottom;
// }
}
return bottom;
@ -3068,7 +3059,9 @@ Element.prototype._getShrink = function(xi, xl, yi, yl, get) {
Element.prototype._getCoords = function(get, noscroll) {
if (this.hidden) return;
// if (this.parent._rendering) get = true;
// if (this.parent._rendering) {
// get = true;
// }
var xi = this._getLeft(get)
, xl = xi + this._getWidth(get)
@ -3209,10 +3202,10 @@ Element.prototype._getCoords = function(get, noscroll) {
}
}
//if (this.parent.lpos) {
// this.parent.lpos._scrollBottom = Math.max(
// this.parent.lpos._scrollBottom, yl);
//}
// if (this.parent.lpos) {
// this.parent.lpos._scrollBottom = Math.max(
// this.parent.lpos._scrollBottom, yl);
// }
return {
xi: xi,
@ -3493,9 +3486,13 @@ Element.prototype.render = function() {
if (el.screen._ci !== -1) {
el.index = el.screen._ci++;
}
//if (el.screen._rendering) el._rendering = true;
// if (el.screen._rendering) {
// el._rendering = true;
// }
el.render();
//if (el.screen._rendering) el._rendering = false;
// if (el.screen._rendering) {
// el._rendering = false;
// }
});
this._emit('render', [coords]);
@ -3753,22 +3750,9 @@ function Line(options) {
this.border = {
type: 'bg',
__proto__: this
// get ch() { return self.ch; },
// set ch(c) { return self.ch = c; }
};
this.style.border = this.style;
// Maybe instead of the above:
// this.on('prerender', function() {
// self._style = self.style;
// self.border = { type: 'bg', ch: self.ch };
// self.style = { border: self.style };
// });
//
// this.on('render', function(coords) {
// self.style = self._style;
// });
}
Line.prototype.__proto__ = Box.prototype;
@ -3876,12 +3860,12 @@ function ScrollableBox(options) {
return;
}
if (options.vi && key.name === 'g' && !key.shift) {
self.scroll(-self._clines.length);
self.scrollTo(0);
self.screen.render();
return;
}
if (options.vi && key.name === 'g' && key.shift) {
self.scroll(self._clines.length);
self.scrollTo(self._scrollBottom());
self.screen.render();
return;
}
@ -4187,15 +4171,11 @@ function List(options) {
if (options.mouse) {
this.screen._listenMouse(this);
//this.screen.on('element wheeldown', function(el, data) {
this.on('element wheeldown', function(el, data) {
// if (el !== self && !el.hasAncestor(self)) return;
self.select(self.selected + 2);
self.screen.render();
});
//this.screen.on('element wheelup', function(el, data) {
this.on('element wheelup', function(el, data) {
// if (el !== self && !el.hasAncestor(self)) return;
self.select(self.selected - 2);
self.screen.render();
});
@ -4291,8 +4271,8 @@ function List(options) {
this.on('resize', function() {
var visible = self.height - self.iheight;
// if (self.selected < visible - 1) {
if (visible >= self.selected + 1) {
//if (self.selected < visible - 1) {
self.childBase = 0;
self.childOffset = self.selected;
} else {
@ -4468,8 +4448,11 @@ List.prototype.select = function(index) {
index = this.items.indexOf(index);
}
if (index < 0) index = 0;
else if (index >= this.items.length) index = this.items.length - 1;
if (index < 0) {
index = 0;
} else if (index >= this.items.length) {
index = this.items.length - 1;
}
if (this.selected === index && this._listInitialized) return;
this._listInitialized = true;
@ -4502,9 +4485,10 @@ List.prototype.pick = function(label, callback) {
if (focused && focused._done) focused._done('stop');
this.screen.saveFocus();
//var parent = this.parent;
//this.detach();
//parent.append(this);
// XXX Keep above:
// var parent = this.parent;
// this.detach();
// parent.append(this);
this.focus();
this.show();
@ -4529,7 +4513,6 @@ List.prototype.enterSelected = function(i) {
List.prototype.cancelSelected = function(i) {
if (i != null) this.select(i);
//this.emit('action', this.items[this.selected], this.selected);
this.emit('action');
this.emit('cancel');
};
@ -4550,25 +4533,9 @@ function Form(options) {
options.ignoreKeys = true;
Box.call(this, options);
//this.on('element focus', function(el, ch, key) {
// self._refresh();
// if (~self._children.indexOf(el)) {
// self._selected = el;
// }
//});
if (options.keys) {
this.screen._listenKeys(this);
//this.screen.on('element keypress', function(el, ch, key) {
this.on('element keypress', function(el, ch, key) {
// Make sure we're not entering input into a textbox.
// if (self.screen.grabKeys || self.screen.lockKeys) {
// return;
// }
// Make sure we're a form or input element.
// if (el !== self && !el.hasAncestor(self)) return;
if ((key.name === 'tab' && !key.shift)
|| (el.type === 'textbox' && options.autoNext && key.name === 'enter')
|| key.name === 'down'
@ -4639,7 +4606,6 @@ Form.prototype.next = function() {
if (!this._selected) {
this._selected = this._children[0];
if (!this._selected.visible) return this.next();
// return this._selected;
if (this.screen.focused !== this._selected) return this._selected;
}
@ -4663,7 +4629,6 @@ Form.prototype.previous = function() {
if (!this._selected) {
this._selected = this._children[this._children.length - 1];
if (!this._selected.visible) return this.previous();
// return this._selected;
if (this.screen.focused !== this._selected) return this._selected;
}
@ -4836,7 +4801,6 @@ function Textarea(options) {
this.value = options.value || '';
//this.on('prerender', this._render.bind(this));
this.__updateCursor = this._updateCursor.bind(this);
this.on('resize', this.__updateCursor);
this.on('move', this.__updateCursor);
@ -5037,7 +5001,6 @@ Textarea.prototype._listener = function(ch, key) {
}
if (this.value !== value) {
//this.setValue();
this.screen.render();
}
};
@ -5046,7 +5009,6 @@ Textarea.prototype._typeScroll = function() {
// XXX Workaround
var height = this.height - this.iheight;
if (this._clines.length - this.childBase > height) {
//this.setContent(this.value + '\n');
this.scroll(this._clines.length);
}
};
@ -5299,8 +5261,6 @@ function ProgressBar(options) {
self.setProgress(p);
});
}
//this.on('render', this._render.bind(this));
}
ProgressBar.prototype.__proto__ = Input.prototype;
@ -5583,15 +5543,12 @@ function Checkbox(options) {
this.on('focus', function(old) {
var lpos = self.lpos;
if (!lpos) return;
//self.screen.program.saveCursor();
self.screen.program.lsaveCursor('checkbox');
self.screen.program.cup(lpos.yi, lpos.xi + 1);
self.screen.program.showCursor();
});
this.on('blur', function() {
//self.screen.program.hideCursor();
//self.screen.program.restoreCursor();
self.screen.program.lrestoreCursor('checkbox', true);
});
}
@ -5756,9 +5713,10 @@ Prompt.prototype.readInput = function(text, value, callback) {
value = '';
}
//var parent = this.parent;
//this.detach();
//parent.append(this);
// Keep above:
// var parent = this.parent;
// this.detach();
// parent.append(this);
this.show();
this.setContent(' ' + text);
@ -5842,9 +5800,10 @@ Question.prototype.ask = function(text, callback) {
var self = this;
var press, okay, cancel;
//var parent = this.parent;
//this.detach();
//parent.append(this);
// Keep above:
// var parent = this.parent;
// this.detach();
// parent.append(this);
this.show();
this.setContent(' ' + text);
@ -5908,16 +5867,18 @@ Message.prototype.type = 'message';
Message.prototype.log =
Message.prototype.display = function(text, time, callback) {
var self = this;
if (typeof time === 'function') {
callback = time;
time = null;
}
if (time == null) time = 3;
//time = time || 3;
//var parent = this.parent;
//this.detach();
//parent.append(this);
if (time == null) time = 3;
// Keep above:
// var parent = this.parent;
// this.detach();
// parent.append(this);
if (this.scrollable) {
this.screen.saveFocus();
@ -6021,9 +5982,10 @@ Loading.prototype.type = 'loading';
Loading.prototype.load = function(text) {
var self = this;
//var parent = this.parent;
//this.detach();
//parent.append(this);
// XXX Keep above:
// var parent = this.parent;
// this.detach();
// parent.append(this);
this.show();
this.setContent(text);
@ -6071,10 +6033,6 @@ function Listbar(options) {
options = options || {};
// XXX Workaround to make sure buttons don't
// overlap border on the right.
// options.scrollable = true;
this.items = [];
this.ritems = [];
this.commands = [];
@ -6086,15 +6044,6 @@ function Listbar(options) {
Box.call(this, options);
//this._.debug = new Box({
// parent: this.screen,
// top: 0,
// left: 0,
// height: 'shrink',
// width: 'shrink',
// content: '...'
//});
if (options.commands || options.items) {
this.setItems(options.commands || options.items);
}
@ -6290,17 +6239,10 @@ Listbar.prototype.appendItem = function(item, callback) {
this.append(el);
if (cmd.callback) {
//el.on('press', cmd.callback);
//this.on('select', function(el) {
// if (el._.cmd.callback) {
// el._.cmd.callback();
// }
//});
if (cmd.keys) {
this.screen.key(cmd.keys, function(ch, key) {
self.emit('action', el, self.selected);
self.emit('select', el, self.selected);
//el.press();
if (el._.cmd.callback) {
el._.cmd.callback();
}
@ -6318,7 +6260,6 @@ Listbar.prototype.appendItem = function(item, callback) {
el.on('click', function(data) {
self.emit('action', el, self.selected);
self.emit('select', el, self.selected);
//el.press();
if (el._.cmd.callback) {
el._.cmd.callback();
}
@ -6363,33 +6304,31 @@ Listbar.prototype.select = function(offset) {
, visible = 0
, el;
if (offset < 0) offset = 0;
else if (offset >= this.items.length) offset = this.items.length - 1;
if (offset < 0) {
offset = 0;
} else if (offset >= this.items.length) {
offset = this.items.length - 1;
}
el = this.items[offset];
if (!el) return;
this.items.forEach(function(el, i) {
if (i < self.leftBase) return;
var lpos = el._getCoords();
if (!lpos) return;
// XXX Need this because overflowed elements will still return lpos.
if (lpos.xl - lpos.xi <= 0) return;
drawn += (lpos.xl - lpos.xi) + 2;
// XXX Need this because overflowed elements will still return lpos.
//drawn += el.getText().length + 2 + 2;
if (drawn <= width) visible++;
});
var diff = offset - (this.leftBase + this.leftOffset);
if (offset > this.leftBase + this.leftOffset) {
if (offset > this.leftBase + visible - 1) {
//this.leftOffset = visible;
//this.leftBase = offset - visible;
this.leftOffset = 0;
this.leftBase = offset;
} else {
@ -6404,18 +6343,6 @@ Listbar.prototype.select = function(offset) {
this.leftOffset -= diff;
}
}
//this.leftOffset = Math.max(0, this.leftOffset);
//this.leftBase = Math.max(0, this.leftBase);
//this._.debug.setContent(JSON.stringify({
// leftOffset: this.leftOffset,
// leftBase: this.leftBase,
// drawn: drawn,
// visible: visible,
// width: width,
// diff: diff
//}, null, 2));
};
Listbar.prototype.removeItem = function(child) {
@ -6449,7 +6376,6 @@ Listbar.prototype.moveRight = function(offset) {
Listbar.prototype.selectTab = function(index) {
var item = this.items[index];
if (item) {
//item.press();
if (item._.cmd.callback) {
item._.cmd.callback();
}
@ -6458,52 +6384,6 @@ Listbar.prototype.selectTab = function(index) {
}
};
/**
* DirManager - Merge into FileManager?
*/
function DirManager(options) {
var self = this;
if (!(this instanceof Node)) {
return new DirManager(options);
}
options = options || {};
FileManager.call(this, options);
this.on('cd', function(dir) {
if (dir === self.cwd) return;
self.emit('file', dir);
});
}
DirManager.prototype.__proto__ = FileManager.prototype;
DirManager.prototype.type = 'dir-manager';
/**
* Passbox - Useless
*/
function Passbox(options) {
var self = this;
if (!(this instanceof Node)) {
return new Passbox(options);
}
options = options || {};
options.censor = true;
Textbox.call(this, options);
}
Passbox.prototype.__proto__ = Textbox.prototype;
Passbox.prototype.type = 'passbox';
/**
* Terminal
*/
@ -6748,8 +6628,6 @@ exports.Question = exports.question = Question;
exports.Message = exports.message = Message;
exports.Loading = exports.loading = Loading;
exports.Listbar = exports.listbar = Listbar;
exports.DirManager = exports.dirmanager = DirManager;
exports.Passbox = exports.passbox = Passbox;
exports.Terminal = exports.terminal = Terminal;