Code Monkey home page Code Monkey logo

blessed-contrib's Introduction

blessed-contrib

Build dashboards (or any other application) using ascii/ansi art and javascript.

Friendly to terminals, ssh and developers. Extends blessed with custom drawille and other widgets.

You should also check WOPR: a markup for creating terminal reports, presentations and infographics.

Contributors:

Yaron Naveh (@YaronNaveh) Chris (@xcezzz) Miguel Valadas (@mvaladas) Liran Tal (@lirantal)

Demo (full size):

term

term

(source code)

Running the demo

git clone https://github.com/yaronn/blessed-contrib.git
cd blessed-contrib
npm install
node ./examples/dashboard.js

Works on Linux, OS X and Windows. For Windows follow the pre requisites.

Installation (to build custom projects)

npm install blessed blessed-contrib

Usage

You can use any of the default widgets of blessed (texts, lists and etc) or the widgets added in blessed-contrib (described below). A layout is optional but useful for dashboards. The widgets in blessed-contrib follow the same usage pattern:

   var blessed = require('blessed')
     , contrib = require('blessed-contrib')
     , screen = blessed.screen()
     , line = contrib.line(
         { style:
           { line: "yellow"
           , text: "green"
           , baseline: "black"}
         , xLabelPadding: 3
         , xPadding: 5
         , label: 'Title'})
     , data = {
         x: ['t1', 't2', 't3', 't4'],
         y: [5, 1, 7, 5]
      }
   screen.append(line) //must append before setting data
   line.setData([data])

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

   screen.render()

See below for a complete list of widgets.

Widgets

Line Chart

Bar Chart

Stacked Bar Chart

Map

Gauge

Stacked Gauge

Donut

LCD Display

Rolling Log

Picture

Sparkline

Table

Tree

Markdown

Line Chart

line

   var line = contrib.line(
         { style:
           { line: "yellow"
           , text: "green"
           , baseline: "black"}
         , xLabelPadding: 3
         , xPadding: 5
         , showLegend: true
         , wholeNumbersOnly: false //true=do not show fraction in y axis
         , label: 'Title'})
   var series1 = {
         title: 'apples',
         x: ['t1', 't2', 't3', 't4'],
         y: [5, 1, 7, 5]
      }
   var series2 = {
         title: 'oranges',
         x: ['t1', 't2', 't3', 't4'],
         y: [2, 1, 4, 8]
      }
   screen.append(line) //must append before setting data
   line.setData([series1, series2])

Examples: simple line chart, multiple lines, 256 colors

Bar Chart

bar

    var bar = contrib.bar(
       { label: 'Server Utilization (%)'
       , barWidth: 4
       , barSpacing: 6
       , xOffset: 0
       , maxHeight: 9})
    screen.append(bar) //must append before setting data
    bar.setData(
       { titles: ['bar1', 'bar2']
       , data: [5, 10]})

Stacked Bar Chart

stacked-bar

    bar = contrib.stackedBar(
       { label: 'Server Utilization (%)'
       , barWidth: 4
       , barSpacing: 6
       , xOffset: 0
       //, maxValue: 15
       , height: "40%"
       , width: "50%"
       , barBgColor: [ 'red', 'blue', 'green' ]})
    screen.append(bar)
    bar.setData(
       { barCategory: ['Q1', 'Q2', 'Q3', 'Q4']
       , stackedCategory: ['US', 'EU', 'AP']
       , data:
          [ [ 7, 7, 5]
          , [8, 2, 0]
          , [0, 0, 0]
          , [2, 3, 2] ]
       })

Map

map

   var map = contrib.map({label: 'World Map'})
   map.addMarker({"lon" : "-79.0000", "lat" : "37.5000", color: "red", char: "X" })

Gauge

gauge

   var gauge = contrib.gauge({label: 'Progress', stroke: 'green', fill: 'white'})
   gauge.setPercent(25)

Stacked Gauge

stackedgauge

Either specify each stacked portion with a percent and stroke...

   var gauge = contrib.gauge({label: 'Stacked '})
   gauge.setStack([{percent: 30, stroke: 'green'}, {percent: 30, stroke: 'magenta'}, {percent: 40, stroke: 'cyan'}])

Or, you can just supply an array of numbers and random colors will be chosen.

   var gauge = contrib.gauge({label: 'Stacked Progress'})
   gauge.setStack([30,30,40])

Donut

