Code Monkey home page Code Monkey logo

wopr's Introduction

WOPR

WOPR is a simple markup language for creating rich terminal reports, presentations and infographics.

Put a report on the web (e.g. gist) and view it via curl:

$> curl -N tty.zone/\[0-2\]\?auto\&cols=$((COLUMNS))

(If you experience firewall issues replace tty.zone with ec2-23-21-64-152.compute-1.amazonaws.com or use a local viewer)

Created by Yaron Naveh (@YaronNaveh)

##Writing your first terminal report##

Here is a simple report with a bar chart:

<document>
  <page>
    <item col="0" row="0" colSpan="5" rowSpan="4">
      <bar maxHeight="5" data-titles="A,B,C" data-data="2,5,3" />
    </item>
  </page>
</document>

You have 3 options to view this report:

Option 1: POST it to the wopr online viewer

$> curl --data '<document><page><item col="0" row="0" colSpan="5" rowSpan="4"><bar maxHeight="5" data-titles="A,B,C" data-data="2,5,3" /></item></page></document>' tty.zone\?cols=$((COLUMNS))

If you experience firewall issues replace tty.zone with ec2-23-21-64-152.compute-1.amazonaws.com.

Note: The online viewer is a reference implementation. Do not send it secret data but rather create your own.

Option 2: POST it from external url

Save the report content in some url (e.g. gist) and then:

