Skip to content
Browse files

Initial checkin.

Signed-off-by: SchizoDuckie <schizoduckie@gmail.com>
  • Loading branch information...
0 parents commit b5bff37ba96e5e5465ecedf6dd8645e21f07a69c @SchizoDuckie committed Oct 20, 2010
Showing with 144 additions and 0 deletions.
  1. +23 −0 README
  2. +4 −0 example.js
  3. +117 −0 node-cli.js
  4. BIN screenshot.png
23 README
@@ -0,0 +1,23 @@
+
+Node.CLI
+By SchizoDuckie
+
+Super simple CLI cursor position control to spice up your script's functionality in terminal/console windows
+Requires sys
+v1.0
+
+Free to use and modify.
+
+
+
+Usage:
+
+
+require('./node-cli.js');
+
+cli.clear().move(20,20).color('red').write('Node.js').down(1).back(7).color('yellow').write('Rocks!').down(10);
+
+Try node example.js to see this in action.
+See screenshot.png for an impression of what you can do.
+
+Enjoy!
4 example.js
@@ -0,0 +1,4 @@
+require('./node-cli.js');
+
+
+cli.clear().move(20,20).color('red').write('Node.js').down(1).back(7).color('yellow').write('Rocks!').down(10);
117 node-cli.js
@@ -0,0 +1,117 @@
+/**
+ * Node.CLI
+ * By SchizoDuckie
+ *
+ * Super simple CLI cursor position control to spice up your script's functionality in terminal/console windows
+ * Requires sys
+ * v1.0
+ *
+ * Free to use and modify, enjoy!
+ */
+
+var sys = require("sys");
+
+
+function NodeCli () {
+
+ this.colors = {
+ grey: 30,
+ red: 31,
+ green: 32,
+ yellow: 33,
+ blue: 34,
+ magenta: 35,
+ cyan: 36,
+ white: 37
+ };
+
+ /**
+ * Echo color code, bold is optional
+ */
+ this.color = function(color, bold) {
+ sys.print('\x1B['+(bold ? 1 : 0)+';'+this.colors[color]+'m');
+ return(this);
+ };
+
+ /**
+ * Reset terminal to default color
+ */
+ this.resetColor = function() {
+ sys.print('\x1B[0m');
+ return(this);
+ };
+
+ /**
+ * Output string @ current x/y
+ */
+ this.write = function(string) {
+ sys.print(string);
+ return(this);
+ };
+
+ /**
+ * Position the Cursor to x/y
+ */
+ this.move = function(x,y) {
+ sys.print('\033['+x+';'+y+'H');
+ return this;
+ };
+
+ /**
+ * Move the cursor up x rows
+ */
+ this.up = function(x) {
+ sys.print('\033['+x+'A');
+ return this;
+ };
+
+ /**
+ * Move the cursor down x rows
+ */
+ this.down = function(x) {
+ sys.print('\033['+x+'B');
+ return this;
+ };
+
+ /**
+ * Move the cursor forward x rows
+ */
+ this.fwd = function(x) {
+ sys.print('\033['+x+'C');
+ return this;
+ };
+
+ /**
+ * Move the cursor backwards x columns
+ */
+ this.back = function(x) {
+ sys.print('\033['+x+'D');
+ return this;
+ };
+
+ /**
+ * Clear the entire screen
+ */
+ this.clear = function(x) {
+ sys.print('\033[2J');
+ return this;
+ };
+
+ /**
+ * Clear the current line
+ */
+ this.clearLine = function(x) {
+ sys.print('\033[K');
+ return this;
+ };
+
+ /**
+ * Clear the next x chars, keep cursor positioned where it started.
+ */
+ this.clearNext = function(x) {
+ return this.write(new Array(x+1).join(' ')).back(x);
+ }
+
+}
+
+cli = new NodeCli();
BIN screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b5bff37

Please sign in to comment.
Something went wrong with that request. Please try again.