donut

   var donut = contrib.donut({
	label: 'Test',
	radius: 8,
	arcWidth: 3,
	remainColor: 'black',
	yPadding: 2,
	data: [
	  {percent: 80, label: 'web1', color: 'green'}
	]
  });

Data passed in uses percent and label to draw the donut graph. Color is optional and defaults to green.

   donut.setData([
   	{percent: 87, label: 'rcp','color': 'green'},
	{percent: 43, label: 'rcp','color': 'cyan'},
   ]);

Updating the donut is as easy as passing in an array to setData using the same array format as in the constructor. Pass in as many objects to the array of data as you want, they will automatically resize and try to fit. However, please note that you will still be restricted to actual screen space.

You can also hardcode a specific numeric into the donut's core display instead of the percentage by passing an percentAltNumber property to the data, such as:

   var donut = contrib.donut({
	label: 'Test',
	radius: 8,
	arcWidth: 3,
	remainColor: 'black',
	yPadding: 2,
	data: [
	  {percentAltNumber: 50, percent: 80, label: 'web1', color: 'green'}
	]
  });

See an example of this in one of the donuts settings on ./examples/donut.js.

LCD Display

lcd

   var lcd = contrib.lcd(
     { segmentWidth: 0.06 // how wide are the segments in % so 50% = 0.5
     , segmentInterval: 0.11 // spacing between the segments in % so 50% = 0.550% = 0.5
     , strokeWidth: 0.11 // spacing between the segments in % so 50% = 0.5
     , elements: 4 // how many elements in the display. or how many characters can be displayed.
     , display: 321 // what should be displayed before first call to setDisplay
     , elementSpacing: 4 // spacing between each element
     , elementPadding: 2 // how far away from the edges to put the elements
     , color: 'white' // color for the segments
     , label: 'Storage Remaining'})
	lcd.setDisplay(23 + 'G'); // will display "23G"
	lcd.setOptions({}) // adjust options at runtime

Please see the examples/lcd.js for an example. The example provides keybindings to adjust the segmentWidth and segmentInterval and strokeWidth in real-time so that you can see how they manipulate the look and feel.

Rolling Log

log

   var log = contrib.log(
      { fg: "green"
      , selectedFg: "green"
      , label: 'Server Log'})
   log.log("new log line")

Picture

(Also check the new blessed image implementation which has several benefits over this one.)

log

    var pic = contrib.picture(
       { file: './flower.png'
       , cols: 25
       , onReady: ready})
    function ready() {screen.render()}

note: only png images are supported

Sparkline

spark

   var spark = contrib.sparkline(
     { label: 'Throughput (bits/sec)'
     , tags: true
     , style: { fg: 'blue' }})

   sparkline.setData(
   [ 'Sparkline1', 'Sparkline2'],
   [ [10, 20, 30, 20]
   , [40, 10, 40, 50]])

Table

table

   var table = contrib.table(
     { keys: true
     , fg: 'white'
     , selectedFg: 'white'
     , selectedBg: 'blue'
     , interactive: true
     , label: 'Active Processes'
     , width: '30%'
     , height: '30%'
     , border: {type: "line", fg: "cyan"}
     , columnSpacing: 10 //in chars
     , columnWidth: [16, 12, 12] /*in chars*/ })

   //allow control the table with the keyboard
   table.focus()

   table.setData(
   { headers: ['col1', 'col2', 'col3']
   , data:
      [ [1, 2, 3]
      , [4, 5, 6] ]})

Tree

