[Pkg-javascript-commits] [node-mute-stream] 03/05: Imported Upstream version 0.0.4
Jérémy Lal
kapouer at moszumanska.debian.org
Tue Jul 29 00:30:49 UTC 2014
This is an automated email from the git hooks/post-receive script.
kapouer pushed a commit to branch master
in repository node-mute-stream.
commit 9df7824c6ec236edf7806903da848f6568e7aeec
Author: Jérémy Lal <kapouer at melix.org>
Date: Tue Jul 29 02:28:39 2014 +0200
Imported Upstream version 0.0.4
---
README.md | 6 ++++++
mute.js | 19 ++++++++++++++++++-
package.json | 2 +-
test/basic.js | 1 +
4 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 91b45c4..8ab1238 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,12 @@ All options are optional.
specified string when muted. (So you can show `****` instead of the
password, for example.)
+* `prompt` If you are using a replacement char, and also using a
+ prompt with a readline stream (as for a `Password: *****` input),
+ then specify what the prompt is so that backspace will work
+ properly. Otherwise, pressing backspace will overwrite the prompt
+ with the replacement character, which is weird.
+
## ms.mute()
Set `muted` to `true`. Turns `.write()` into a no-op.
diff --git a/mute.js b/mute.js
index 7746618..42eac31 100644
--- a/mute.js
+++ b/mute.js
@@ -11,6 +11,12 @@ function MuteStream (opts) {
this.muted = false
this.on('pipe', this._onpipe)
this.replace = opts.replace
+
+ // For readline-type situations
+ // This much at the start of a line being redrawn after a ctrl char
+ // is seen (such as backspace) won't be redrawn as the replacement
+ this._prompt = opts.prompt || null
+ this._hadControl = false
}
MuteStream.prototype = Object.create(Stream.prototype)
@@ -94,7 +100,18 @@ MuteStream.prototype.resume = function () {
MuteStream.prototype.write = function (c) {
if (this.muted) {
if (!this.replace) return true
- c = c.toString().replace(/./g, this.replace)
+ if (c.match(/^\u001b/)) {
+ this._hadControl = true
+ return this.emit('data', c)
+ } else {
+ if (this._prompt && this._hadControl &&
+ c.indexOf(this._prompt) === 0) {
+ this._hadControl = false
+ this.emit('data', this._prompt)
+ c = c.substr(this._prompt.length)
+ }
+ c = c.toString().replace(/./g, this.replace)
+ }
}
this.emit('data', c)
}
diff --git a/package.json b/package.json
index 8685517..4cd299c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mute-stream",
- "version": "0.0.3",
+ "version": "0.0.4",
"main": "mute.js",
"directories": {
"test": "test"
diff --git a/test/basic.js b/test/basic.js
index 2d1f6ae..41f9e10 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -19,6 +19,7 @@ PassThrough.prototype = Object.create(Stream.prototype, {
write: {
value: function (c) {
this.emit('data', c)
+ return true
}
},
end: {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mute-stream.git
More information about the Pkg-javascript-commits
mailing list