-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprompt.ml
47 lines (39 loc) · 1.47 KB
/
prompt.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(* Interface for prompting from the command-line
Copyright (C) 2008 Michael Bacarella <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*)
open Unix
let print_flush s =
Stdlib.print_string s;
Stdlib.flush Stdlib.stdout
let read_password prompt =
print_flush prompt;
let term_init = tcgetattr stdin in
let term_no_echo = { term_init with c_echo = false } in
tcsetattr stdin TCSANOW term_no_echo;
let password =
try Some (read_line ()) with
| _ -> None
(* term echo back on no matter what! *)
in
tcsetattr stdin TCSAFLUSH term_init;
print_flush "\n";
password
let _test () =
match read_password "enter combination: " with
| None -> failwith "error reading combination"
| Some password -> Printf.printf "I enjoyed reading your password -->%s<--\n" password
(*
let () =
test ()
*)