table

   var tree = contrib.tree({fg: 'green'})

   //allow control the table with the keyboard
   tree.focus()

   tree.on('select',function(node){
     if (node.myCustomProperty){
       console.log(node.myCustomProperty);
     }
     console.log(node.name);
   }

   // you can specify a name property at root level to display root
   tree.setData(
   { extended: true
   , children:
     {
       'Fruit':
       { children:
         { 'Banana': {}
         , 'Apple': {}
         , 'Cherry': {}
         , 'Exotics': {
             children:
             { 'Mango': {}
             , 'Papaya': {}
             , 'Kiwi': { name: 'Kiwi (not the bird!)', myCustomProperty: "hairy fruit" }
             }}
         , 'Pear': {}}}
     , 'Vegetables':
       { children:
         { 'Peas': {}
         , 'Lettuce': {}
         , 'Pepper': {}}}}})

Options

  • keys : Key to expand nodes. Default : ['enter','default']
  • extended : Should nodes be extended/generated by default? Be careful with this setting when using a callback function. Default : false
  • template :
    • extend : Suffix "icon" for closed node. Default : '[+]'
    • retract : Suffix "icon" for opened node. Default : '[-]'
    • lines : Show lines in tree. Default : true

Nodes

Every node is a hash and it can have custom properties that can be used in "select" event callback. However, there are several special keys :

  • name
    • Type : string
    • Desc : Node name
    • If the node isn't the root and you don't specify the name, will be set to hash key
    • Example : { name: 'Fruit'}
  • children
    • Type : hash or function(node){ return children }
    • Desc : Node children.
    • The function must return a hash that could have been used as children property
    • If you use a function, the result will be stored in node.childrenContent and children
    • Example :
      • Hash : {'Fruit':{ name: 'Fruit', children:{ 'Banana': {}, 'Cherry': {}}}}
      • Function : see examples/explorer.js
  • childrenContent
    • Type : hash
    • Desc : Children content for internal usage DO NOT MODIFY
    • If node.children is a hash, node.children===node.childrenContent
    • If node.children is a function, it's used to store the node.children() result
    • You can read this property, but you should never write it.
    • Usually this will be used to check if(node.childrenContent) in your node.children function to generate children only once
  • extended
    • Type : boolean
    • Desc : Determine if this node is extended
    • No effect when the node have no child
    • Default value for each node will be treeInstance.options.extended if the node extended option is not set
    • Example : {'Fruit':{ name: 'Fruit', extended: true, children:{ 'Banana': {}, 'Cherry': {}}}}

Markdown

table

   var markdown = contrib.markdown()
   markdown.setMarkdown('# Hello \n blessed-contrib renders markdown using `marked-terminal`')

Colors

You can use 256 colors (source):

  function randomColor() {
    return [Math.random() * 255,Math.random()*255, Math.random()*255]
  }

  line = contrib.line(
  {
    ...
    , style: { line: randomColor(), text: randomColor(), baseline: randomColor() }
  })

Layouts

Grid

Carousel

Grid

A grid layout can auto position your elements in a grid layout. When using a grid, you should not create the widgets, rather specify to the grid which widget to create and with which params. Each widget can span multiple rows and columns.

   var screen = blessed.screen()

   var grid = new contrib.grid({rows: 12, cols: 12, screen: screen})

   //grid.set(row, col, rowSpan, colSpan, obj, opts)
   var map = grid.set(0, 0, 4, 4, contrib.map, {label: 'World Map'})
   var box = grid.set(4, 4, 4, 4, blessed.box, {content: 'My Box'})

   screen.render()

Carousel

A carousel layout switches between different views based on time or keyboard activity. One use case is an office dashboard with rotating views:

    var blessed = require('blessed')
      , contrib = require('./')
      , screen = blessed.screen()

    function page1(screen) {
       var map = contrib.map()
       screen.append(map)
    }

    function page2(screen) {
      var line = contrib.line(
       { width: 80
       , height: 30
       , left: 15
       , top: 12
       , xPadding: 5
       , label: 'Title'
       })

      var data = [ { title: 'us-east',
                 x: ['t1', 't2', 't3', 't4'],
                 y: [0, 0.0695652173913043, 0.11304347826087, 2],
                 style: {
                  line: 'red'
                 }
               }
            ]

      screen.append(line)
      line.setData(data)
    }

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

    var carousel = new contrib.carousel( [page1, page2]
                                       , { screen: screen
                                         , interval: 3000 //how often to switch views (set 0 to never swicth automatically)
                                         , controlKeys: true  //should right and left keyboard arrows control view rotation
                                         })
    carousel.start()

Samples

Terminal Dashboard

term

Running the sample

git clone https://github.com/yaronn/blessed-contrib.git
cd blessed-contrib
npm install
node ./examples/dashboard.js

Installation (for a custom dashboard)

npm install blessed
npm install blessed-contrib

A simple dashboard

   var blessed = require('blessed')
     , contrib = require('blessed-contrib')
     , screen = blessed.screen()
     , grid = new contrib.grid({rows: 1, cols: 2, screen: screen})

   var line = grid.set(0, 0, 1, 1, contrib.line,
     { style:
       { line: "yellow"
       , text: "green"
       , baseline: "black"}
     , xLabelPadding: 3
     , xPadding: 5
     , label: 'Stocks'})

   var map = grid.set(0, 1, 1, 1, contrib.map, {label: 'Servers Location'})

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

   line.setData([lineData])

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

   screen.render()

Rich dashboard

See source code

Troubleshooting

If you see questions marks or some (or all) missign characters try running with these env vars to fix encoding / terminal:

    $> LANG=en_US.utf8 TERM=xterm-256color node your-code.js 

License

This library is under the MIT License

More Information

Created by Yaron Naveh (twitter, blog)

blessed-contrib's People

Contributors

aktowns avatar bendrucker avatar chinggg avatar chrisdew avatar crazyguitar avatar cwingrav avatar danielrussellla avatar hmil avatar huan avatar j-cat avatar jcarvalho avatar jdloft avatar jshen212 avatar larsonjj avatar lholznagel avatar lirantal avatar lucasbento avatar mamachanko avatar martinpallmann avatar mortonfox avatar mvaladas avatar nikhilm avatar notbobthebuilder avatar piranna avatar reconbot avatar resseguie avatar sayuki0x avatar thehandsomepanther avatar theredcat avatar yaronn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blessed-contrib's Issues

Support color and font tags in log?

I was hoping to color some lines based on content. Reading the blessed docs, it seems like I might be able to do something like "{red-fg}foo{/red-fg}", but this doesn't work. I guess I could just use terminal escape codes, but I'm not positive that those wouldn't have a negative impact somewhere.

Any ideas?

Allow to provide tree childrens asynchronously

It would be awesome if it would be possible to provide the data for contrib.tree in an async way. Maybe it would be possible to return a Promise in the function passed to the children key like:

{
  extended: true,
  name: 'root',
  children: () => {
     //return Promise() 
  }
}

or via a callback function like:

{
  extended: true,
  name: 'root',
  children: (self, done) => {
     asyncTask((err, data) => { done(data) }); 
  }
}

Line chart hangs when y-axis label increment evaluates to 0

The following causes a hang:

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

var screen = blessed.screen();

var line = contrib.line({
  style: {
    line: 'yellow',
    text: 'green',
    baseline: 'black'
  },
  xLabelPadding: 3,
  xPadding: 5,
  label: 'Title'
});

var data = {
  x: ['t1', 't2', 't3', 't4'],
  y: [1, 1, 1, 1]
};

screen.append(line);

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

line.setData(data.x, data.y);
screen.render();

It is caused by this line:

var yLabelIncrement = Math.round(getMaxY()/5)

where Math.round(getMaxY()/5) evaluates to 0. This causes an infinite loop in the following for loop:

// Draw the Y value texts
for(var i = 0; i < getMaxY(); i += yLabelIncrement) {    
  c.fillText(i.toString(), xPadding - xLabelPadding, getYPixel(i));    
}

Great project, BTW!

Support color tags in table?

Based on issue #42, I tried both the colors node module and the blessed tags to color the text in table cells. In both cases, cells to the right of the colored cell were misaligned
misaligned

Nothing happens when I run

Cloned the repo
sudo apt-get install npm
sudo apt-get install node
npm install
node ./examples/dashboard.js

and nothing happens

Running Ubuntu 14.04

Add option to remove borders on grid

The grid add a border on all the widgets. Add an option to remove them and only show the lines that separate the cells, it would get a little bit ugly but will allow to get some extra space on too crowd grids used on small screens. Ideally, it should detect complex configurations like the dashboard demo and use the three and four ends like graphics.

Widget border line drawing error

Hi,

I have just tried installing this but when I run the example I get an error where the lines around each widget are letters rather than lines.

Error Image

I am running OSX El Capitan and using the font Monaco.

Any ideas anyone?

grid.set purges function values from options

This line in lib/layout/grid.js removes keys from the options that have function values. As far as see from the history of the file, this was introduced in 9f73971, and was not present before.

This causes a few problems for me, because I have custom widgets built on top of blessed-contrib, that would really benefit from being able to specify callback functions in the widget options.

Would it make sense to replace the quoted line with var options = opts instead? Or to find a way to make this stringify->parse dance optional?

grid.set is ok.. but, how to hide any widgets?

Hello guys!

Thank you for this amazing project. I love it. I have a question for you.

I am working with a grid, and it is ok. But i need to change my widgets because i am using a dynamic json to draw the widgets. I mean, i need to draw "x" number of bar widgets from a REST-API. If that json is sending me 3 nodes, then I need to draw three bar-widgets with the data. If that REST-API sends me twelve nodes, then I need to draw twelve.

I can use grid.set to draw that widgets with a "for" or something similar but... if my new request has a number of nodes lower than before one then i need to hide the widgets painted in the screen (or something similar) because screen.render() doesn't clear the buffer with the painted widgets i had before.

So, is there any method to clear the screen buffer or to hide widgets in a grid?

Thx

Grid example does not run.

/examples/layout/grid.js does not run.

Line 7 is currently:

var grid = new contrib.Layout.Grid({rows: rows, cols: cols})

but I believe it should be this to match the other example

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

Error: Not a terminal

Hello, I'm running an AWS instance of Ubuntu Server accessed through Iterm, I followed the basic example on the front page and I get this error:

Error: Not a terminal.
at Program.listen (/var/nodejs/node_modules/blessed/lib/program.js:264:11)
at new Program (/var/nodejs/node_modules/blessed/lib/program.js:112:8)
at Program (/var/nodejs/node_modules/blessed/lib/program.js:30:12)
at new Screen (/var/nodejs/node_modules/blessed/lib/widget.js:259:20)
at Function.Screen (/var/nodejs/node_modules/blessed/lib/widget.js:248:12)
at Object. (/var/nodejs/myapp/app.js:10:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

What do you think could cause this issue?

No Active Screen Error

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.

TypeError: Cannot read property 'width' of null

Hi. When i try to create ListTable in grid, application crashing with that error.
ba0bxljc14r7my

var accountList = mainGrid.set(1, 16, 6, 9, blessed.ListTable, {
    label: "Loaded Acounts",
    keys: true,
    fg: "white",
    selectedFg: "white",
    selectedBg: "blue",
    interactive: true,
    border: {type: "line", fg: "cyan"},
    scrollable: true
});

accountList.setData({
    headers: ["Login", "Password"],
    data: [["asdasd", "asdasd"], ["asdd", "asda"]]
});

How fix that problem? Maybe i do something wrong?

readme typo

Nothing spectecular or big, but:

var donut = contrib.donut({
    label: 'Test',
    radius: 8,
    arcWidth: 3,
    spacing: 2,
    yPadding: 2,
    data: [
      {perent: 80, label: 'web1', color: 'green'}
    ]
  });

perent should probably be percent ;-)

Breaking changes in version 2.0.0

Major release 2.0.0 contains a few breaking changes. Depending on how you use blessed-contrib it may take you a few minutes to adjust your code. The changes come to make the API more coherent and to make it easy to build complex layouts.

Grid System
The main change is in the way the grid layout is used. Previously it had these two limitations:

  • creating complex layouts required nesting grids which was not intuative
  • creating grid elements and getting a reference to them was made in separate calls

Today, blessed-contrib is moving to a grid system where you specify how many cells are on the screen (e.g. 5X5=25) and for each widget you specify the left/top cells and the number of cells it spreads upon. For example:

var screen = blessed.screen()
var grid = new contrib.grid({rows: 12, cols: 12, screen: screen})
//grid.set(row, col, rowSpan, colSpan, obj, opts)
var map = grid.set(0, 0, 2, 2, contrib.map, {label: 'World Map'})
var box = grid.set(0, 6, 2, 2, blessed.box, {content: 'My Box'})
screen.render()

Here we define a 12X12 grid. We layout two elements (map, box). The map starts at cell (0,0) and spans 2 cells width and height. Note that we get the reference to the map object as the grid.set return value so no need to call grid.get. The new API requires much less code from users and allows to easily define complex layouts.

In addition, there was a confusion in the parameter order for grid.set. The rowSpan parameter was actually used as colSpan. From now this is the correct order:

grid.set(row, col, rowSpan, colSpan, obj, opts)

The dashboard is a canonical sample of this new style.

Multi Line Chart
This is not a breaking change. The line-chart widget now supports displaying multiple lines in the same chart. This means the input for line.setData is now an array of data series rather than just one. However if you specify just one (as in the previous API) it will be automatically converted to an array to keep compatibility.
The line chart now also support displaying a legend (useful if you show multiple series).

Here is a detailed sample.

Table
Some of the property names were misleading. From now:

var table = contrib.table(
     { keys: true
     , fg: 'green'
     , label: 'Active Processes'
     , columnSpacing: 10
     , columnWidth: [16, 12, 12]  })

columnSpacing is the number of space characters between table columns. columnWidth is an array of values which specify the width (in characters) of each column.

Let me know if you have any question or concern.

Focus detection in style structure

I have got the following code:

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

///////////////////////
// UI configuration //
/////////////////////

var screen = blessed.screen({
  smartCSR: true
});
var grid = new contrib.grid({rows: 14, cols: 14, screen: screen});

//grid.set(row, col, rowSpan, colSpan, obj, opts)
var nodeTable = grid.set(0, 0, 6, 6, contrib.table, {
  keys: true,
  fg:'white',
  selectedFg: 'white',
  selectedBg: 'blue',
  interactive: true,
  label: 'Node',
  width: '30%',
  height: '30%',
  border: {type: "line", fg: "cyan"},

  style: {
    border: {type: "line", fg: "cyan"},
    focus: {
      border: {
        type: 'line',
        fg: 'white'
      }
    }
  },

  columnSpacing: 10,
  columnWidth: [16, 12]
  });

var servicesTable = grid.set(0, 6, 6, 6, contrib.table, {
  keys: true,
  fg:'white',
  selectedFg: 'white',
  selectedBg: 'blue',
  interactive: true,
  label: 'Active Services',
  width: '30%',
  height: '30%',

  style: {
    border: {type: "line", fg: "cyan"},
    focus: {
      border: {
        type: 'line',
        fg: 'white'
      }
    }
  },

  columnSpacing: 10,
  columnWidth: [16, 12]
});

//////////////
// Set Data //
//////////////

nodeTable.setData({
  headers: ['Node Name'],
  data: [['ocfcld'],
  ['oalcld'],
  ['slbcld'],
  ['ocfcld'],
  ['octcld']]
});

servicesTable.setData({
  headers: ['Service', 'Status'],
  data:[ ['IF-MAP', 'OK'], ['API', 'FAILED'], ['SVC', 'OK'] ]
});

//////////////////////
// Keyboard handler //
//////////////////////

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

screen.key(['C-right'], function(ch, key) {
  screen.focusNext();
  screen.render();
});

screen.key(['C-left'], function(ch, key) {
  screen.focusPrevious();
});

nodeTable.focus();


screen.render();

I have got two tables, I would like to change the border color when I switch between tables, but it seems not working.

Lines appear with letters

The separating lines (the ones that make a box around a widget) do not appear with dashes (as they do in your screenshot) but with the letters 'q', 'm', 'x', 'j', 'k', and 'l'.
Any idea ? I don't think it is related to encoding...

EDIT : Just test with another Terminal (OSX 10.10) settings, and it's the exact same thing

Lines with callbacks

What do you think about modifying the syntax of a line to take an optional callback and interval values?The callback would be function() --> [labels_arr, values_arr]. This would be wrapped in a function to call it and use the return value to call setData. This wrapper would be setImmediate and setInterval.

Some adjustment issues

I'm using a 1024x768 (125x47) terminal and I'm getting some adjustment issues on the dashboard demo:

pantallazo-qemu-1

As you can see, the bars chart bars gets too wide, so it wrap itself. They should use Math.floor() instead of Math.ceil() for adjustment. Also, there are empty lines between widgets wasting screen space, and finally in the progress bar the background don't get filled under the overlay text, being the background filled all or nothing.

Version 2.1.5 hasn't been published?

Hi,

After running npm info blessed-contrib, the latest version I got is 2.0.5, and the master branch version is 2.1.5, seemed has't been published. There is a bug in 2.0.5 and has been fixed in 2.1.5: in version 2.0.5 the first row in table won't not be displayed until you press page down key, but 2.1.5 is Okay. When will you release the newest version? Thanks

About encoding problems

Hi,

Thanks for the great work, but it seems to have some encoding problems, when I set the table label to:

table = contrib.table({
        label : '你好',
    })

It just didn't display as it should be, any ideas? Thanks.

It would be amazing to have a way to rotate a set of graphs.

Totally selfish I know... I was thinking of using this with a Raspberry Pi and TFT shield, but I'd only be able to show one graph at a time.

If there was a way to have pass a set of objects with an interval, it would be possible to create hugely rich interfaces, even in 320x240 ;)

