* Rename position x/y stuff to row/col. X/Y were backwards anyway :)
This commit is contained in:
parent
159cdcb763
commit
eaa4feeebd
|
@ -46,7 +46,7 @@ EditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
||||||
// no shortcuts - redraw the view
|
// no shortcuts - redraw the view
|
||||||
this.redraw();
|
this.redraw();
|
||||||
} else {
|
} else {
|
||||||
this.cursorPos.x += 1;
|
this.cursorPos.row += 1;
|
||||||
|
|
||||||
if(this.textMaskChar) {
|
if(this.textMaskChar) {
|
||||||
this.client.term.write(this.textMaskChar);
|
this.client.term.write(this.textMaskChar);
|
||||||
|
@ -67,15 +67,15 @@ EditTextView.prototype.onSpecialKeyPress = function(keyName) {
|
||||||
if(this.text.length >= this.dimens.width) {
|
if(this.text.length >= this.dimens.width) {
|
||||||
this.redraw();
|
this.redraw();
|
||||||
} else {
|
} else {
|
||||||
this.cursorPos.x -= 1;
|
this.cursorPos.row -= 1;
|
||||||
if(this.cursorPos.x >= 0) {
|
if(this.cursorPos.row >= 0) {
|
||||||
this.clientBackspace();
|
this.clientBackspace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(this.isSpecialKeyMapped('clearLine', keyName)) {
|
} else if(this.isSpecialKeyMapped('clearLine', keyName)) {
|
||||||
this.text = '';
|
this.text = '';
|
||||||
this.cursorPos.x = 0;
|
this.cursorPos.row = 0;
|
||||||
this.setFocus(true); // resetting focus will redraw & adjust cursor
|
this.setFocus(true); // resetting focus will redraw & adjust cursor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ function MaskEditTextView(options) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getEndOfTextYPosition = function() {
|
this.getEndOfTextColumn = function() {
|
||||||
return this.position.y + this.patternArrayPos;
|
return this.position.col + this.patternArrayPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.buildPattern();
|
this.buildPattern();
|
||||||
|
@ -128,7 +128,7 @@ MaskEditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
this.client.term.write(ansi.goto(this.position.x, this.getEndOfTextYPosition()));
|
this.client.term.write(ansi.goto(this.position.row, this.getEndOfTextColumn()));
|
||||||
}
|
}
|
||||||
|
|
||||||
MaskEditTextView.super_.prototype.onKeyPress.call(this, key, isSpecial);
|
MaskEditTextView.super_.prototype.onKeyPress.call(this, key, isSpecial);
|
||||||
|
@ -148,7 +148,7 @@ MaskEditTextView.prototype.onSpecialKeyPress = function(keyName) {
|
||||||
while(this.patternArrayPos > 0) {
|
while(this.patternArrayPos > 0) {
|
||||||
if(_.isRegExp(this.patternArray[this.patternArrayPos])) {
|
if(_.isRegExp(this.patternArray[this.patternArrayPos])) {
|
||||||
this.text = this.text.substr(0, this.text.length - 1);
|
this.text = this.text.substr(0, this.text.length - 1);
|
||||||
this.client.term.write(ansi.goto(this.position.x, this.getEndOfTextYPosition() + 1));
|
this.client.term.write(ansi.goto(this.position.row, this.getEndOfTextColumn() + 1));
|
||||||
this.clientBackspace();
|
this.clientBackspace();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
id : mci.id,
|
id : mci.id,
|
||||||
ansiSGR : mci.SGR,
|
ansiSGR : mci.SGR,
|
||||||
ansiFocusSGR : mci.focusSGR,
|
ansiFocusSGR : mci.focusSGR,
|
||||||
position : { x : mci.position[0], y : mci.position[1] },
|
position : { row : mci.position[0], col : mci.position[1] },
|
||||||
};
|
};
|
||||||
|
|
||||||
function setOption(pos, name) {
|
function setOption(pos, name) {
|
||||||
|
|
|
@ -56,18 +56,18 @@ function MultiLineEditTextView(options) {
|
||||||
/*
|
/*
|
||||||
this.redrawViewableText = function() {
|
this.redrawViewableText = function() {
|
||||||
//
|
//
|
||||||
// v--- position.x/y
|
// v--- position.row/y
|
||||||
// +-----------------------------------+ <--- x + width
|
// +-----------------------------------+ <--- x + width
|
||||||
// | |
|
// | |
|
||||||
// | |
|
// | |
|
||||||
// | |
|
// | |
|
||||||
// +-----------------------------------+
|
// +-----------------------------------+
|
||||||
// ^--- position.x + height
|
// ^--- position.row + height
|
||||||
//
|
//
|
||||||
// A given line in lines[] may need to take up 1:n physical lines
|
// A given line in lines[] may need to take up 1:n physical lines
|
||||||
// due to wrapping / available space.
|
// due to wrapping / available space.
|
||||||
//
|
//
|
||||||
var x = self.position.x;
|
var x = self.position.row;
|
||||||
var bottom = x + self.dimens.height;
|
var bottom = x + self.dimens.height;
|
||||||
var idx = self.topLineIndex;
|
var idx = self.topLineIndex;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ function MultiLineEditTextView(options) {
|
||||||
} else {
|
} else {
|
||||||
lines = self.wordWrap(self.lines[idx]);
|
lines = self.wordWrap(self.lines[idx]);
|
||||||
for(var y = 0; y < lines.length && x < bottom; ++y) {
|
for(var y = 0; y < lines.length && x < bottom; ++y) {
|
||||||
self.client.term.write(ansi.goto(x, this.position.y));
|
self.client.term.write(ansi.goto(x, this.position.col));
|
||||||
self.client.term.write(lines[y]);
|
self.client.term.write(lines[y]);
|
||||||
++x;
|
++x;
|
||||||
}
|
}
|
||||||
|
@ -91,14 +91,14 @@ function MultiLineEditTextView(options) {
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
this.redrawViewableText = function() {
|
this.redrawViewableText = function() {
|
||||||
var x = self.position.x;
|
var x = self.position.row;
|
||||||
var bottom = x + self.dimens.height;
|
var bottom = x + self.dimens.height;
|
||||||
var index = self.topLineIndex;
|
var index = self.topLineIndex;
|
||||||
|
|
||||||
self.client.term.write(self.getSGR());
|
self.client.term.write(self.getSGR());
|
||||||
|
|
||||||
while(index < self.lines.length && x < bottom) {
|
while(index < self.lines.length && x < bottom) {
|
||||||
self.client.term.write(ansi.goto(x, this.position.y));
|
self.client.term.write(ansi.goto(x, this.position.col));
|
||||||
self.writeLine(self.lines[index]);
|
self.writeLine(self.lines[index]);
|
||||||
console.log(self.lines[index])
|
console.log(self.lines[index])
|
||||||
++x;
|
++x;
|
||||||
|
@ -140,8 +140,8 @@ function MultiLineEditTextView(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.keyUp = function() {
|
this.keyUp = function() {
|
||||||
if(self.cursorPos.x > 0) {
|
if(self.cursorPos.row > 0) {
|
||||||
self.cursorPos.x--;
|
self.cursorPos.row--;
|
||||||
console.log(self.lines[self.getLineIndex()])
|
console.log(self.lines[self.getLineIndex()])
|
||||||
} else if(self.topLineIndex > 0) {
|
} else if(self.topLineIndex > 0) {
|
||||||
// :TODO: scroll
|
// :TODO: scroll
|
||||||
|
@ -154,7 +154,7 @@ function MultiLineEditTextView(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getLineIndex = function() {
|
this.getLineIndex = function() {
|
||||||
return self.topLineIndex + self.cursorPos.x;
|
return self.topLineIndex + self.cursorPos.row;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ MultiLineEditTextView.prototype.setText = function(text) {
|
||||||
// :TODO: text.split(/\r\n|\n|\r/))
|
// :TODO: text.split(/\r\n|\n|\r/))
|
||||||
//this.lines = text.split(/\r?\n/);
|
//this.lines = text.split(/\r?\n/);
|
||||||
|
|
||||||
//this.cursorPos.x = this.position.x + this.dimens.height;
|
//this.cursorPos.row = this.position.row + this.dimens.height;
|
||||||
this.lines = this.wordWrap(text);
|
this.lines = this.wordWrap(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ function SpinnerMenuView(options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client.term.write(ansi.goto(this.position.x, this.position.y));
|
this.client.term.write(ansi.goto(this.position.row, this.position.col));
|
||||||
this.client.term.write(self.hasFocus ? self.getFocusSGR() : self.getSGR());
|
this.client.term.write(self.hasFocus ? self.getFocusSGR() : self.getSGR());
|
||||||
|
|
||||||
var text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
|
var text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
|
||||||
|
|
|
@ -24,7 +24,7 @@ function TextView(options) {
|
||||||
if(options.maxLength) {
|
if(options.maxLength) {
|
||||||
this.maxLength = options.maxLength;
|
this.maxLength = options.maxLength;
|
||||||
} else {
|
} else {
|
||||||
this.maxLength = this.client.term.termWidth - this.position.x;
|
this.maxLength = this.client.term.termWidth - this.position.row;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1);
|
this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1);
|
||||||
|
@ -84,9 +84,9 @@ function TextView(options) {
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getEndOfTextYPosition = function() {
|
this.getEndOfTextColumn = function() {
|
||||||
var offset = Math.min(this.text.length, this.dimens.width);
|
var offset = Math.min(this.text.length, this.dimens.width);
|
||||||
return this.position.y + offset;
|
return this.position.col + offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setText(options.text || '');
|
this.setText(options.text || '');
|
||||||
|
@ -105,7 +105,7 @@ TextView.prototype.setFocus = function(focused) {
|
||||||
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
|
|
||||||
this.client.term.write(ansi.goto(this.position.x, this.getEndOfTextYPosition()));
|
this.client.term.write(ansi.goto(this.position.row, this.getEndOfTextColumn()));
|
||||||
this.client.term.write(this.getFocusSGR());
|
this.client.term.write(this.getFocusSGR());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ function TickerTextView(options) {
|
||||||
this.tickerState = {};
|
this.tickerState = {};
|
||||||
switch(this.tickerStyle) {
|
switch(this.tickerStyle) {
|
||||||
case 'rightToLeft' :
|
case 'rightToLeft' :
|
||||||
this.tickerState.pos = this.position.x + this.dimens.width;
|
this.tickerState.pos = this.position.row + this.dimens.width;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,14 @@ function VerticalMenuView(options) {
|
||||||
this.performAutoScale = function() {
|
this.performAutoScale = function() {
|
||||||
if(this.autoScale.height) {
|
if(this.autoScale.height) {
|
||||||
this.dimens.height = (self.items.length * (self.itemSpacing + 1)) - (self.itemSpacing);
|
this.dimens.height = (self.items.length * (self.itemSpacing + 1)) - (self.itemSpacing);
|
||||||
this.dimens.height = Math.min(this.dimens.height, self.client.term.termHeight - self.position.x);
|
this.dimens.height = Math.min(this.dimens.height, self.client.term.termHeight - self.position.row);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.autoScale.width) {
|
if(this.autoScale.width) {
|
||||||
var l = 0;
|
var l = 0;
|
||||||
self.items.forEach(function item(i) {
|
self.items.forEach(function item(i) {
|
||||||
if(i.text.length > l) {
|
if(i.text.length > l) {
|
||||||
l = Math.min(i.text.length, self.client.term.termWidth - self.position.y);
|
l = Math.min(i.text.length, self.client.term.termWidth - self.position.col);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.dimens.width = l + 1;
|
self.dimens.width = l + 1;
|
||||||
|
@ -45,7 +45,7 @@ function VerticalMenuView(options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.client.term.write(ansi.goto(item.xPosition, self.position.y));
|
self.client.term.write(ansi.goto(item.row, self.position.col));
|
||||||
self.client.term.write(index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR());
|
self.client.term.write(index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR());
|
||||||
|
|
||||||
var text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
|
var text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
|
||||||
|
@ -60,9 +60,9 @@ util.inherits(VerticalMenuView, MenuView);
|
||||||
VerticalMenuView.prototype.redraw = function() {
|
VerticalMenuView.prototype.redraw = function() {
|
||||||
VerticalMenuView.super_.prototype.redraw.call(this);
|
VerticalMenuView.super_.prototype.redraw.call(this);
|
||||||
|
|
||||||
var x = this.position.x;
|
var x = this.position.row;
|
||||||
for(var i = this.viewWindow.top; i <= this.viewWindow.bottom; ++i) {
|
for(var i = this.viewWindow.top; i <= this.viewWindow.bottom; ++i) {
|
||||||
this.items[i].xPosition = x;
|
this.items[i].row = x;
|
||||||
x += this.itemSpacing + 1;
|
x += this.itemSpacing + 1;
|
||||||
this.items[i].focused = this.focusedItemIndex === i;
|
this.items[i].focused = this.focusedItemIndex === i;
|
||||||
this.drawItem(i);
|
this.drawItem(i);
|
||||||
|
|
38
core/view.js
38
core/view.js
|
@ -112,29 +112,29 @@ View.prototype.getId = function() {
|
||||||
|
|
||||||
View.prototype.setPosition = function(pos) {
|
View.prototype.setPosition = function(pos) {
|
||||||
//
|
//
|
||||||
// We allow [x, y], { x : x, y : y }, or (x, y)
|
// Allow the following forms: [row, col], { row : r, col : c }, or (row, col)
|
||||||
//
|
//
|
||||||
if(util.isArray(pos)) {
|
if(util.isArray(pos)) {
|
||||||
this.position.x = pos[0];
|
this.position.row = pos[0];
|
||||||
this.position.y = pos[1];
|
this.position.col = pos[1];
|
||||||
} else if(pos.x && pos.y) {
|
} else if(pos.row && pos.col) {
|
||||||
this.position.x = pos.x;
|
this.position.row = pos.row;
|
||||||
this.position.y = pos.y;
|
this.position.col = pos.col;
|
||||||
} else if(2 === arguments.length) {
|
} else if(2 === arguments.length) {
|
||||||
this.position.x = parseInt(arguments[0], 10);
|
this.position.row = parseInt(arguments[0], 10);
|
||||||
this.position.y = parseInt(arguments[1], 10);
|
this.position.col = parseInt(arguments[1], 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!(isNaN(this.position.x)));
|
assert(!(isNaN(this.position.row)));
|
||||||
assert(!(isNaN(this.position.y)));
|
assert(!(isNaN(this.position.col)));
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
this.position.x > 0 && this.position.x <= this.client.term.termHeight,
|
this.position.row > 0 && this.position.row <= this.client.term.termHeight,
|
||||||
'X position ' + this.position.x + ' out of terminal range ' + this.client.term.termHeight);
|
'X position ' + this.position.row + ' out of terminal range ' + this.client.term.termHeight);
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
this.position.y > 0 && this.position.y <= this.client.term.termWidth,
|
this.position.col > 0 && this.position.col <= this.client.term.termWidth,
|
||||||
'Y position ' + this.position.y + ' out of terminal range ' + this.client.term.termWidth);
|
'Y position ' + this.position.col + ' out of terminal range ' + this.client.term.termWidth);
|
||||||
};
|
};
|
||||||
|
|
||||||
View.prototype.setDimension = function(dimens) {
|
View.prototype.setDimension = function(dimens) {
|
||||||
|
@ -158,17 +158,17 @@ View.prototype.getSGR = function() {
|
||||||
return this.ansiSGR;
|
return this.ansiSGR;
|
||||||
};
|
};
|
||||||
|
|
||||||
View.prototype.getStyleSGR = function(x) {
|
View.prototype.getStyleSGR = function(n) {
|
||||||
assert(_.isNumber(x));
|
assert(_.isNumber(n));
|
||||||
return this['styleSGR' + x];
|
return this['styleSGR' + n];
|
||||||
}
|
};
|
||||||
|
|
||||||
View.prototype.getFocusSGR = function() {
|
View.prototype.getFocusSGR = function() {
|
||||||
return this.ansiFocusSGR;
|
return this.ansiFocusSGR;
|
||||||
};
|
};
|
||||||
|
|
||||||
View.prototype.redraw = function() {
|
View.prototype.redraw = function() {
|
||||||
this.client.term.write(ansi.goto(this.position.x, this.position.y));
|
this.client.term.write(ansi.goto(this.position.row, this.position.col));
|
||||||
};
|
};
|
||||||
|
|
||||||
View.prototype.setFocus = function(focused) {
|
View.prototype.setFocus = function(focused) {
|
||||||
|
|
Loading…
Reference in New Issue