-
Notifications
You must be signed in to change notification settings - Fork 2
/
screen.js
48 lines (37 loc) · 1.25 KB
/
screen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
define(['jquery'], function ($) {
var Screen = function (output) {
};
Screen.prototype = {
init: function (output) {
this.output = output;
},
outputToTerminal: function (type, contents) {
this.output.append('<p class="' + type +'">' + contents + '</p>');
},
stdout: function (output) {
this.outputToTerminal('terminal__output', output);
},
stderr: function (output) {
this.outputToTerminal('terminal__error', output);
},
prompt: function () {
var prompt = '<font color="lime">guest</font> in <font color="yellow">/</font>';
this.outputToTerminal('terminal__prompt', prompt);
this.scrollToCursor();
},
scrollToCursor: function () {
var output = this.output[0];
// need to setTimeout to allow time for the dom appending elements
setTimeout(function () {
output.scrollTop = output.scrollHeight;
}, 1);
},
setHeight: function (height) {
this.output.css('max-height', height);
},
clear: function () {
this.output.html('');
}
};
return new Screen();
});