Color bleeding with line charts

Something that happens when plotting (float) data series with values in the same range. Unfortunately I couldn't easily copy data from logs for reproducibility, I can do that manually if needed.

color-bleeding

A potential workaround would be to make the Y axis start from a non-zero value, is that currently possible?

Table widget doesn't allow you to set most options.

keys, fg, interactive, selectedFg, selectedBg, etc. are set to defaults. There doesn't appear to be any way to override them if you don't want the default colors, or don't want the selection highlighted.

Or have I missed something?

License?

Hi, under which license can I use this library? Could you add a license to the package.json? Preferably one which is usable on bintray, so it is usable it with webjars.

See: http://www.webjars.org/npm

Select Events on Table Widget

Is it possible to implement the select events on the table widget? At the moment, the widget does not emit any events at all from what I can tell.

Random Colors for Line Chart

Can someone give me a lead on a discrete list of valid color strings for the chart lines?

Looking to differentiate dynamic series sets on the same chart.
Thanks!

Font?

After installing and running on a CentOS 6.6 server it seems the font may be screwed up as the alignment of everything was off when running on the local terminal. Can this be run on a remote terminal? Would that mean I need to have a specific font installed on the local client?

Bars Questions

@yaronn I am looking into making some improvements to the bars and I wanted to open a thread for discussion.

