Skip to content

Commit

Permalink
feat(cursor): Implements fill method
Browse files Browse the repository at this point in the history
Fill method fills the specified region by coordinates with specified background, foreground and
symbol
  • Loading branch information
ghaiklor committed Nov 12, 2015
1 parent 3200eb7 commit f6a6cca
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/Cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export const ERASE_REGIONS = {
ENTIRE_SCREEN: 'screen'
};

export default class Cursor {
export class Cursor {
/**
* Creates new Cursor instance
* @constructor
* @param {Stream|Boolean} [stdout]
* @param {Stream|Boolean} [stdin]
*/
constructor(stdout = process.stdout, stdin = false) {
this._cursor = charm();

Expand Down Expand Up @@ -138,6 +144,33 @@ export default class Cursor {
return this;
}

/**
* Fill the specified region with symbol
* @param {String} [symbol] Symbol that will be used for filling the region
* @param {String} [background] Background color from COLORS
* @param {String} [foreground] Foreground color from COLORS
* @param {Number} x1
* @param {Number} y1
* @param {Number} x2
* @param {Number} y2
* @returns {Cursor}
*/
fill({x1, y1, x2, y2, symbol = ' ', background, foreground}) {
let filler = new Array(x2 - x1).fill(symbol).join('');

if (background) this.background(background);
if (foreground) this.foreground(foreground);

this.setPosition(x1, y1);

while (y1 <= y2) {
this.write(filler);
this.setPosition(x1, ++y1);
}

return this;
}

/**
* Set the cursor invisible
* @returns {Cursor}
Expand Down

0 comments on commit f6a6cca

Please sign in to comment.