我正在尝试制作一个简单的列表框。
var blessed = require("blessed");
// Create a screen object.
var screen = blessed.screen();
// Create a box perfectly centered horizontally and vertically.
var serverList = blessed.list({
align: "center",
mouse: true,
width: "50%",
height: "50%",
top: "center",
left: "center",
items: [
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten"
]
});
// Append our box to the screen.
screen.append(serverList);
serverList.select(0);
// Quit on Escape, q, or Control-C.
screen.key(["escape", "q", "C-c"], function(ch, key) {
return process.exit(0);
});
// Focus our element.
serverList.focus();
// Render the screen.
screen.render();
根据文档和chjj/blessed/test/widget.js
应该是我所需要的全部内容。但它只是错误地说它无法读取高度。这是错误。
TypeError: Cannot read property 'height' of null
at ScrollableBox.Element._getTop (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:2595:17)
at ScrollableBox.Element._getBottom.parent [as top] (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:2617:15)
at Box.Element._getTop (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:2613:17)
at Box.Element._getBottom.parent [as top] (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:2617:15)
at Screen._focus (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:1439:19)
at Screen.focusPush (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:1389:8)
at Screen.clearRegion [as focused] (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:1467:15)
at ScrollableBox.Node.insert (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:86:25)
at ScrollableBox.Node.append (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:95:8)
at ScrollableBox.List.add.List.addItem.List.appendItem (/home/giodamelio/Projects/real/Vindinium-Bots/node_modules/blessed/lib/widget.js:4262:8)
答案 0 :(得分:3)
它看起来像blessed
中的错误。如果您在parent: screen
选项中手动指定blessed.list()
,则会有效。由于某种原因,它不会自动确定父母。
您链接到工作的测试的原因是因为首先在屏幕上添加了其他小部件,这意味着该列表肯定会设置parent
(对于之前添加的小部件)。