First question. Why is height and width not dynamic based on the underlying canvas? If there are no objections I am ready to submit a PR for this.

Tree widget: wrong select data after calling .setData()

After calling .setData() twice (and more) tree.on('select') emits wrong data.
Here is the code representing the problem:

var blessed = require('blessed'),
  contrib = require('blessed-contrib'),
  screen = blessed.screen();

var grid = new contrib.grid({
  rows: 6,
  cols: 6,
  screen: screen
});

var tree = grid.set(0, 0, 4, 6, contrib.tree, {
  label: 'Commands'
});

//allow control the table with the keyboard
tree.focus();
var log = grid.set(4, 0, 2, 6, contrib.log, {
  label: 'Server Log'
});

tree.on('select', function(node) {
  log.log(node.name);
});

var data1 = {
  extended: true,
  children: {
    'hash1': {
      name: 'Fruits',
      extended: true,
      children: {
        'h1': {
          name: 'apple'
        },
        'h2': {
          name: 'orange'
        },
      }
    },
    'hash2': {
      name: 'Vegetables',
      extended: true,
      children: {
        'h3': {
          name: 'carrot'
        },
        'h4': {
          name: 'potato'
        }
      }
    },
  }
};

var data2 = {
  extended: true,
  children: {
    'hash11': {
      name: 'More Fruits',
      extended: true,
      children: {
        'h11': {
          name: 'banana'
        },
        'h22': {
          name: 'lemon'
        },
      }
    },
    'hash22': {
      name: 'More Vegetables',
      extended: true,
      children: {
        'h33': {
          name: 'onion'
        },
        'h44': {
          name: 'tomato'
        }
      }
    },
  }
};

