From 0bc343b434dafac50fd238aed6c3a8be9b12586a Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Sat, 5 Sep 2015 15:07:53 +0200 Subject: [PATCH] added a status bar that shows last login/online status --- README.md | 3 +-- lib/ui.js | 42 ++++++++++++++++++++++++++++++++++++++---- lib/util.js | 2 +- telecommander.js | 1 + 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 94910b1..0f72483 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ As of __now__, __Telecommander lets you__: - Sign in with a code sent via SMS or Telegram until you delete the Telecommander session files or the session expires - Chat in groups and in private (it also marks messages as read when you read them) - Know when you have unread messages -- View who's online +- View who's online and when was the last time someone logged in - Do everything __completely in the terminal, even via ssh__ using only the keyboard - Do everything (except writing messages, duh) using only the mouse, in the terminal! - Navigate your contact and chat list @@ -25,7 +25,6 @@ As of __now__, __Telecommander lets you__: Waht's missing for version _0.1.0_ (__Almost done!__): -- View when was the last time someone logged in - Download latest messages on session start and show unreads What's missing (for future versions up to 1.0) diff --git a/lib/ui.js b/lib/ui.js index 0a09437..530a644 100644 --- a/lib/ui.js +++ b/lib/ui.js @@ -26,6 +26,7 @@ module.exports = function(data){ data.msgBox[data.selectedWindow].hide() if(boxname === undefined){ // Leave the clear + data.statusBar.hide() } else { // Switch window data.selectedWindow = boxname; @@ -37,12 +38,21 @@ module.exports = function(data){ data.cmdline.setLabel('Command for Telecommander') } var newb = data.getMsgBox(data.selectedWindow) + data.refreshStatusBar() + data.statusBar.show() newb.show() newb.emit('scroll') } data.screen.render() } + data.refreshStatusBar = function(){ + var obj = data.nameToObj(data.selectedWindow) + if(obj && obj.id) + data.statusBar.setContent(data.getName(obj.id,obj.title?'group':'user','statusbar')) + else data.statusBar.setContent(data.selectedWindow) + } + data.screen = blessed.screen({ smartCSR: true, dockBorders: true @@ -117,10 +127,11 @@ module.exports = function(data){ tags: true, mouse: true, right: 0, - label: { text: txt, side: 'left' }, + top: 2, + //label: { text: txt, side: 'left' }, width: '80%', hidden: true, - height: data.screen.height - data.cmdline.height, + height: data.screen.height - data.cmdline.height - 2, border: { type: 'line' }, scrollable: true, autoscroll: true, @@ -133,9 +144,16 @@ module.exports = function(data){ }, style: data.getDefaultStyle() }) + b.on('focus',function(){ + data.statusBarStyle.border.fg = b.style.focus.border.fg + data.screen.render() + }) + b.on('blur',function(){ + data.statusBarStyle.border.fg = b.style.border.fg + }) var obj = data.nameToObj(txt) - if(obj && obj.id) - b.setLabel(data.getName(obj.id,obj.title?'group':'user','label')) + /*if(obj && obj.id) + b.setLabel(data.getName(obj.id,obj.title?'group':'user','label'))*/ b.data.downloadedHistoryTimes = 0 b.key('enter',function(){ this.setScrollPerc(100) @@ -152,6 +170,22 @@ module.exports = function(data){ return b } + data.statusBarStyle = data.getDefaultStyle() + data.statusBarStyle.border.fg = 'white' + data.statusBar = blessed.box({ + tags: true, + input: false, + keyable: false, + keys: false, + border: { type: 'line' }, + height: 3, + right: 0, + top: 0, + width: '80%', + style: data.statusBarStyle + }) + data.screen.append(data.statusBar) + data.getDefaultPopupStyle = function(){ return { width: '30%', diff --git a/lib/util.js b/lib/util.js index f32c892..35a583a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -155,7 +155,7 @@ module.exports = function(data){ if(online_expires) if(moment().isBefore(online_expires)) name = name + '{|}{green-fg}Online{/green-fg}' - else name = name + '{|}Last Seen: '+moment(online_expires).fromNow() + else name = name + '{|}Last Seen {grey-fg}'+moment(online_expires).fromNow()+'{/grey-fg}' } else if(f === 'label'){ name = 'to ' + name } diff --git a/telecommander.js b/telecommander.js index 93a10ad..639b935 100755 --- a/telecommander.js +++ b/telecommander.js @@ -217,6 +217,7 @@ data.downloadUpdates = function(){ for(c in res.other_updates.list) data.onUpdate(res.other_updates.list[c]) } data.rebuildChatList() + data.refreshStatusBar() } setTimeout(data.downloadUpdates,1000) })