forked from unconed/TermKit
/
termkit.js
74 lines (60 loc) · 1.76 KB
/
termkit.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var termkit = {};
(function ($) {
///////////////////////////////////////////////////////////////////////////////
$(document).ready(function () {
var client = new termkit.client();
client.onConnect = function () {
console.log('client conn');
var shell = new termkit.client.shell(client, {}, function () {
console.log('shell conn');
var view = new termkit.commandView(shell);
$('#terminal').append(view.$element);
view.newCommand();
});
};
});
})(jQuery);
///////////////////////////////////////////////////////////////////////////////
function asyncCallback(func) {
return function () {
var that = this;
var args = arguments;
setTimeout(function () { func.apply(that, args); }, 0);
};
}
function async(func) {
var that = this;
setTimeout(function () { func.call(that); }, 0);
}
function escapeText(text) {
return String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
}
function bug(object, type) {
$.each(object, function (index) {
if ($.isFunction(this)) {
var original = this;
object[index] = function () {
console.log(type +'.'+ index);
console.log(arguments);
original.apply(this, arguments);
};
}
});
}
function oneOrMany(object) {
return (typeof object == 'object' && object.constructor == [].constructor) ? object : [ object ];
}
///////////////////////////////////////////////////////////////////////////////
function formatSize(bytes) {
var suffixes = ['B', 'KB', 'MB', 'GB', 'TB'];
var limit = 1, cap = 1;
for (i in suffixes) {
limit *= 1000;
if (bytes > limit) {
cap = limit;
}
else {
return Math.round(bytes / cap * 10) / 10 + ' ' + suffixes[i];
}
}
}