From 0905019b5584a262915ebbe15ead55e6578d935f Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Tue, 1 Sep 2015 16:43:47 +0200 Subject: [PATCH] I can't believe I forgot some files. But I did. --- lib/cli.js | 29 ++++++++++++++++++++++++++++ lib/ui-widgets/chatbox.js | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 lib/cli.js create mode 100644 lib/ui-widgets/chatbox.js diff --git a/lib/cli.js b/lib/cli.js new file mode 100644 index 0000000..e4fc61e --- /dev/null +++ b/lib/cli.js @@ -0,0 +1,29 @@ +module.exports = function(data){ + data.cli = require('commander') + data.cli + .version('0.1.0') + .description('the full-featured curses-like command line client for Telegram.\n\n More Info: https://github.com/fazo96/telecommander') + .usage('[options]') + .option('-d, --debug', "debug mode") + .option('-t, --testdc',"use Telegram's test DataCenter") + .option('-n, --nuke','delete user data and access key (overdramatic log out)') + .parse(process.argv) + + data.debug = data.cli.debug + + if(data.cli.testdc){ + data.dataCenter = data.telegramLink.TEST_PRIMARY_DC + } else data.dataCenter = data.telegramLink.PROD_PRIMARY_DC + + if(data.cli.nuke){ + var fs = require('fs') + try { + fs.unlinkSync(data.keyFile) + fs.unlinkSync(data.userFile) + } catch (e){ + console.log("Couldn't delete "+data.keyFile+" and "+data.userFile+". They probably don't exist.") + } + console.log('Deleted',data.keyFile,'and',data.userFile) + process.exit(0) + } +} diff --git a/lib/ui-widgets/chatbox.js b/lib/ui-widgets/chatbox.js new file mode 100644 index 0000000..37fa715 --- /dev/null +++ b/lib/ui-widgets/chatbox.js @@ -0,0 +1,40 @@ +var blessed = require('blessed') + +function ChatBox(options) { + var self = this + if (!(this instanceof blessed.Node)) { + return new ChatBox(options) + } + options = options || {} + options.scrollable = true + this.options = options + blessed.Box.call(this, options) + this.on('log',function(text){ + if(self.options.autoscroll) self.setScrollPerc(100); + this.setLine(this.getLines().length-1,this.getLine(this.getLines().length-1).trim()) + self.screen.render() + }) + this.on('prepend',function(){ + this.setLine(this.getLines().length-1,this.getLine(this.getLines().length-1).trim()) + self.screen.render() + }) + this.on('click',function(){ + self.focus() + self.screen.render() + }) +} + +ChatBox.prototype.__proto__ = blessed.Box.prototype +ChatBox.prototype.type = 'chatbox' +ChatBox.prototype.add = ChatBox.prototype.log = function(){ + var text = Array.prototype.slice.call(arguments).join(' ') + this.pushLine(text) + this.emit('log',text) +} +ChatBox.prototype.prepend = function(){ + var text = Array.prototype.slice.call(arguments).join(' ') + this.insertLine(0,text) + this.emit('prepend',text) +} + +module.exports = ChatBox