UNPKG

sirrobert-terminal

Version:

A class for interacting with shell terminals.

50 lines (40 loc) 1.01 kB
function gen_move_str (num) { return "\033" + "[" (num || "") + "D"; } function Terminal () { } Terminal.prototype.get_cols = function () { return process.stdout.columns; }; Terminal.prototype.get_rows = function () { return process.stdout.rows; }; Terminal.prototype.cr = function () { process.stdout.write("\r"); } Terminal.prototype.clearLine = function () { this.cr(); process.stdout.write(Array(this.get_cols()).join(" ")); this.cr(); } Terminal.prototype.left = function (num) { if (typeof num === "undefined") { process.stdout.write(this.left_str); } else { for (var i = 0; i < num; i++) { process.stdout.write(this.left_str); } } } Terminal.prototype.right = function (num) { if (typeof num === "undefined") { process.stdout.write(this.right_str); } else { for (var i = 0; i < num; i++) { process.stdout.write(this.right_str); } } } Terminal.prototype.left_str = ""; Terminal.prototype.right_str = ""; module.exports = Terminal;