1
0
mirror of https://github.com/fazo96/telecommander.git synced 2025-01-10 11:34:20 +01:00

I can't believe I forgot some files. But I did.

This commit is contained in:
Enrico Fasoli 2015-09-01 16:43:47 +02:00
parent 93b0c8a9b6
commit 0905019b55
2 changed files with 69 additions and 0 deletions

29
lib/cli.js Normal file
View File

@ -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)
}
}

40
lib/ui-widgets/chatbox.js Normal file
View File

@ -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