From fd186300a1619beb43d9061b10f6b608797e5722 Mon Sep 17 00:00:00 2001 From: anseki Date: Wed, 8 Apr 2015 22:57:52 +0900 Subject: [PATCH] Fix: NL can't be output. --- lib/read.ps1 | 2 +- lib/read.sh | 33 +++++++++++++++++++-------------- package.json | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/read.ps1 b/lib/read.ps1 index c23098c..7599f40 100644 --- a/lib/read.ps1 +++ b/lib/read.ps1 @@ -57,7 +57,7 @@ function execWithTTY ($command, $getRes = $False) { function writeTTY ($text) { execWithTTY ('Write-Host (''' + - (($text -replace '''', '''''') -replace '\n', '''+"`n"+''') + ''') -NoNewline') + (($text -replace '''', '''''') -replace '[\r\n]', '''+"`n"+''') + ''') -NoNewline') } if ($options.display) { diff --git a/lib/read.sh b/lib/read.sh index 3c75ba3..e33bc7c 100644 --- a/lib/read.sh +++ b/lib/read.sh @@ -4,8 +4,11 @@ # Copyright (c) 2015 anseki # Licensed under the MIT license. +# Use perl for compatibility of sed/awk of GNU / POSIX, BSD. (tr too, maybe) +# Hide "\n" from shell by "\fNL" + decode_arg() { - printf '%s' "$(printf '%s' "$1" | perl -pe 's/#(\d+);/sprintf("%c", $1)/ge')" + printf '%s' "$(printf '%s' "$1" | perl -pe 's/#(\d+);/sprintf("%c", $1)/ge; s/[\r\n]/\fNL/g')" } # getopt(s) @@ -36,12 +39,13 @@ save_tty="$(stty --file=/dev/tty -g 2>/dev/null || stty -F /dev/tty -g 2>/dev/nu [ "$options_hideEchoBack" = true ] && [ -z "$options_mask" ] && silent=true [ "$options_hideEchoBack" != true ] && [ "$options_keyIn" != true ] && is_cooked=true -write_tty() { # 2nd arg: enable escape sequence - if [ "$2" = true ]; then - printf '%b' "$1" >/dev/tty - else - printf '%s' "$1" >/dev/tty - fi +write_tty() { + # if [ "$2" = true ]; then + # printf '%b' "$1" >/dev/tty + # else + # printf '%s' "$1" >/dev/tty + # fi + printf '%s' "$1" | perl -pe 's/\fNL/\r\n/g' >/dev/tty } replace_allchars() { ( @@ -75,7 +79,6 @@ if [ "$options_keyIn" = true ] && [ -n "$options_limit" ]; then else # Safe list # limit_ptn="$(printf '%s' "$options_limit" | sed 's/\([a-z]\)/\L\1\U\1/ig')" - # for compatibility of sed of GNU / POSIX, BSD. (tr too, maybe) limit_ptn="$(printf '%s' "$options_limit" | perl -pe 's/([a-z])/lc($1) . uc($1)/ige')" fi fi @@ -83,15 +86,17 @@ fi while : do if [ "$is_cooked" != true ]; then - chunk="$(dd if=/dev/tty bs=1 count=1 2>/dev/null)" + # chunk="$(dd if=/dev/tty bs=1 count=1 2>/dev/null)" + chunk="$(dd if=/dev/tty bs=1 count=1 2>/dev/null | perl -pe 's/[\r\n]/\fNL/g')" else IFS= read -r chunk