Utils: add getpass
This commit is contained in:
parent
6096592a22
commit
28adbb5814
@ -136,6 +136,22 @@ let getaddrinfo ~passive ~node ~service =
|
||||
addr in
|
||||
Lwt.return points
|
||||
|
||||
let getpass () =
|
||||
let open Unix in
|
||||
(* Turn echoing off and fail if we can't. *)
|
||||
let tio = tcgetattr stdin in
|
||||
let old_echo = tio.c_echo in
|
||||
let old_echonl = tio.c_echonl in
|
||||
tio.c_echo <- false ;
|
||||
tio.c_echonl <- true ;
|
||||
tcsetattr stdin TCSAFLUSH tio ;
|
||||
(* Read the passwd. *)
|
||||
let passwd = read_line () in
|
||||
(* Restore terminal. *)
|
||||
tio.c_echo <- old_echo ;
|
||||
tio.c_echonl <- old_echonl ;
|
||||
tcsetattr stdin TCSAFLUSH tio ;
|
||||
passwd
|
||||
|
||||
module Json = struct
|
||||
|
||||
|
@ -34,6 +34,10 @@ val getaddrinfo:
|
||||
node:string -> service:string ->
|
||||
(Ipaddr.V6.t * int) list Lwt.t
|
||||
|
||||
(** [getpass ()] reads a password from stdio while setting-up the
|
||||
terminal to not display the password being typed. *)
|
||||
val getpass : unit -> string
|
||||
|
||||
module Json : sig
|
||||
|
||||
(** Loads a JSON file in memory *)
|
||||
|
Loading…
Reference in New Issue
Block a user