Software /
code /
clix
Diff
clix.lua @ 165:e4391832be1e
clix: Read password from stdin if not available
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 03 Aug 2022 03:01:26 +0200 |
parent | 131:58d485001448 |
child | 166:b0c586241224 |
line wrap: on
line diff
--- 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 </stream:stream> local _real_close = conn.close;