Permalink
Browse files

A MUCH LOUDER EXAMPLE THAN THE OTHER EXAMPLES WHICH, ARE ALL DISTURBI…

…NGLY LOWER IN THEIR CASE
  • Loading branch information...
1 parent 0f8f4f7 commit 9adeb65729ebaddcf001082bfcbba8738d750ef2 @isaacs isaacs committed Oct 2, 2012
Showing with 29 additions and 0 deletions.
  1. +29 −0 examples/CAPSLOCKTYPER.JS
View
@@ -0,0 +1,29 @@
+var Transform = require('../transform');
+var inherits = require('util').inherits;
+
+// subclass
+function MyStream () {
+ Transform.call(this);
+}
+inherits(MyStream, Transform);
+
+MyStream.prototype._transform = function (chunk, outputFn, callback) {
+ outputFn(new Buffer(String(chunk).toUpperCase()));
+ callback();
+};
+
+// use it!
+var s = new MyStream();
+process.stdin.resume();
+process.stdin.pipe(s).pipe(process.stdout);
+if (process.stdin.setRawMode)
+ process.stdin.setRawMode(true);
+process.stdin.on('data', function (c) {
+ c = c.toString();
+ if (c === '\u0003' || c === '\u0004') {
+ process.stdin.pause();
+ s.end();
+ }
+ if (c === '\r')
+ process.stdout.write('\n');
+});

0 comments on commit 9adeb65

Please sign in to comment.