blessed-contrib icon indicating copy to clipboard operation
blessed-contrib copied to clipboard

No Active Screen Error

Open sarcasticHippo opened this issue 10 years ago • 3 comments

Hi, I am facing following error: Error: No active screen. at Node.screen (/home/training/node_modules/blessed/lib/widget.js:37:26) at Line.Node (/home/training/node_modules/blessed/lib/widget.js:37:58) at Line.Element (/home/training/node_modules/blessed/lib/widget.js:1712:8) at Line.Box (/home/training/node_modules/blessed/lib/widget.js:3602:11) at Line.Canvas (/home/training/node_modules/blessed-contrib/widget/canvas.js:16:7) at new Line (/home/training/node_modules/blessed-contrib/widget/charts/line-simple.js:22:10) at Object.Line as obj at Grid.applyLayout (/home/training/node_modules/blessed-contrib/layout/grid.js:53:60) at Grid.applyLayout (/home/training/node_modules/blessed-contrib/layout/grid.js:43:18) at Object. (/home/training/blessed-contrib/examples/dashboard.js:66:6)

when i tried the sample widgets while dashboard.js worked fine. Only difference i could find was that i was using require('blesseed-contrib') in place of ('../index') so when i changed that in dashboard.js, it returned the same error.

I have installed blessed and blessed-contrib.

sarcasticHippo avatar Jan 15 '15 15:01 sarcasticHippo

Hi, can you paste here the code you use?

yaronn avatar Jan 15 '15 18:01 yaronn

Its the same code as in current dashboard.js with only change in require (i.e. 2nd line) changed which is highlighted =>

var blessed = require('blessed')
 , contrib = require('blessed-contrib')

var screen = blessed.screen()

//create layout and widgets

var grid = new contrib.grid({rows: 1, cols: 2})

var grid1 = new contrib.grid({rows: 1, cols: 3}) grid1.set(0, 0, contrib.log, { fg: "green" , selectedFg: "green" , label: 'Server Log'}) grid1.set(0, 1, contrib.line, { style: { line: "yellow" , text: "green" , baseline: "black"} , xLabelPadding: 3 , xPadding: 5 , label: 'Network Latency (sec)'})

var grid2 = new contrib.grid({rows: 2, cols: 1}) grid2.set(0, 0, contrib.gauge, {label: 'Deployment Progress'}) grid2.set(1, 0, contrib.sparkline, { label: 'Throughput (bits/sec)' , tags: true , style: { fg: 'blue' }})

grid1.set(0, 2, grid2)

var grid3 = new contrib.grid({rows: 1, cols: 2}) grid3.set(0, 0, contrib.bar, { label: 'Server Utilization (%)' , barWidth: 4 , barSpacing: 6 , xOffset: 0 , maxHeight: 9}) grid3.set(0, 1, contrib.table, { keys: true , fg: 'green' , label: 'Active Processes' , columnSpacing: 16})

var grid4 = new contrib.grid({rows: 3, cols: 1}) grid4.set(0, 0, contrib.line, { style: { line: "red" , text: "white" , baseline: "black"} , label: 'Errors Rate' , maxY: 60}) grid4.set(1, 0, grid3) grid4.set(2, 0, grid1)

var grid5 = new contrib.grid({rows: 2, cols: 1}) grid5.set(0, 0, contrib.line, { showNthLabel: 5 , maxY: 100 , label: 'Total Transactions'}) grid5.set(1, 0, contrib.map, {label: 'Servers Location'}) grid.set(0, 0, grid5) grid.set(0, 1, grid4)

grid.applyLayout(screen)

var transactionsLine = grid5.get(0, 0) var errorsLine = grid4.get(0, 0) var latencyLine = grid1.get(0, 1) var map = grid5.get(1, 0) var log = grid1.get(0, 0) var table = grid3.get(0,1) var sparkline = grid2.get(1, 0) var gauge = grid2.get(0, 0) var bar = grid3.get(0, 0)

//dummy data var servers = ['US1', 'US2', 'EU1', 'AU1', 'AS1', 'JP1'] var commands = ['grep', 'node', 'java', 'timer', '~/ls -l', 'netns', 'watchdog', 'gulp', 'tar -xvf', 'awk', 'npm install']

//set dummy data on gauge var gauge_percent = 0 setInterval(function() { gauge.setPercent(gauge_percent++)
if (gauge_percent>100) gauge_percent = 0
}, 200)

