X-Git-Url: https://jasonwoof.com/gitweb/?p=af-coffee.git;a=blobdiff_plain;f=client.coffee;h=9765703de69f2e535769466f7c5c0f3fc6b2f0d1;hp=a7dbca5a6e447fd8c4590056a4f43b2261cd066e;hb=956e082276ac2330d4c4e108c8f6b1b23943d057;hpb=ac50f2ea803eb6d5e59aa8309df328ea81573fcd diff --git a/client.coffee b/client.coffee index a7dbca5..9765703 100755 --- a/client.coffee +++ b/client.coffee @@ -85,7 +85,7 @@ class Session when 0 get_token callback when -1 - login callback + login.call this, callback else callback null, @token (token, callback) => @@ -103,17 +103,18 @@ class Session else callback err, result -ask = (opts, callback) -> - process.stdout.write opts.prompt - process.stdin.setEncoding 'utf8' - process.stdin.resume() - process.stdin.once 'data', (line) -> - if opts.silent - # send ^[[A^[[2K to move the cursor up one line, then clear that line - process.stdout.write new Buffer [27, 91, 65, 27, 91, 50, 75] - process.stdout.write opts.prompt + "***\n" - process.stdin.pause() - callback null, (line.substr 0, line.length - 1) + ask: (opts, callback) -> + process.stdout.write @log_whitespace() + opts.prompt + process.stdin.setEncoding 'utf8' + process.stdin.resume() + process.stdin.once 'data', (line) => + if opts.silent + # send ^[[A^[[2K to move the cursor up one line, then clear that line + process.stdout.write new Buffer [27, 91, 65, 27, 91, 50, 75] + process.stdout.write @log_whitespace() + opts.prompt + "***\n" + process.stdin.pause() + @log_mid = false + callback null, (line.substr 0, line.length - 1) get_token = (callback) -> fs.readFile token_file, 'utf8', (err, token) -> @@ -124,9 +125,9 @@ get_token = (callback) -> login = (callback) -> async.waterfall [ - (callback) -> async.series [ - (callback) -> ask prompt: 'username: ', callback - (callback) -> ask prompt: 'password: ', silent: true, callback + (callback) => async.series [ + (callback) => @ask prompt: 'username: ', callback + (callback) => @ask prompt: 'password: ', silent: true, callback ], callback ([username, password], callback) -> af.login username, password, callback