/**
* A helper class for creating Multiline Text storage, base for other classes
*/
class Multiline {
/**
* @param {String[]} text - the array of strings
*/
constructor(text) {
this.textArray = text;
this.text = {};
let i = 0;
text.forEach((e) => {
this.text[i] = e;
i++;
});
this.current = 0;
this.al = text.length;
}
/**
* Get the text at a specific line
* @param {number} number - line number
* @returns {String}
*/
gL (number) {
return this.text[number];
}
/**
* Same as gL()
* @see Multiline#gL
*/
getLine (number) {
return this.gL(number);
}
/**
* Get the line that is currently selected
* @returns {string}
*/
gC () {
return this.text[this.current];
}
/**
* Same as gC()
* @see Multiline#gC
* @returns {string}
*/
getCurrent () {
return this.gC();
}
/**
* Set the currently selected line one higher
* Returns itself to allow chaining
* @returns {function}
*/
inc () {
if (this.current+1 < this.al) {
this.current++;
}
return this.inc;
}
/**
* Same as inc(), also returns itself
* @see Multiline#inc
*/
increment () {
return this.inc();
}
/**
* Set the currently selected line one lower
* Returns itself to allow chaining
* @returns {function}
*/
dec () {
if (this.current-1 > -1) {
this.current--;
}
return this.dec;
}
/**
* Same as dec(), also returns itself
* @see Multiline#dec
*/
decrement () {
return this.dec();
}
/**
* Get the length of the array
* @returns {number}
*/
get length () {
return this.al;
}
/**
* The line number of the currently selected line
* @returns {number}
*/
get cur () {
return this.current;
}
/**
* Get the array of strings, that was passed to the constructor
* @returns {String[]}
*/
get textArr () {
return this.textArray;
}
}
module.exports = Multiline;