mirror of
https://github.com/fazo96/telecommander.git
synced 2025-01-10 11:34:20 +01:00
rewrote chatbox to support manual scrolling and custom behavior
This commit is contained in:
parent
99c302ac35
commit
94337fa3ef
47
lib/ui.js
47
lib/ui.js
@ -1,4 +1,5 @@
|
|||||||
var blessed = require('blessed')
|
var blessed = require('blessed')
|
||||||
|
var ChatBox = require('./ui-widgets/chatbox.js')
|
||||||
|
|
||||||
module.exports = function(data){
|
module.exports = function(data){
|
||||||
data.statusWindow = "Status"
|
data.statusWindow = "Status"
|
||||||
@ -45,18 +46,16 @@ module.exports = function(data){
|
|||||||
fg: 'white',
|
fg: 'white',
|
||||||
border: { fg: 'grey' },
|
border: { fg: 'grey' },
|
||||||
focus: {
|
focus: {
|
||||||
border: { fg: 'white' }
|
border: { fg: 'white' },
|
||||||
|
scrollbar: {
|
||||||
|
fg: 'white',
|
||||||
|
bg: 'white'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
selected: { bold: true },
|
selected: { bold: true },
|
||||||
scrollbar: {
|
scrollbar: {
|
||||||
style: {
|
fg: 'white', bg: 'white',
|
||||||
ch: '#',
|
track: { fg: 'grey', bg: 'grey' }
|
||||||
fg: 'white'
|
|
||||||
},
|
|
||||||
track : {
|
|
||||||
ch: '|',
|
|
||||||
fg: 'grey'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,14 +70,24 @@ module.exports = function(data){
|
|||||||
width: '20%',
|
width: '20%',
|
||||||
border: { type: 'line' },
|
border: { type: 'line' },
|
||||||
mouse: true,
|
mouse: true,
|
||||||
invertSelected: true,
|
/*
|
||||||
|
scrollbar: {
|
||||||
|
ch: ' ',
|
||||||
|
track : {
|
||||||
|
ch: ' '
|
||||||
|
}
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
scrollbar: false, // disabled cause can't change track style when focused
|
||||||
|
invertSelected: false,
|
||||||
style: data.getDefaultStyle(),
|
style: data.getDefaultStyle(),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Function to create a log box
|
// Function to create a log box
|
||||||
data.mkBox = function(label){
|
data.mkBox = function(label){
|
||||||
return blessed.log({
|
var b = ChatBox({
|
||||||
keys: true,
|
keys: true,
|
||||||
|
mouse: true,
|
||||||
right: 0,
|
right: 0,
|
||||||
label: label,
|
label: label,
|
||||||
width: '80%',
|
width: '80%',
|
||||||
@ -86,9 +95,20 @@ module.exports = function(data){
|
|||||||
height: data.screen.height - data.cmdline.height,
|
height: data.screen.height - data.cmdline.height,
|
||||||
border: { type: 'line' },
|
border: { type: 'line' },
|
||||||
scrollable: true,
|
scrollable: true,
|
||||||
//draggable: true,
|
autoscroll: true,
|
||||||
|
scrollbar: {
|
||||||
|
ch: ' ',
|
||||||
|
fg: 'white',
|
||||||
|
track: {
|
||||||
|
ch: ' ', fg: 'grey', bg: 'grey'
|
||||||
|
}
|
||||||
|
},
|
||||||
style: data.getDefaultStyle()
|
style: data.getDefaultStyle()
|
||||||
})
|
})
|
||||||
|
b.key('enter',function(){
|
||||||
|
data.cmdline.focus()
|
||||||
|
})
|
||||||
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command line prompt
|
// Command line prompt
|
||||||
@ -219,7 +239,7 @@ module.exports = function(data){
|
|||||||
|
|
||||||
// What happens when the user submits a command in the prompt
|
// What happens when the user submits a command in the prompt
|
||||||
data.cmdline.on('submit',function(value){
|
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){
|
if(data.selectedWindow === data.statusWindow || data.nameToObj(data.selectedWindow) === undefined){
|
||||||
//log('Window:',selectedWindow,'Eval cmd:',value)
|
//log('Window:',selectedWindow,'Eval cmd:',value)
|
||||||
data.command(value)
|
data.command(value)
|
||||||
@ -232,7 +252,6 @@ module.exports = function(data){
|
|||||||
}
|
}
|
||||||
data.cmdline.clearValue()
|
data.cmdline.clearValue()
|
||||||
data.cmdline.focus()
|
data.cmdline.focus()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,7 @@ data.whenReady = function(){
|
|||||||
data.log('Connected')
|
data.log('Connected')
|
||||||
data.connected = true
|
data.connected = true
|
||||||
data.downloadData()
|
data.downloadData()
|
||||||
|
data.chats.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloads stuff
|
// Downloads stuff
|
||||||
@ -216,7 +217,7 @@ data.getMessages = function(name,box){
|
|||||||
var peer = data.idToPeer(obj.id,type)
|
var peer = data.idToPeer(obj.id,type)
|
||||||
box.add('Downloading message history for '+name)
|
box.add('Downloading message history for '+name)
|
||||||
if(!peer) return log('Could not find peer:',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(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){
|
||||||
|
Loading…
Reference in New Issue
Block a user