简体   繁体   中英

How to integrate node module vorpal and blessed

I want to integrate node module blessed and vorpal, Can anyone give me some tips about how to integrate this two module, Thank U very much!

Below is my draft code (as reference only), My goal is the left part of terminal used for vorpal interactive CLI, and the top-right part used for log output.

var blessed = require('blessed')
    , screen;
var vorpal = require('vorpal')();

vorpal
    .command('foo', 'bar')
    .action(function(args, callback) {
        this.log('bar');
        callback();
    });

vorpal
    .delimiter('testapp$')
    .show();

screen = blessed.screen({
    dump: __dirname + '/logs/logger.log',
    smartCSR: true,
    autoPadding: false,
    warnings: true
});

//This area I want the vorpal interactive CLI
var leftPart = blessed.box({
    parent: screen,
    left: 0,
    top: 0,
    width: '50%',
    height: '100%',
    border: {
        type: 'line',
        left: false,
        top: false,
        right: true,
        bottom: false
    },
    // border: 'line',

    content: 'I want here is the normal terminal input/output with vorpal style\n'+
             'How can I do this?'
    //content:vorpal
});

//This area with be the log output area
var logger = blessed.log({
    parent: screen,
    top: '0',
    left: '50%-1',
    width: '50%-1',
    height: '50%-1',
    border: 'line',
    tags: true,
    keys: true,
    vi: true,
    mouse: true,
    scrollback: 100,
    scrollbar: {
        ch: ' ',
        track: {
            bg: 'yellow'
        },
        style: {
            inverse: true
        }
    }
});

leftPart.focus();


setInterval(function() {
    logger.log('Hello {#0fe1ab-fg}world{/}: {bold}%s{/bold}.', Date.now().toString(36));

    //screen.render();
}, 1000).unref();

screen.key('q', function() {
    return screen.destroy();
});

screen.render();

I don't think that this has been tried before, so it's sort of uncharted territory!

I do think you'll be able to use blessed components with Vorpal, however I'm not so sure you're going to be able to stuff the Vorpal prompt into a blessed box wrapper. Vorpal is based on Inquirer.js and his logic is very engineered in relation to the prompt being where it is.

Perhaps you put the log box on the top of the screen and keep the Vorpal prompt where it is.

Play around with this and see if it works - and feel free to ask more questions as you go along!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM