开发者社区> 镜像站> NPM> hypernal
hypernal
Renders terminal output as html to simplify reusing server side modules in the browser.
Last updated 6 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hypernal 
SYNC missed versions from official npm registry.

hypernal

Renders terminal output as html to simplify reusing server side modules in the browser.

Example

main.js

var term = require('hypernal')();
term.appendTo('#terminal');

var difflet = require('difflet')({
      indent : 2 
    , comma : 'first'
    , comment: true
    });

var diff = difflet.compare({ a : [1, 2, 3 ], c : 5 }, { a : [1, 2, 3, 4 ], b : 4 });
term.write(diff);

browserify-build.js

require('browserify')()
  .require(require.resolve('./main.js'), { entry: true })
  .bundle()
  .pipe(require('fs').createWriteStream(__dirname + '/bundle.js'), 'utf-8');

index.html

<body>
  <div id="terminal"></div>
  <script type="text/javascript" src="./bundle.js"></script>
</body>

index.css

#terminal {
  width         :  600px;
  height        :  400px;
  background    :  black;
  padding       :  15px 20px 15px 20px;
  border-radius :  15px;
  border        :  2px solid #CEE1F0;
  font-family   :  Monaco;
  font-size     :  16px;
}

difflet.png

View more complete example and its source

Installation

npm install hypernal

Demo

npm explore hypernal && npm run demo

API

hypernal(options:Object)

creates a render only terminal and returns an interface to interact with it as described below.

options:

  • allow overriding { cols: Number, rows: Number } of the terminal, which generally is not necessary Note:
    • number of cols will be applied to any row
    • number of rows will indicate how many rows to add initially, but more will be added if needed

term.tail:Boolean

  • when set to true, the terminal will automatically scroll to the bottom when more lines are added than fit in its container

term.appendTo(elem:String|Object)

appends the terminal to the given DOM element.

term.write(s:String)

writes the given string to the terminal.

term.writeln(s:String)

writes the given string to the terminal and adds a line break.

term.reset()

clears the terminal

Kudos

hypernal is basically a trimmed down version of tty.js focused on and improved for rendering only.

Current Tags

  • 0.3.0                                ...           latest (6 years ago)

13 Versions

  • 0.3.0                                ...           6 years ago
  • 0.2.7                                ...           7 years ago
  • 0.2.6                                ...           7 years ago
  • 0.2.5                                ...           7 years ago
  • 0.2.4                                ...           7 years ago
  • 0.2.3                                ...           8 years ago
  • 0.2.2                                ...           8 years ago
  • 0.2.1                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.3                                ...           8 years ago
  • 0.1.2                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)