From 94337fa3ef3f6eb0417a0f4877b3ef20c576be66 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 31 Aug 2015 16:53:38 +0200 Subject: [PATCH] rewrote chatbox to support manual scrolling and custom behavior --- lib/ui.js | 47 +++++++++++++++++++++++++++++++++-------------- telecommander.js | 3 ++- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/ui.js b/lib/ui.js index dba353f..b8ee1fb 100644 --- a/lib/ui.js +++ b/lib/ui.js @@ -1,4 +1,5 @@ var blessed = require('blessed') +var ChatBox = require('./ui-widgets/chatbox.js') module.exports = function(data){ data.statusWindow = "Status" @@ -45,18 +46,16 @@ module.exports = function(data){ fg: 'white', border: { fg: 'grey' }, focus: { - border: { fg: 'white' } + border: { fg: 'white' }, + scrollbar: { + fg: 'white', + bg: 'white' + } }, selected: { bold: true }, scrollbar: { - style: { - ch: '#', - fg: 'white' - }, - track : { - ch: '|', - fg: 'grey' - } + fg: 'white', bg: 'white', + track: { fg: 'grey', bg: 'grey' } } } } @@ -71,14 +70,24 @@ module.exports = function(data){ width: '20%', border: { type: 'line' }, mouse: true, - invertSelected: true, + /* + scrollbar: { + ch: ' ', + track : { + ch: ' ' + } + }, + */ + scrollbar: false, // disabled cause can't change track style when focused + invertSelected: false, style: data.getDefaultStyle(), }) // Function to create a log box data.mkBox = function(label){ - return blessed.log({ + var b = ChatBox({ keys: true, + mouse: true, right: 0, label: label, width: '80%', @@ -86,9 +95,20 @@ module.exports = function(data){ height: data.screen.height - data.cmdline.height, border: { type: 'line' }, scrollable: true, - //draggable: true, + autoscroll: true, + scrollbar: { + ch: ' ', + fg: 'white', + track: { + ch: ' ', fg: 'grey', bg: 'grey' + } + }, style: data.getDefaultStyle() }) + b.key('enter',function(){ + data.cmdline.focus() + }) + return b } // Command line prompt @@ -219,7 +239,7 @@ module.exports = function(data){ // What happens when the user submits a command in the prompt data.cmdline.on('submit',function(value){ - data.getMsgBox(data.statusWindow).add('< '+value) + data.getMsgBox(data.statusWindow).pushLine('< '+value) if(data.selectedWindow === data.statusWindow || data.nameToObj(data.selectedWindow) === undefined){ //log('Window:',selectedWindow,'Eval cmd:',value) data.command(value) @@ -232,7 +252,6 @@ module.exports = function(data){ } data.cmdline.clearValue() data.cmdline.focus() - }) } diff --git a/telecommander.js b/telecommander.js index 0a5333d..2440ff5 100755 --- a/telecommander.js +++ b/telecommander.js @@ -155,6 +155,7 @@ data.whenReady = function(){ data.log('Connected') data.connected = true data.downloadData() + data.chats.focus() } // Downloads stuff @@ -216,7 +217,7 @@ data.getMessages = function(name,box){ var peer = data.idToPeer(obj.id,type) box.add('Downloading message history for '+name) if(!peer) return log('Could not find peer:',name) - data.client.messages.getHistory(peer,0,-1,20,function(res){ + data.client.messages.getHistory(peer,0,-1,100,function(res){ //log(res.toPrintable()) //log('Got history for: '+getName(peer.user_id||peer.chat_id,peer.chat_id?'group':'user')) if(!res.messages){