tree.setData(data1);
screen.render();

setTimeout(function() {
  tree.setData(data2);
  screen.render();
}, 1000);

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

After tree.setData(data2) tree.on('select',...) will emit data from data1 instead of data2.

Map widget is squashed

Hey, great project!
I ran the demo and got this result:

Seems like the map graphic is squashed. I'm using ZSH.

For lines xPadding should be dynamic based on maxY

If I have Y values greater than 4 chars wide, I have to manually override the padding to get the values to appear correctly. I should be able to set the y values and let blessed-contrib do the work for me.

Feature Request - Forms

Hey,

it'd be great to get several widgets to deal with form functionality... like text fields, radio groups, selection list, checkboxes, textarea, etc.

thanks!

Cannot use 256 colors in donuts widget.

As far as I can tell, you can only use 8 colors when drawing with drawille.

I can try and contribute to the repo so it supports 256 colors, but I cannot find the github repo for drawille-canvas-blessed-contrib.

If you tell me I can have a look and get more colors out of the canvas.

Cheers.

License?

Noticed there is no license on this -- any plans for what direction you might take there?

As it stands it's ambiguous if one could even use it for private stuff.

Rate line color confusion

Hi

I am using a rate line to track 3 values. When the values are very close to each other the colors plotted seem to get confused. I understand when the values are the same only one color can be shown, but I have instances where the 2 lines diverge and both are the same color. Am I missing something here?

screenshot from 2016-02-15 11 32 58
screenshot from 2016-02-15 11 35 16
screenshot from 2016-02-15 11 37 56

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.