Skip to content

Commit

Permalink
Fix npm#3 Process backspace characters properly in raw reads
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 11, 2012
1 parent ce40398 commit d746f75
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/read.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ function rawRead (def, timeout, delim, silent, num, cb) {
case "": // probably just a \r that was ignored. case "": // probably just a \r that was ignored.
break break


case "\u007f": // backspace
val = val.substr(0, val.length - 1)
if (!silent) process.stdout.write('\b \b')
break

case "\u0004": // EOF case "\u0004": // EOF
case delim: case delim:
raw(false) raw(false)
Expand All @@ -151,7 +156,8 @@ function rawRead (def, timeout, delim, silent, num, cb) {
buffer = "" buffer = ""
if (!silent) process.stdout.write(c) if (!silent) process.stdout.write(c)


// explicitly process a delim if we have enough chars. // explicitly process a delim if we have enough chars
// and stop the processing.
if (num && val.length >= num) D(delim) if (num && val.length >= num) D(delim)
break break
} }
Expand Down

0 comments on commit d746f75

Please sign in to comment.