mirror of
https://github.com/fazo96/telecommander.git
synced 2025-01-10 11:34:20 +01:00
style update
This commit is contained in:
parent
92f37bf061
commit
09e51675bb
@ -41,30 +41,35 @@ screen.title = "Telecommander"
|
|||||||
|
|
||||||
var defaultStyle = {
|
var defaultStyle = {
|
||||||
fg: 'white',
|
fg: 'white',
|
||||||
border: { fg: 'gray' },
|
border: { fg: 'grey' },
|
||||||
scrollbar: {
|
scrollbar: {
|
||||||
bg: 'blue',
|
ch: '*'
|
||||||
fg: 'red'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contact list window
|
// Contact list window
|
||||||
var chats = blessed.list({
|
var chats = blessed.list({
|
||||||
|
keys: true,
|
||||||
|
label: 'Conversations',
|
||||||
left: 0,
|
left: 0,
|
||||||
top:0,
|
top:0,
|
||||||
height: screen.height-3,
|
height: screen.height-3,
|
||||||
width: '20%',
|
width: '20%',
|
||||||
border: { type: 'line' },
|
border: { type: 'line' },
|
||||||
mouse: true,
|
mouse: true,
|
||||||
invertSelected: false,
|
invertSelected: true,
|
||||||
style: defaultStyle,
|
style: defaultStyle,
|
||||||
})
|
})
|
||||||
chats.style.selected = { bg: 'blue' }
|
chats.style.item = { fg: 'grey' }
|
||||||
|
chats.style.selected = { fg: 'white' }
|
||||||
|
chats.focus()
|
||||||
|
|
||||||
// Function to create a log box
|
// Function to create a log box
|
||||||
function mkBox(){
|
function mkBox(label){
|
||||||
var box = blessed.log({
|
var box = blessed.log({
|
||||||
|
keys: true,
|
||||||
right: 0,
|
right: 0,
|
||||||
|
label: label,
|
||||||
width: '80%',
|
width: '80%',
|
||||||
height: screen.height - cmdline.height,
|
height: screen.height - cmdline.height,
|
||||||
border: { type: 'line' },
|
border: { type: 'line' },
|
||||||
@ -78,6 +83,8 @@ function mkBox(){
|
|||||||
|
|
||||||
// Command line prompt
|
// Command line prompt
|
||||||
var cmdline = blessed.textbox({
|
var cmdline = blessed.textbox({
|
||||||
|
keys: true,
|
||||||
|
label: 'Command for Telecommander',
|
||||||
inputOnFocus: true,
|
inputOnFocus: true,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 'center',
|
left: 'center',
|
||||||
@ -91,7 +98,7 @@ var statusWindow = "Status"
|
|||||||
|
|
||||||
// mgsBox holds the chat boxes for every list entry
|
// mgsBox holds the chat boxes for every list entry
|
||||||
var msgBox = { }
|
var msgBox = { }
|
||||||
msgBox[statusWindow] = mkBox()
|
msgBox[statusWindow] = mkBox(statusWindow)
|
||||||
|
|
||||||
// Add stuff to the screen
|
// Add stuff to the screen
|
||||||
screen.append(chats);
|
screen.append(chats);
|
||||||
@ -107,6 +114,9 @@ screen.on('resize',function(){
|
|||||||
chats.height = screen.height - cmdline.height
|
chats.height = screen.height - cmdline.height
|
||||||
screen.render()
|
screen.render()
|
||||||
})
|
})
|
||||||
|
screen.key('tab',function(){
|
||||||
|
screen.focusPush(chats)
|
||||||
|
})
|
||||||
screen.render()
|
screen.render()
|
||||||
|
|
||||||
// Contacts holds all the contacts data
|
// Contacts holds all the contacts data
|
||||||
@ -206,12 +216,18 @@ function command(cmd){
|
|||||||
chats.on('select',function(selected){
|
chats.on('select',function(selected){
|
||||||
log('SELECT:',selected.content)
|
log('SELECT:',selected.content)
|
||||||
switchToBox(selected.content)
|
switchToBox(selected.content)
|
||||||
|
screen.focusPush(cmdline)
|
||||||
|
screen.render()
|
||||||
})
|
})
|
||||||
|
|
||||||
function switchToBox(boxname){
|
function switchToBox(boxname){
|
||||||
if(selectedWindow && msgBox[selectedWindow])
|
if(selectedWindow && msgBox[selectedWindow])
|
||||||
msgBox[selectedWindow].hide()
|
msgBox[selectedWindow].hide()
|
||||||
selectedWindow = boxname;
|
selectedWindow = boxname;
|
||||||
|
if(selectedWindow != statusWindow)
|
||||||
|
cmdline.setLabel('to '+selectedWindow)
|
||||||
|
else
|
||||||
|
cmdline.setLabel('Command for Telecommander')
|
||||||
var newb = getMsgBox(selectedWindow)
|
var newb = getMsgBox(selectedWindow)
|
||||||
newb.show()
|
newb.show()
|
||||||
}
|
}
|
||||||
@ -223,8 +239,8 @@ function getMsgBox(chat,switchto){
|
|||||||
return msgBox[statusWindow]
|
return msgBox[statusWindow]
|
||||||
}
|
}
|
||||||
if(!msgBox[chat]){
|
if(!msgBox[chat]){
|
||||||
log('Generating window: "'+chat+'"')
|
//log('Generating window: "'+chat+'"')
|
||||||
msgBox[chat] = mkBox()
|
msgBox[chat] = mkBox(chat)
|
||||||
screen.append(msgBox[chat])
|
screen.append(msgBox[chat])
|
||||||
getMessages(chat,msgBox[chat])
|
getMessages(chat,msgBox[chat])
|
||||||
} // else log('Getting window','"'+chat+'"')
|
} // else log('Getting window','"'+chat+'"')
|
||||||
@ -251,7 +267,7 @@ cmdline.on('submit',function(value){
|
|||||||
cmdline.focus()
|
cmdline.focus()
|
||||||
})
|
})
|
||||||
|
|
||||||
cmdline.focus() // make sure prompt is focused
|
//cmdline.focus() // make sure prompt is focused
|
||||||
|
|
||||||
function quit(){
|
function quit(){
|
||||||
if(connected || client != undefined){
|
if(connected || client != undefined){
|
||||||
@ -263,7 +279,7 @@ function quit(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Catch ctrl-c or escape event and close program
|
// Catch ctrl-c or escape event and close program
|
||||||
cmdline.key(['escape','C-c'], function(ch,key){
|
screen.key(['escape','C-c'], function(ch,key){
|
||||||
quit()
|
quit()
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -291,9 +307,9 @@ function sendMsg(name,str){
|
|||||||
}
|
}
|
||||||
var peer = idToPeer(nameToObj(name).id,nameToObj(name).title?'group':'user')
|
var peer = idToPeer(nameToObj(name).id,nameToObj(name).title?'group':'user')
|
||||||
var randid = parseInt(Math.random() * 1000000000)
|
var randid = parseInt(Math.random() * 1000000000)
|
||||||
log('Sending Message to:',peer.toPrintable())
|
//log('Sending Message to:',peer.toPrintable())
|
||||||
client.messages.sendMessage(peer,str,randid,function(sent){
|
client.messages.sendMessage(peer,str,randid,function(sent){
|
||||||
log('Sent message:','"'+str+'"','to:',selectedWindow+':',sent.toPrintable())
|
//log('Sent message:','"'+str+'"','to:',selectedWindow+':',sent.toPrintable())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,25 +392,17 @@ function updateState(newstate){
|
|||||||
// process an update
|
// process an update
|
||||||
function onUpdate(upd){
|
function onUpdate(upd){
|
||||||
log('Got Update:',upd.toPrintable())
|
log('Got Update:',upd.toPrintable())
|
||||||
// Process update
|
|
||||||
if(update.message){
|
|
||||||
// It's a chat message
|
|
||||||
log('Writing chat message to ',update.from_id)
|
|
||||||
//appendMsg(update,getName(update.from_id))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadUpdates(){
|
function downloadUpdates(){
|
||||||
client.updates.getDifference(state.pts,state.date,state.qts,function(res){
|
client.updates.getDifference(state.pts,state.date,state.qts,function(res){
|
||||||
if(!res.instanceOf('api.type.updates.DifferenceEmpty')){
|
if(!res.instanceOf('api.type.updates.DifferenceEmpty')){
|
||||||
//log('Got Diff: ',res.toPrintable())
|
log('Got Diff: ',res.toPrintable())
|
||||||
if(res.state){
|
if(res.state){
|
||||||
updateState(res.state)
|
updateState(res.state)
|
||||||
}
|
}
|
||||||
if(res.new_messages){
|
if(res.new_messages){
|
||||||
res.new_messages.list.forEach(function(msg){
|
res.new_messages.list.forEach(function(msg){
|
||||||
if(!msg.message) return log('Empty message!',msg)
|
|
||||||
//log('Scheduling message: '+msg.message)
|
|
||||||
appendMsg(msg,undefined,false,true)
|
appendMsg(msg,undefined,false,true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -421,7 +429,7 @@ function getName(id,type){
|
|||||||
return groups[id].title
|
return groups[id].title
|
||||||
else if(type === 'user' && contacts[id])
|
else if(type === 'user' && contacts[id])
|
||||||
return nameForUser(contacts[id].user)
|
return nameForUser(contacts[id].user)
|
||||||
else log('Failed to find name for:',id)
|
else log('Failed to find name for',type,id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get message history with given name in the given box
|
// Get message history with given name in the given box
|
||||||
@ -440,7 +448,7 @@ function getMessages(name,box){
|
|||||||
if(!peer) return log('Could not find peer:',name)
|
if(!peer) return log('Could not find peer:',name)
|
||||||
client.messages.getHistory(peer,0,-1,20,function(res){
|
client.messages.getHistory(peer,0,-1,20,function(res){
|
||||||
//log(res.toPrintable())
|
//log(res.toPrintable())
|
||||||
log('Got history for: '+getName(peer.user_id||peer.chat_id,peer.chat_id?'group':'user'))
|
//log('Got history for: '+getName(peer.user_id||peer.chat_id,peer.chat_id?'group':'user'))
|
||||||
if(!res.messages){
|
if(!res.messages){
|
||||||
return box.add(res.toPrintable())
|
return box.add(res.toPrintable())
|
||||||
}
|
}
|
||||||
@ -450,7 +458,7 @@ function getMessages(name,box){
|
|||||||
if(res.messages.list.length === 0)
|
if(res.messages.list.length === 0)
|
||||||
return appendToUserBox('No messages.',res)
|
return appendToUserBox('No messages.',res)
|
||||||
res.messages.list.forEach(function(msg){
|
res.messages.list.forEach(function(msg){
|
||||||
if(!msg.message) return log('Empty message!',msg.toPrintable())
|
//if(!msg.message) return log('Empty message!',msg.toPrintable())
|
||||||
//log('Scheduling message: '+msg.toPrintable())
|
//log('Scheduling message: '+msg.toPrintable())
|
||||||
appendMsg(msg)
|
appendMsg(msg)
|
||||||
})
|
})
|
||||||
@ -504,7 +512,17 @@ function appendMsg(msg,toBoxId,bare,smartmode){
|
|||||||
var from = msg.from_id
|
var from = msg.from_id
|
||||||
var date = moment.unix(msg.date).fromNow()
|
var date = moment.unix(msg.date).fromNow()
|
||||||
name = getName(from,'user')
|
name = getName(from,'user')
|
||||||
box.add(date+' | '+(name || from)+' > '+msg.message)
|
var txt
|
||||||
|
if(msg.media){
|
||||||
|
if(msg.media.photo)
|
||||||
|
txt = ' <*> (Photo)'
|
||||||
|
else if(msg.media.audio)
|
||||||
|
txt = " <*> (Audio Message) "+msg.media.audio.duration+" seconds"
|
||||||
|
else if(msg.message)
|
||||||
|
txt = ' > '+msg.message
|
||||||
|
else txt = " <*> (Unsupported Message)"
|
||||||
|
}
|
||||||
|
box.add(date+' | '+(name || from)+txt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user