1 | 'use strict';
|
2 |
|
3 |
|
4 | var Terminal = require('./term')
|
5 | , through = require('through')
|
6 | ;
|
7 |
|
8 | function scroll(elem) {
|
9 | if (!elem) return;
|
10 | elem.scrollTop = elem.scrollHeight;
|
11 | }
|
12 |
|
13 | module.exports = function (opts) {
|
14 | var term = new Terminal(opts);
|
15 | term.open();
|
16 |
|
17 | var hypernal = through(term.write.bind(term));
|
18 | hypernal.appendTo = function (elem) {
|
19 | if (typeof elem === 'string') elem = document.querySelector(elem);
|
20 |
|
21 | elem.appendChild(term.element);
|
22 | elem.setAttribute('style', 'overflow-y : auto;');
|
23 | hypernal.container = elem;
|
24 | term.element.style.position = 'relative';
|
25 | };
|
26 |
|
27 | hypernal.writeln = function (line) {
|
28 | term.writeln(line);
|
29 | if (hypernal.tail) scroll(hypernal.container);
|
30 | };
|
31 |
|
32 | hypernal.write = function (data) {
|
33 | term.write(data);
|
34 | if (hypernal.tail) scroll(hypernal.container);
|
35 | };
|
36 |
|
37 |
|
38 | hypernal.reset = term.reset.bind(term);
|
39 | hypernal.element = term.element;
|
40 |
|
41 |
|
42 | hypernal.term = term;
|
43 |
|
44 | return hypernal;
|
45 | };
|