catox
Version:
A customizable, lightweight, minimalistic, text-based UI for single user chat that runs on top of ratox.
91 lines (90 loc) • 2 kB
JavaScript
// Generated by LiveScript 1.2.0
var fs, blessed, moment, ratox, screen, log, line, textbox, doLog, init;
fs = require('fs');
blessed = require('blessed');
moment = require('moment');
ratox = require('./ratox.js');
screen = blessed.screen();
log = blessed.box({
parent: screen,
scrollable: true,
alwaysScroll: true,
vi: true,
top: 0,
bottom: 2,
tags: true
});
line = blessed.line({
parent: screen,
orientation: 'horizontal',
bottom: 1
});
textbox = blessed.textbox({
parent: screen,
keys: false,
height: 1,
bottom: 0,
style: {
fg: 'white'
}
});
doLog = function(it){
log.pushLine(it);
log.setScrollPerc(100);
screen.render();
};
screen.append(log);
screen.append(line);
screen.append(textbox);
screen.key(['q', 'C-c'], function(){
process.exit();
});
screen.key('j', function(){
log.scroll(10);
screen.render();
});
screen.key('k', function(){
log.scroll(-10);
screen.render();
});
screen.key('S-j', function(){
log.scroll(1);
screen.render();
});
screen.key('S-k', function(){
log.scroll(-1);
screen.render();
});
textbox.on('submit', function(it){
textbox.clearValue();
textbox.readInput(function(){});
doLog("\x1b[1;30m" + moment().format('H:mm') + " {green-fg}{bold}" + ratox.nameOwn + ":{/} " + it);
ratox.textOut(it);
});
init = function(){
ratox.textIn(function(it){
it = (it + "").trim().slice(17);
doLog("\x1b[1;30m" + moment().format('H:mm') + " {green-fg}{bold}" + ratox.nameFriend + ":{/} " + it);
process.stdout.write('\x07');
});
screen.key('i', function(){
textbox.readInput(function(){});
});
screen.key('e', function(){
textbox.readEditor(function(){});
});
textbox.readInput(function(){});
};
fs.readFile(__dirname + '/init.txt', function(err, data){
var ratoxDir;
if (!err) {
doLog(data + "");
}
ratoxDir = process.cwd();
if (process.argv.length > 2) {
ratoxDir = process.argv[2];
}
ratox.init(ratoxDir, doLog, init);
});
screen.render();