aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src/ssh_io.erl
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2012-11-15 14:32:52 +0100
committerFredrik Gustafsson <[email protected]>2012-11-15 14:32:52 +0100
commite9d46adb58b940a92874b2c4bcc833dfcf7375a3 (patch)
tree181317a1a03d54bc335593e9627e5b7d67e0f228 /lib/ssh/src/ssh_io.erl
parent55c2b0b6d55fe6a011671832b5529cb1c7b636a8 (diff)
downloadotp-e9d46adb58b940a92874b2c4bcc833dfcf7375a3.tar.gz
otp-e9d46adb58b940a92874b2c4bcc833dfcf7375a3.tar.bz2
otp-e9d46adb58b940a92874b2c4bcc833dfcf7375a3.zip
Fixed user interaction ssh
Diffstat (limited to 'lib/ssh/src/ssh_io.erl')
-rw-r--r--lib/ssh/src/ssh_io.erl56
1 files changed, 33 insertions, 23 deletions
diff --git a/lib/ssh/src/ssh_io.erl b/lib/ssh/src/ssh_io.erl
index 1dbd097423..fc7a572f7c 100644
--- a/lib/ssh/src/ssh_io.erl
+++ b/lib/ssh/src/ssh_io.erl
@@ -23,37 +23,47 @@
-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
+ proplists:get_value(user_pid, Ssh#ssh.opts) ! {self(), user_password},
+ receive
+ Answer ->
+ case Answer of
+ "" ->
+ read_password(Prompt, Ssh);
+ Pass -> Pass
+ end
end.
listify(A) when is_atom(A) ->