Skip to content
Browse files

code cleanup, quitting works

  • Loading branch information...
1 parent a6a229e commit 5f839035c288208d83889e19d0eeabb08b0f73cd @ahk committed Jul 24, 2010
Showing with 16 additions and 6 deletions.
  1. +16 −6 cli.js
View
22 cli.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node
-var stdin = process.openStdin(), sys = require('sys'), cli;
+var sys = require('sys'), cli;
utils = {
slice: function (arr, start, opt_end) {
@@ -13,7 +13,7 @@ utils = {
}
cli = {
- prompt: 'noding! ~ ',
+ prompt: 'noding! ~ ',
msgHeader: 'node ... ',
inspect: function(thingy) {
@@ -25,28 +25,38 @@ cli = {
return this.msgHeader;
}
var text = [];
- text.push('\n')
text.push(this.msgHeader);
text.push(utils.slice(arguments, 0));
text.push('\n');
return text.join('');
},
run: function() {
+ var stdin = process.openStdin();
+ var newLineOnExit = true;
+
stdin.setEncoding('utf8');
process.stdout.write('noding ... loading ...\n');
process.stdout.write(cli.prompt);
stdin.addListener('data', function (chunk) {
- if (chunk == 'quit') {
- stdin.end();
+ if (chunk === 'quit\n') {
+ newLineOnExit = false;
+ process.exit();
}
process.stdout.write(chunk);
process.stdout.write(cli.prompt);
});
stdin.addListener('end', function () {
- process.stdout.write(cli.info('end'));
+ process.exit();
+ });
+
+ process.addListener('exit', function () {
+ var msg = cli.info('end');
+ if (newLineOnExit)
+ msg = '\n' + msg;
+ process.stdout.write(msg);
});
}

0 comments on commit 5f83903

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