aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src/ssh_io.erl
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2012-11-16 10:42:41 +0100
committerFredrik Gustafsson <[email protected]>2012-11-16 10:42:41 +0100
commit44f36e3eb20f5f9efcdfa5b6ecb3e22fc4ab9011 (patch)
tree807074729cc6db478ce659afb8128b1a83cd266e /lib/ssh/src/ssh_io.erl
parent9aa4de3c97b98974f32c2b8e07c971343faf3f13 (diff)
parentfe607363e2a67f9d565c1b618a3a4fd4bd0baa4e (diff)
downloadotp-44f36e3eb20f5f9efcdfa5b6ecb3e22fc4ab9011.tar.gz
otp-44f36e3eb20f5f9efcdfa5b6ecb3e22fc4ab9011.tar.bz2
otp-44f36e3eb20f5f9efcdfa5b6ecb3e22fc4ab9011.zip
Merge branch 'fredrik/ssh/user-input/OTP-10513' into maint
* fredrik/ssh/user-input/OTP-10513: 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.erl61
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) ->