//set dummy data on bar chart function fillBar() { var arr = [] for (var i=0; i<servers.length; i++) { arr.push(Math.round(Math.random()*10)) } bar.setData({titles: servers, data: arr}) } fillBar() setInterval(fillBar, 2000)

//set dummy data for table function generateTable() { var data = []

for (var i=0; i<30; i++) { var row = []
row.push(commands[Math.round(Math.random()_(commands.length-1))]) row.push(Math.round(Math.random()_5)) row.push(Math.round(Math.random()*100)) data.push(row) }

table.setData({headers: ['Process', 'Cpu (%)', 'Memory'], data: data}) }

generateTable() table.focus() setInterval(generateTable, 3000)

//set log dummy data setInterval(function() { var rnd = Math.round(Math.random()2) if (rnd==0) log.log('starting process ' + commands[Math.round(Math.random()(commands.length-1))])
else if (rnd==1) log.log('terminating server ' + servers[Math.round(Math.random()*(servers.length-1))]) else if (rnd==2) log.log('avg. wait time ' + Math.random().toFixed(2)) screen.render() }, 500)

//set spark dummy data var spark1 = [1,2,5,2,1,5,1,2,5,2,1,5,4,4,5,4,1,5,1,2,5,2,1,5,1,2,5,2,1,5,1,2,5,2,1,5] var spark2 = [4,4,5,4,1,5,1,2,5,2,1,5,4,4,5,4,1,5,1,2,5,2,1,5,1,2,5,2,1,5,1,2,5,2,1,5]

refreshSpark() setInterval(refreshSpark, 1000)

function refreshSpark() { spark1.shift() spark1.push(Math.random()_5+1)
spark2.shift() spark2.push(Math.random()_5+1)
sparkline.setData(['Server1', 'Server2'], [spark1, spark2])
}

//set map dummy markers var marker = true setInterval(function() { if (marker) { map.addMarker({"lon" : "37.5000", "lat" : "-79.0000" }) map.addMarker({"lon" : "45.5200", "lat" : "-122.6819" }) map.addMarker({"lon" : "53.3478", "lat" : "-6.2597" }) map.addMarker({"lon" : "1.3000", "lat" : "103.8000" }) } else { map.clearMarkers() } marker =! marker screen.render() }, 1000)

//set line charts dummy data

var transactionsData = { x: ['00:00', '00:05', '00:10', '00:15', '00:20', '00:30', '00:40', '00:50', '01:00', '01:10', '01:20', '01:30', '01:40', '01:50', '02:00', '02:10', '02:20', '02:30', '02:40', '02:50', '03:00', '03:10', '03:20', '03:30', '03:40', '03:50', '04:00', '04:10', '04:20', '04:30'], y: [0, 10, 40, 45, 45, 50, 55, 70, 65, 58, 50, 55, 60, 65, 70, 80, 70, 50, 40, 50, 60, 70, 82, 88, 89, 89, 89, 80, 72, 70] }

var errorsData = { x: ['00:00', '00:05', '00:10', '00:15', '00:20', '00:25'], y: [30, 50, 70, 40, 50, 20] }

var latencyData = { x: ['t1', 't2', 't3', 't4'], y: [5, 1, 7, 5] }

setLineData(transactionsData, transactionsLine) setLineData(errorsData, errorsLine) setLineData(latencyData, latencyLine)

setInterval(function() { setLineData(transactionsData, transactionsLine) screen.render() }, 500)

setInterval(function() {
setLineData(errorsData, errorsLine) screen.render() }, 1500)

setInterval(function() {
setLineData(latencyData, latencyLine) screen.render() }, 5000)

function setLineData(mockData, line) { var last = mockData.y[mockData.y.length-1] mockData.y.shift() var num = Math.max(last + Math.round(Math.random()*10) - 5, 10)
mockData.y.push(num)
line.setData(mockData.x, mockData.y) }

screen.key(['escape', 'q', 'C-c'], function(ch, key) { return process.exit(0); });

screen.render()

sarcasticHippo avatar Jan 16 '15 15:01 sarcasticHippo

I have just done the following succesfully:

  1. create a new folder
  2. npm init
  3. npm install blessed blessed-contrib
  4. copy dashboard.cs to the folder root and change the reference as you did
  5. running the dashboard

can you try again with this exact flow?

yaronn avatar Jan 16 '15 17:01 yaronn