$> a=$(curl -s https://gist.githubusercontent.com/yaronn/e6eec6d0e7adac63c83f/raw/50aca544d26a32aa189e790635c8679067017948/gistfile1.xml); curl --data "$a" tty.zone\?cols=$((COLUMNS))

(note you need the gist raw url)

If you experience firewall issues replace tty.zone with ec2-23-21-64-152.compute-1.amazonaws.com.

Note: The online viewer is a reference implementation. Do not send it secret data but rather create your own.

Option 3: Via the local viewer

Save the report xml to report.xml and then:

$> npm install -g wopr
$> wopr report.xml

Note the local viewer does not send anything online and does not require network.

##Markup Basics#

Pages

A document is a set of pages:

<document>
  <page>
    ...
  </page>
  <page>
    ...
  </page>
</document>

Layout

A page is a 12x12 grid in which you can position different widgets:

<document>
  <page>
    <item col="0" row="0" colSpan="3" rowSpan="3">
      <bar maxHeight="5" data-titles="A,B,C" data-data="2,5,3" />
    </item>
    <item col="5" row="9" colSpan="1" rowSpan="1">
      <box content="some text" />
    </item>
  </page>
</document>

Here, the bar widget is in the first column and row (0-based indexing) and spans three columns and rows. The box element is in the same page but in a different position.

Widgets

The available widgets are the ones that exist in the blessed and blessed-contrib projects. You can infer the xml representation of a javascript widget using a simple convention. Assume that you would instantiate some blessed widget with this javascript:

blessed.widget({ string: "5"
               , int: 1
               , intArray: [1,2,3]
               , stringArray: ["a", "b", "c"]
               , multiArray: [ [1,2,3], [4,5,6] ]
               , complexArray: [ {a: 1, b: [1,2] }, {a: 3, b: [3,4]} ]
               , object: { innerProp: 1, multiArray: [ [1,2], [3,4] ] }
})

Then here is how you would represent it in xml:

<widget string="5" int="1" intArray="1,2,3" stringArray="a,b,c" object-innerProp="1">
  <multiArray>
    1,2,3
    4,5,6
  </multiArray>
  <object-multiArray>
    1,2
    3,4
  </object-multiArray>
  <complexArray>
    <m a="1" b="1,2" />
    <m a="3" b="3,4" />
  </complexArray>
</widget>

You can also look at the demo xml to get more samples.

##Viewing Reports##

Depending on how you use a report, you have a few ways to view it. On Windows you will probably only be able to use the third option and need to install the fonts for best view.

Option 1: POST it to the wopr online viewer

$> curl --data '<document><page><item col="0" row="0" colSpan="5" rowSpan="4"><bar maxHeight="5" data-titles="A,B,C" data-data="2,5,3" /></item></page></document>' tty.zone\?cols=$((COLUMNS))

If you experience firewall issues replace tty.zone with ec2-23-21-64-152.compute-1.amazonaws.com.

Option 2: POST it from external url

Save the report content in some url (e.g. gist) and then:

$> a=$(curl -s https://gist.githubusercontent.com/yaronn/e6eec6d0e7adac63c83f/raw/50aca544d26a32aa189e790635c8679067017948/gistfile1.xml); curl --data "$a" tty.zone\?cols=$((COLUMNS))

(note you need the gist raw url)

If you experience firewall issues replace tty.zone with ec2-23-21-64-152.compute-1.amazonaws.com.

Tip: If you use a url shortener (e.g. bit.ly) add the -L flag to curl to follow redirects.

Option 3: via the local viewer

Save the report xml to report.xml and then:

$> npm install -g wopr
$> wopr report.xml

Note the local viewer does not send anything online and does not require network.

Tip: Maximize the terminal before viewing the report for best viewing experience
Tip: If you CTRL+C in the middle or rendering your cursoe might disappear. Restore it by running again and letting the render complete or with $> echo '\033[?25h'

View customization When using the online reports, you might need to adjust the slides size based on your font / resolution or use non-xterm terminal. tty.zone supports the following query params:

curl -N tty.zone\?\&cols=200\&rows=50\&terminal=xterm

You can infer them automatically from your environment:

curl -N tty.zone\?\&cols=$((COLUMNS))\&rows=$((LINES-5))\&terminal=${TERM}

It is best to escape all special characters (e.g. ? &) as seen in the above samples, since some shells will require this (zsh).

Pages

When viewing a report with the local viewer you can advance slides with the Return or Space keys. When using the online viewer you have 2 options:

Option 1: Manually advance slides with Return or Space:

p=0; while true; do curl tty.zone/$((p++))\?cols=$((COLUMNS)); read; done

Option 2: Slides advance automatically every 5 seconds:

curl -N tty.zone/\[0-2\]\?auto\&cols=$((COLUMNS))

Where 0 is the index of the first slide and 2 of the last slide. Keep the brackets in the url (they are not to express optional argument) and escape them as in the above sample.

Tip: disable curl buffering with the -N flag

You can also view a specific slide (#4 in this case):

curl --data '<document>...</document>' tty.zone/4\?cols=$((COLUMNS))

##License## MIT

More Information

Created by Yaron Naveh (twitter, blog)

wopr's People

Contributors

daveloyall avatar icyflame avatar tcyrus 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

wopr's Issues

Server crashes with `screen.program.destroy is not a function` after displaying first dashboard

What I do

  • I'm installing dependencies by running the following command (in wopr/):
# Note: I'm installing specific versions here because I was also having trouble 
# running simply `npm install`.
$ npm install \
    [email protected] \
    [email protected] \
    [email protected]
  • I launch the wopr server (with node server.js) and it awaits connections as expected.
  • From the client, I run curl -N localhost:1337/\[0-2\]\?auto\&cols=$((COLUMNS)).

What I expect

The server should display all 3 dashboards in the terminal of the client.

What I see instead

  • The server displays the first dashboard as expected, then crashes a few seconds later, citing the error screen.program.destroy is not a function.

Client-side output:

[1/3]: localhost:1337/0?auto&cols=117 --> <stdout>
--_curl_--localhost:1337/0?auto&cols=117
curl: (18) transfer closed with outstanding read data remaining

[3/3]: localhost:1337/2?auto&cols=117 --> <stdout>
--_curl_--localhost:1337/2?auto&cols=117
curl: (7) Failed to connect to localhost port 1337: Connection refused

The server-side logs:

Server running at http://127.0.0.1:1337/
TypeError: screen.program.destroy is not a function
    at clean (/src/wopr/server/presenter.js:72:18)
    at null._onTimeout (/src/wopr/server/presenter.js:57:9)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
Error: write after end
    at ServerResponse.OutgoingMessage.write (_http_outgoing.js:426:15)
    at OutputBuffer.write (/src/wopr/node_modules/blessed-contrib/lib/server-utils.js:12:19)
    at Program.flush (/src/wopr/node_modules/blessed/lib/program.js:1473:15)
    at Screen.leave (/src/wopr/node_modules/blessed/lib/widgets/screen.js:273:16)
    at process.<anonymous> (/src/wopr/node_modules/blessed/lib/widgets/screen.js:184:10)
    at emitOne (events.js:90:13)
    at process.emit (events.js:182:7)
    at process._fatalException (node.js:264:26)
error: Forever detected script exited with code: 1

To reproduce the issue

I'm installing wopr in a Docker container. There are Dockerfiles for the server and even the client in my fork of this repo.

duplicate viewers information

the readme.md contains twice the information about the viewing of said report, the second one talks about customization of online viewer, not the first one. Nice work.

TypeError: this.input.removeListener is not a function

Note: Contrary to #9, here I'm installing with npm install instead of specific versions of the dependencies.

What I do

$ git clone https://github.com/yaronn/wopr.git /src/wopr
$ cd /src/wopr
$ npm install
$ node server.js

Then I run curl -N localhost:1337/\[0-2\]\?auto\&cols=$((COLUMNS)) from the client.

What I expect

The server should display those sweet-looking dashboards.

What I see instead

Client-side output

No dashboard appears, only this:

[1/3]: localhost:1337/0?auto&cols=94 --> <stdout>
--_curl_--localhost:1337/0?auto&cols=94

Then, a few seconds later:

[2/3]: localhost:1337/1?auto&cols=94 --> <stdout>
--_curl_--localhost:1337/1?auto&cols=94
curl: (7) Failed to connect to localhost port 1337: Connection refused

[3/3]: localhost:1337/2?auto&cols=94 --> <stdout>
--_curl_--localhost:1337/2?auto&cols=94
curl: (7) Failed to connect to localhost port 1337: Connection refused

The server-side logs:

Server running at http://127.0.0.1:1337/
TypeError: this.input.removeListener is not a function
    at Program.destroy (/src/wopr/node_modules/blessed/lib/program.js:487:18)
    at clean (/src/wopr/server/presenter.js:72:18)
    at null._onTimeout (/src/wopr/server/presenter.js:57:9)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
/src/wopr/node_modules/blessed/lib/program.js:487
      this.input.removeListener('keypress', this.input._keypressHandler);
                 ^

TypeError: this.input.removeListener is not a function
    at Program.destroy (/src/wopr/node_modules/blessed/lib/program.js:487:18)
    at Screen.destroy (/src/wopr/node_modules/blessed/lib/widgets/screen.js:442:16)
    at /src/wopr/node_modules/blessed/lib/widgets/screen.js:239:14
    at Array.forEach (native)
    at process.on.Screen._exitHandler (/src/wopr/node_modules/blessed/lib/widgets/screen.js:238:30)
    at emitOne (events.js:95:20)
    at process.emit (events.js:182:7)
    at process.exit (node.js:721:17)
    at Immediate._onImmediate (/src/wopr/node_modules/blessed/lib/widgets/screen.js:221:15)
    at processImmediate [as _immediateCallback] (timers.js:516:17)

XML namespace

Hi! I would like to know if there is an XML namespace already defined for the XML format used by wopr. I would like to use the format in other contexts, and possibly, within other XML applications, so it would be good having a dedicated namespace for this.

-h / --help customary options?

It's more or less a convention, although right now usage is entirely straightforward. Thanks for the utility - it's awesome to have such great expressiveness in a tty.

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.