diff options
author | Fredrik Gustafsson <[email protected]> | 2012-11-16 10:46:13 +0100 |
---|---|---|
committer | Fredrik Gustafsson <[email protected]> | 2012-11-16 10:46:13 +0100 |
commit | 054ea4f360b2aaea2dc56fe70c9a6706c6494c71 (patch) | |
tree | ba9d3cef0902394d1c4ab97bdc44e56287bb10c4 /lib/ssh/src/ssh_io.erl | |
parent | 94e3d2d216b843a2f3e7187e3f972ebbe3134eba (diff) | |
parent | 44f36e3eb20f5f9efcdfa5b6ecb3e22fc4ab9011 (diff) | |
download | otp-054ea4f360b2aaea2dc56fe70c9a6706c6494c71.tar.gz otp-054ea4f360b2aaea2dc56fe70c9a6706c6494c71.tar.bz2 otp-054ea4f360b2aaea2dc56fe70c9a6706c6494c71.zip |
Merge branch 'maint'
* maint:
Fixed if it is not the record to read from in read_password
Fixed user interaction ssh
Diffstat (limited to 'lib/ssh/src/ssh_io.erl')
-rw-r--r-- | lib/ssh/src/ssh_io.erl | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/lib/ssh/src/ssh_io.erl b/lib/ssh/src/ssh_io.erl index 1dbd097423..17a7cebb4a 100644 --- a/lib/ssh/src/ssh_io.erl +++ b/lib/ssh/src/ssh_io.erl @@ -23,37 +23,52 @@ -module(ssh_io). --export([yes_no/1, read_password/1, read_line/1, format/2]). +-export([yes_no/2, read_password/2, read_line/2, format/2]). -import(lists, [reverse/1]). +-include("ssh.hrl"). +read_line(Prompt, Ssh) -> + format("~s", [listify(Prompt)]), + proplists:get_value(user_pid, Ssh) ! {self(), question}, + receive + Answer -> + Answer + end. -read_line(Prompt) when is_list(Prompt) -> - io:get_line(list_to_atom(Prompt)); -read_line(Prompt) when is_atom(Prompt) -> - io:get_line(Prompt). - -read_ln(Prompt) -> - trim(read_line(Prompt)). - -yes_no(Prompt) -> +yes_no(Prompt, Ssh) -> io:format("~s [y/n]?", [Prompt]), - case read_ln('') of - "y" -> yes; - "n" -> no; - "Y" -> yes; - "N" -> no; - _ -> - io:format("please answer y or n\n"), - yes_no(Prompt) + proplists:get_value(user_pid, Ssh#ssh.opts) ! {self(), question}, + receive + Answer -> + case trim(Answer) of + "y" -> yes; + "n" -> no; + "Y" -> yes; + "N" -> no; + y -> yes; + n -> no; + _ -> + io:format("please answer y or n\n"), + yes_no(Prompt, Ssh) + end end. -read_password(Prompt) -> +read_password(Prompt, Ssh) -> format("~s", [listify(Prompt)]), - case io:get_password() of - "" -> - read_password(Prompt); - Pass -> Pass + case is_list(Ssh) of + false -> + proplists:get_value(user_pid, Ssh#ssh.opts) ! {self(), user_password}; + _ -> + proplists:get_value(user_pid, Ssh) ! {self(), user_password} + end, + receive + Answer -> + case Answer of + "" -> + read_password(Prompt, Ssh); + Pass -> Pass + end end. listify(A) when is_atom(A) -> |