# HG changeset patch # User Kim Alvefur # Date 1659488486 -7200 # Node ID e4391832be1e7171c7764cbb99ea7da24ca684e4 # Parent fafdcde2e2eb548ae8b49793c1a550aaeb855959 clix: Read password from stdin if not available diff -r fafdcde2e2eb -r e4391832be1e clix.lua --- a/clix.lua Wed Dec 01 17:25:25 2021 +0100 +++ b/clix.lua Wed Aug 03 03:01:26 2022 +0200 @@ -52,6 +52,22 @@ end end +local function read_password() + io.write("Password: ") + local stty_ret = os.execute("stty -echo 2>/dev/null"); + if stty_ret ~= 0 then + io.write("\027[08m"); -- ANSI 'hidden' text attribute + end + local ok, pass = pcall(io.read, "*l"); + if stty_ret == 0 then + os.execute("stty sane"); + else + io.write("\027[00m"); + end + io.write("\n"); + if ok then return pass; end +end + function clix_connect(opts, on_connect, plugins) local account = accounts[opts.account or "default"]; if not (account and account.jid) then @@ -94,9 +110,13 @@ -- Optional config parameters conn.connect_host = account.address; conn.connect_port = account.port; + + if not account.password and opts.interactive then + account.password = read_password() + end -- Connect! - conn:connect_client(account.jid, opts.password or account.password); + conn:connect_client(account.jid, account.password); -- COMPAT: Tigase discards stanzas sent at the same time as local _real_close = conn.close;