blessed icon indicating copy to clipboard operation
blessed copied to clipboard

When adding a callback to screen.on 'resize' the parents of the instances are null

Open binarymist opened this issue 5 years ago • 0 comments

An example:

    screen.on('resize', function () {
      loggers.forEach(logger => logger.instance.emit('attach'));
      // workaround: assign this (screen)
      // testerPctComplete is a contrib.donut
      testerPctComplete.instance.parent = this;
      testerPctComplete.instance.emit('attach');
      statTable.instance.emit('attach');
      // Next line (newBugs is a contrib.lcd) causes the lcd to completly dissapear
      //newBugs.instance.emit('attach');
      // totalProgress is a contrib.gauge
      // workaround: assign this (screen)
      totalProgress.instance.parent = this;
      totalProgress.instance.emit('attach');
    });

this exhibits itself in blessed/lib/widgets/element at:

https://github.com/chjj/blessed/blob/eab243fc7ad27f1d2932db6134f7382825ee3488/lib/widgets/element.js#L1060

For example, without the contrib.gauge assignment of screen to it's parent, we get the following:

TypeError: Cannot read property 'width' of null at Gauge.Element._getWidth (node_modules/blessed/lib/widgets/element.js:1060:20) at Gauge.width (node_modules/blessed/lib/widgets/element.js:1095:15) at Gauge.calcSize (node_modules/blessed-contrib/lib/widget/gauge.js:36:36) at Gauge. (node_modules/blessed-contrib/lib/widget/canvas.js:19:10) at Gauge.EventEmitter._emit (node_modules/blessed/lib/events.js:98:20) at Gauge.EventEmitter.emit (node_modules/blessed/lib/events.js:117:12) at Screen. (src/view/dashboard.js:468:30) at Screen.EventEmitter._emit (node_modules/blessed/lib/events.js:98:20) at Screen.EventEmitter.emit (node_modules/blessed/lib/events.js:114:17) at emit (node_modules/blessed/lib/widgets/screen.js:148:10)

the line src/view/dashboard.js:468:30 is the totalProgress.instance.emit('attach'); line.

binarymist avatar Aug 04 '18 04:08 binarymist