简体   繁体   English

如何使用blessed / nodejs创建可滚动框

[英]How to create a scrollable box with blessed/nodejs

I cannot figure out, how to create a scrollable box with blessed. 我无法弄清楚,如何创建一个有福的可滚动框。

https://github.com/chjj/blessed https://github.com/chjj/blessed

According to the docs, it should be like this: 根据文档,它应该是这样的:

"use strict";

const blessed = require('blessed');

const screen = blessed.screen({
    smartCSR: true
});

let box = blessed.box({
    top: 0,
    left: 0,
    width: '80%',
    height: '80%',
    style: {
        bg: 'red'
    },
    alwaysScroll:true,
    scrollable: true,
    scrollbar: true
});

screen.append(box);
screen.render();

for (let i = 0; i < 200; i++) {
    box.insertLine(0, 'texting ' + i);
    box.screen.render();
}

The box window shows, it gets filled, but no scrollbar. 框窗口显示,它被填充,但没有滚动条。 What am i missing? 我错过了什么?

Your code is correct but you need a bit more configuration to make it work. 您的代码是正确的,但您需要更多配置才能使其正常工作。 I added keys and vi properties to your box and defined a style for your scrollbar. 我在您的框中添加了keysvi属性,并为滚动条定义了一种style With the following code, you should be able to scroll using arrow keys or Vi-like key mappings ( j to go down, k to go up, g to jump to the first line, G to jump to the last line). 使用以下代码,您应该能够使用箭头键或类似Vi的键映射滚动( j向下, k向上, g向跳到第一行, G向跳到最后一行)。

"use strict";

const blessed = require('blessed');

const screen = blessed.screen({
    smartCSR: true
});

let box = blessed.box({
    parent: screen,
    top: 0,
    left: 0,
    width: '80%',
    height: '80%',
    style: {
        bg: 'red'
    },
    keys: true,
    vi: true,
    alwaysScroll:true,
    scrollable: true,
    scrollbar: {
      style: {
        bg: 'yellow'
      }
    }
});

screen.render();

for (let i = 0; i < 200; i++) {
    box.insertLine(0, 'texting ' + i);
    box.screen.render();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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