Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle cases where more than one byte comes at a time in raw mode

  • Loading branch information...
commit 2e97faf203dfff5bc80cdbd6c54e9652094054b4 1 parent d746f75
@isaacs authored
Showing with 4 additions and 7 deletions.
  1. +4 −7 lib/read.js
View
11 lib/read.js
@@ -122,12 +122,10 @@ function rawRead (def, timeout, delim, silent, num, cb) {
stdin.on("error", cb)
stdin.on("data", function D (c) {
// \r is my enemy.
- c = decoder.write(c).replace(/\r/g, "\n")
-
- switch (c) {
- case "": // probably just a \r that was ignored.
- break
+ var s = decoder.write(c).replace(/\r/g, "\n")
+ var i = 0
+ LOOP: while (c = s.charAt(i++)) switch (c) {
case "\u007f": // backspace
val = val.substr(0, val.length - 1)
if (!silent) process.stdout.write('\b \b')
@@ -149,7 +147,6 @@ function rawRead (def, timeout, delim, silent, num, cb) {
stdin.removeListener("error", cb)
stdin.pause()
return cb(new Error("cancelled"))
- break
default: // just a normal char
val += buffer + c
@@ -159,7 +156,7 @@ function rawRead (def, timeout, delim, silent, num, cb) {
// explicitly process a delim if we have enough chars
// and stop the processing.
if (num && val.length >= num) D(delim)
- break
+ break LOOP
}
})
}
Please sign in to comment.
Something went wrong with that request. Please try again.