Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/jquery-terminal/test.ts
1293 views
1
/// <reference path="./js/jquery.terminal.d.ts" />
2
3
import "jquery";
4
import "jquery.terminal";
5
6
7
function test_type<T>(x: T) {};
8
// -----------------------------------------------------------------------------
9
// :: instance
10
// -----------------------------------------------------------------------------
11
12
$('.term').terminal(function(command, term) {
13
14
});
15
$('.term').terminal(function(command) {
16
17
});
18
$('.term').terminal([function(command, term) {
19
return Promise.resolve(document.createElement('div'));
20
}]);
21
$('.term').terminal("foo.php");
22
$('.term').terminal(["foo.php"]);
23
var obj_interpreter: JQueryTerminal.ObjectInterpreter = {
24
foo: function(...args) {
25
return $('<div/>');
26
},
27
bar: function(a, b) {
28
// user should typecheck the arguments in JavaScript
29
(<RegExp>a).test('x');
30
return Promise.resolve("foo");
31
},
32
baz: {
33
a: function() {
34
return document.createElement('canvas');
35
},
36
b: {
37
c: function() {
38
return "xxx";
39
}
40
}
41
}
42
};
43
$('.term').terminal([obj_interpreter]);
44
$('.term').terminal(["foo.php", obj_interpreter]);
45
$('.term').terminal(["foo.php", obj_interpreter, function(command) {
46
}]);
47
48
class Foo {
49
x: string;
50
constructor(x: string) {
51
this.x = x;
52
}
53
}
54
// -----------------------------------------------------------------------------
55
// :: formatters
56
// -----------------------------------------------------------------------------
57
$.terminal.nested_formatting.__inherit__ = true;
58
$.terminal.nested_formatting.__warn__ = true;
59
$.terminal.nested_formatting.__meta__ = true;
60
61
// -----------------------------------------------------------------------------
62
// :: Options
63
// -----------------------------------------------------------------------------
64
(function() {
65
// -------------------------------------------------------------------------
66
// :: prompt
67
// -------------------------------------------------------------------------
68
$('.term').terminal($.noop, {
69
prompt: function() {
70
return Promise.resolve(">>> ");
71
}
72
});
73
$('.term').terminal($.noop, {
74
prompt: ">>> "
75
});
76
$('.term').terminal($.noop, {
77
prompt: function(cb) {
78
cb(">>> ");
79
console.log(this.get_command());
80
}
81
});
82
// -------------------------------------------------------------------------
83
// :: keymap
84
// -------------------------------------------------------------------------
85
$('.term').terminal($.noop, {
86
keymap: {
87
'CTRL+C': function(e, original) {
88
console.log(e.target);
89
original(e);
90
}
91
}
92
});
93
// -------------------------------------------------------------------------
94
// :: exceptionHandler
95
// -------------------------------------------------------------------------
96
$('.term').terminal($.noop, {
97
exceptionHandler: function(e, label) {
98
test_type<JQueryTerminal>(this);
99
this.error(e.message);
100
}
101
});
102
// -------------------------------------------------------------------------
103
// :: onCommandChange
104
// -------------------------------------------------------------------------
105
$('.term').terminal($.noop, {
106
onCommandChange: function(command) {
107
test_type<JQueryTerminal>(this);
108
test_type<string>(command);
109
}
110
});
111
// -------------------------------------------------------------------------
112
// :: processRPCResponse
113
// -------------------------------------------------------------------------
114
$('.term').terminal($.noop, {
115
processRPCResponse: function(data) {
116
data.result = 10;
117
}
118
});
119
// -------------------------------------------------------------------------
120
// :: greetings
121
// -------------------------------------------------------------------------
122
$('.term').terminal($.noop, {
123
greetings: "hello"
124
});
125
$('.term').terminal($.noop, {
126
greetings: null
127
});
128
$('.term').terminal($.noop, {
129
greetings: function(cb) {
130
cb("hello");
131
}
132
});
133
$('.term').terminal($.noop, {
134
greetings: function() {
135
console.log(this.get_command());
136
return Promise.resolve("Hello");
137
}
138
});
139
// -------------------------------------------------------------------------
140
// :: scrollObject
141
// -------------------------------------------------------------------------
142
$('.term').terminal($.noop, {
143
scrollObject: "html"
144
});
145
$('.term').terminal($.noop, {
146
scrollObject: $("body")
147
});
148
$('.term').terminal($.noop, {
149
scrollObject: document.body
150
});
151
// -------------------------------------------------------------------------
152
// :: historyFilter
153
// -------------------------------------------------------------------------
154
$('.term').terminal($.noop, {
155
historyFilter: /^ /
156
});
157
$('.term').terminal($.noop, {
158
historyFilter: function(command) {
159
return !!command.match(/^ /);
160
}
161
});
162
// -------------------------------------------------------------------------
163
// :: login
164
// -------------------------------------------------------------------------
165
$('.term').terminal($.noop, {
166
login: true
167
});
168
$('.term').terminal($.noop, {
169
login: function(username, password) {
170
return Promise.resolve("TOKEN");
171
}
172
});
173
$('.term').terminal($.noop, {
174
login: function(username, password, cb) {
175
cb("TOKEN");
176
}
177
});
178
// -------------------------------------------------------------------------
179
// :: onAjaxError
180
// -------------------------------------------------------------------------
181
$('.term').terminal($.noop, {
182
onAjaxError: function(xhr, status, error) {
183
xhr.getAllResponseHeaders();
184
status.charCodeAt(0);
185
error.charCodeAt(0);
186
}
187
});
188
// -------------------------------------------------------------------------
189
// :: request
190
// -------------------------------------------------------------------------
191
$('.term').terminal($.noop, {
192
request: function(xhr, json, term) {
193
term.echo("foo");
194
}
195
});
196
$('.term').terminal($.noop, {
197
request: function(xhr, data) {
198
data.params.unshift("token");
199
this.echo(JSON.stringify(data));
200
var term = this;
201
xhr.then(function(value) {
202
term.echo(value);
203
});
204
}
205
});
206
// -------------------------------------------------------------------------
207
// :: response
208
// -------------------------------------------------------------------------
209
$('.term').terminal($.noop, {
210
response: function(xhr, data) {
211
data.result = 10;
212
this.echo(JSON.stringify(data));
213
var term = this;
214
xhr.then(function(value) {
215
term.echo(value);
216
});
217
}
218
});
219
// -------------------------------------------------------------------------
220
// :: onRPCError
221
// -------------------------------------------------------------------------
222
$('.term').terminal($.noop, {
223
onRPCError: function(error) {
224
this.echo(error.error.message);
225
}
226
});
227
// -------------------------------------------------------------------------
228
// :: doubleTab
229
// -------------------------------------------------------------------------
230
$('.term').terminal($.noop, {
231
doubleTab: function(str, matched, echo_Command) {
232
echo_Command();
233
this.echo(matched.slice(1).concat([str]));
234
}
235
});
236
// -------------------------------------------------------------------------
237
// :: completion
238
// -------------------------------------------------------------------------
239
$('.term').terminal($.noop, {
240
completion: ["foo", "bar", "baz"]
241
});
242
$('.term').terminal($.noop, {
243
completion: function(str, cb) {
244
str.charCodeAt(0);
245
cb(["foo", "bar", "baz"]);
246
}
247
});
248
// -------------------------------------------------------------------------
249
// :: Simple events
250
// -------------------------------------------------------------------------
251
$('.term').terminal($.noop, {
252
onInit: function(term) {
253
this.echo('event');
254
}
255
});
256
$('.term').terminal($.noop, {
257
onClear: function(term) {
258
this.echo('event');
259
}
260
});
261
$('.term').terminal($.noop, {
262
onBlur: function(term) {
263
this.echo('event');
264
}
265
});
266
$('.term').terminal($.noop, {
267
onFocus: function(term) {
268
this.echo('event');
269
}
270
});
271
$('.term').terminal($.noop, {
272
onExit: function(term) {
273
this.echo('event');
274
}
275
});
276
$('.term').terminal($.noop, {
277
onAfterRedraw: function(term) {
278
this.echo('event');
279
}
280
});
281
$('.term').terminal($.noop, {
282
onFlush: function(term) {
283
this.echo('event');
284
}
285
});
286
// -------------------------------------------------------------------------
287
// :: onPush
288
// -------------------------------------------------------------------------
289
$('.term').terminal($.noop, {
290
onPush: function(before, after) {
291
before.interpreter.call(this, "init", this);
292
}
293
});
294
// -------------------------------------------------------------------------
295
// :: onPush
296
// -------------------------------------------------------------------------
297
$('.term').terminal($.noop, {
298
onPop: function(before, after) {
299
before.interpreter.call(this, "init", this);
300
}
301
});
302
// -------------------------------------------------------------------------
303
// :: keypress
304
// -------------------------------------------------------------------------
305
$('.term').terminal($.noop, {
306
keypress: function(e) {
307
this.echo(e.key);
308
}
309
});
310
// -------------------------------------------------------------------------
311
// :: keydown
312
// -------------------------------------------------------------------------
313
$('.term').terminal($.noop, {
314
keydown: function(e) {
315
this.echo(e.key);
316
}
317
});
318
// -------------------------------------------------------------------------
319
// :: onEchoCommand
320
// -------------------------------------------------------------------------
321
$('.term').terminal($.noop, {
322
onEchoCommand: function(div, command) {
323
div.css('color', 'red');
324
this.echo(command.charCodeAt(0).toString());
325
}
326
});
327
// -------------------------------------------------------------------------
328
// :: renderHandler
329
// -------------------------------------------------------------------------
330
$('.term').terminal($.noop, {
331
renderHandler: function(value) {
332
// value here is any you should typecheck the value in JS
333
// and return string, DOM node or jQuery object
334
if (value instanceof Foo) {
335
return $('<span>' + value.x + '</span>');
336
}
337
if (value === true) {
338
this.echo('true value');
339
return false;
340
}
341
if (value === false) {
342
var div = document.createElement('div');
343
div.innerHTML = 'false value';
344
return div;
345
}
346
}
347
});
348
});
349
350
// -----------------------------------------------------------------------------
351
// :: Methods
352
// -----------------------------------------------------------------------------
353
(function() {
354
var term = $('.term').terminal();
355
// -------------------------------------------------------------------------
356
// :: id
357
// -------------------------------------------------------------------------
358
test_type<number>(term.id());
359
// -------------------------------------------------------------------------
360
// :: clear
361
// -------------------------------------------------------------------------
362
term.clear().clear();
363
// -------------------------------------------------------------------------
364
// :: import/export
365
// -------------------------------------------------------------------------
366
term.import_view(term.export_view());
367
// -------------------------------------------------------------------------
368
// :: save_state
369
// -------------------------------------------------------------------------
370
term.save_state("foo");
371
term.save_state("foo", true);
372
term.save_state("foo", undefined, 10);
373
term.save_state("foo", false, 10);
374
// -------------------------------------------------------------------------
375
// :: exec
376
// -------------------------------------------------------------------------
377
term.exec("foo");
378
term.exec("foo", true);
379
term.exec("foo", true, jQuery.Deferred()).then(function() {
380
});
381
// -------------------------------------------------------------------------
382
// :: autologin
383
// -------------------------------------------------------------------------
384
term.autologin("username", "TOKEN").clear();
385
term.autologin("username", "TOKEN", true).clear();
386
// -------------------------------------------------------------------------
387
// :: login
388
// -------------------------------------------------------------------------
389
term.login(function(username, password, callback) {
390
391
}).clear();
392
term.login(function(username, password) {
393
394
}).clear();
395
term.login(function(username, password) {
396
397
}, true, () => {}).clear();
398
term.login(function(username, password) {
399
400
}, undefined, () => {}).clear();
401
term.login(function(username, password) {
402
403
}, true, () => {}, () => {}).clear();
404
// -------------------------------------------------------------------------
405
// :: settings
406
// -------------------------------------------------------------------------
407
term.before_cursor().charCodeAt(0);
408
term.before_cursor(true).charCodeAt(0);
409
// -------------------------------------------------------------------------
410
// ::
411
// -------------------------------------------------------------------------
412
term.set_interpreter(function(command) {
413
});
414
term.set_interpreter(function(command, term) {
415
416
});
417
term.set_interpreter(function(command) {
418
419
});
420
term.set_interpreter([function(command, term) {
421
422
}]);
423
term.set_interpreter("foo.php");
424
term.set_interpreter(["foo.php"]);
425
term.set_interpreter([obj_interpreter]);
426
term.set_interpreter(["foo.php", obj_interpreter]);
427
term.set_interpreter(["foo.php", obj_interpreter, function(command) {
428
}]);
429
term.set_interpreter("foo.php", true);
430
term.set_interpreter("foo.php", "login");
431
term.set_interpreter("foo.php", function(user, password) {
432
});
433
term.set_interpreter("foo.php", function(user, password, cb) {
434
cb("Foo");
435
});
436
// -------------------------------------------------------------------------
437
// :: greetings
438
// -------------------------------------------------------------------------
439
term.greetings().echo("foo");
440
// -------------------------------------------------------------------------
441
// :: paused
442
// -------------------------------------------------------------------------
443
test_type<boolean>(term.paused());
444
// -------------------------------------------------------------------------
445
// :: pause
446
// -------------------------------------------------------------------------
447
term.pause().echo("foo");
448
// -------------------------------------------------------------------------
449
// :: resume
450
// -------------------------------------------------------------------------
451
term.resume().echo("foo");
452
// -------------------------------------------------------------------------
453
// :: cols
454
// -------------------------------------------------------------------------
455
test_type<number>(term.cols());
456
// -------------------------------------------------------------------------
457
// :: rows
458
// -------------------------------------------------------------------------
459
test_type<number>(term.rows());
460
// -------------------------------------------------------------------------
461
// :: history
462
// -------------------------------------------------------------------------
463
test_type<JQueryTerminal.History<string>>(term.history())
464
// -------------------------------------------------------------------------
465
// :: history_state
466
// -------------------------------------------------------------------------
467
term.history_state(true).echo("foo");
468
// -------------------------------------------------------------------------
469
// :: clear_history_state
470
// -------------------------------------------------------------------------
471
term.clear_history_state().echo("foo");
472
// -------------------------------------------------------------------------
473
// :: next
474
// -------------------------------------------------------------------------
475
term.next().echo("foo");
476
// -------------------------------------------------------------------------
477
// :: focus
478
// -------------------------------------------------------------------------
479
term.focus().echo("foo");
480
term.focus(true).echo("foo");
481
// -------------------------------------------------------------------------
482
// :: freeze
483
// -------------------------------------------------------------------------
484
term.freeze().echo("foo");
485
term.freeze(true).echo("foo");
486
// -------------------------------------------------------------------------
487
// :: fronzen
488
// -------------------------------------------------------------------------
489
test_type<boolean>(term.frozen());
490
// -------------------------------------------------------------------------
491
// :: enable
492
// -------------------------------------------------------------------------
493
term.enable().echo("foo");
494
term.enable(true);
495
// -------------------------------------------------------------------------
496
// :: disable
497
// -------------------------------------------------------------------------
498
term.disable().echo("foo");
499
term.disable(true);
500
// -------------------------------------------------------------------------
501
// :: enabled
502
// -------------------------------------------------------------------------
503
test_type<boolean>(term.enabled());
504
// -------------------------------------------------------------------------
505
// :: signature
506
// -------------------------------------------------------------------------
507
test_type<string>(term.signature());
508
// -------------------------------------------------------------------------
509
// :: version
510
// -------------------------------------------------------------------------
511
test_type<string>(term.version());
512
// -------------------------------------------------------------------------
513
// :: cmd
514
// -------------------------------------------------------------------------
515
test_type<Cmd>(term.cmd());
516
// -------------------------------------------------------------------------
517
// :: get_command
518
// -------------------------------------------------------------------------
519
test_type<string>(term.get_command());
520
// -------------------------------------------------------------------------
521
// :: set_command
522
// -------------------------------------------------------------------------
523
term.set_command("foo").echo("foo");
524
term.set_command("foo", true);
525
// -------------------------------------------------------------------------
526
// :: get_position
527
// -------------------------------------------------------------------------
528
test_type<number>(term.get_position());
529
// -------------------------------------------------------------------------
530
// :: insert
531
// -------------------------------------------------------------------------
532
test_type<JQueryTerminal>(term.insert("foo"));
533
term.insert("foo", true);
534
// -------------------------------------------------------------------------
535
// :: set_prompt
536
// -------------------------------------------------------------------------
537
test_type<JQueryTerminal>(term.set_prompt(">>> "));
538
term.set_prompt(function(cb) {
539
cb(">>> ");
540
this.get_command();
541
});
542
term.set_prompt(function() {
543
this.get_command();
544
return Promise.resolve(">>> ");
545
});
546
// -------------------------------------------------------------------------
547
// :: get_prompt
548
// -------------------------------------------------------------------------
549
var fn: (cb: (prompt: string) => void) => void = term.get_prompt();
550
var prompt: string = term.get_prompt();
551
// -------------------------------------------------------------------------
552
// :: set_mask
553
// -------------------------------------------------------------------------
554
test_type<JQueryTerminal>(term.set_mask(true));
555
term.set_mask("-");
556
// -------------------------------------------------------------------------
557
// :: get_output
558
// -------------------------------------------------------------------------
559
test_type<string[]>(term.get_output());
560
var lines: JQueryTerminal.Lines = term.get_output();
561
test_type<number>(lines[0].index);
562
var div = $('<div/>');
563
lines[0].options.finalize.call(term, div);
564
lines[0].options.onClear.call(term, div);
565
lines[0].options.unmount.call(term, div);
566
// -------------------------------------------------------------------------
567
// :: resize
568
// -------------------------------------------------------------------------
569
test_type<JQueryTerminal>(term.resize());
570
term.resize(100);
571
term.resize(100, 200);
572
// -------------------------------------------------------------------------
573
// :: refresh
574
// -------------------------------------------------------------------------
575
test_type<JQueryTerminal>(term.refresh());
576
// -------------------------------------------------------------------------
577
// :: flush
578
// -------------------------------------------------------------------------
579
test_type<JQueryTerminal>(term.flush());
580
term.flush({update: true});
581
term.flush({scroll: true});
582
// -------------------------------------------------------------------------
583
// :: update
584
// -------------------------------------------------------------------------
585
test_type<JQueryTerminal>(term.update(10, ">>>"));
586
term.update(10, ">>>", {
587
finalize: function(div) {
588
div.css('color', 'red');
589
}
590
});
591
// -------------------------------------------------------------------------
592
// :: remove_line
593
// -------------------------------------------------------------------------
594
test_type<JQueryTerminal>(term.remove_line(10));
595
// -------------------------------------------------------------------------
596
// :: echo
597
// -------------------------------------------------------------------------
598
term.echo("foo");
599
term.echo(["foo", "bar"]);
600
term.echo(function(): string {
601
return "foo";
602
});
603
term.echo(function(): string[] {
604
return ["foo", "bar"];
605
});
606
term.echo(Promise.resolve("foo"));
607
term.echo(Promise.resolve(["foo"]));
608
term.echo(Promise.resolve(function(): string {
609
return "foo";
610
}));
611
term.echo(Promise.resolve(function(): string[] {
612
return ["foo"];
613
}));
614
// add in version 2.9.0
615
term.echo(document.createElement('div'));
616
term.echo($('<div/>'));
617
term.echo($(document.createElement('div')));
618
// special case when Foo class is processed by renderHandler
619
// this is wordaround since echo can accept anything
620
term.echo<Foo>(new Foo('hello'));
621
// function options
622
term.echo(document.createElement('canvas'), {
623
onClear: function(div) {
624
div.find('canvas');
625
console.log(this.get_command());
626
(div[0] as any).pause = true;
627
},
628
unmount: function(div) {
629
div.find('canvas');
630
console.log(this.get_command());
631
},
632
finalize: function(div) {
633
div.find('canvas');
634
console.log(this.get_command());
635
var canvas = <HTMLCanvasElement>(div.find('cavas')[0]);
636
canvas.width = canvas.height = 100;
637
var ctx = canvas.getContext("2d");
638
if (ctx === null) {
639
return;
640
}
641
ctx.clearRect(0, 0, 100, 100);
642
ctx.fillStyle = "#00FF00";
643
ctx.fillRect(10, 10, 90, 90);
644
}
645
});
646
// -------------------------------------------------------------------------
647
// :: error
648
// -------------------------------------------------------------------------
649
test_type<JQueryTerminal>(term.error("foo"));
650
term.error(function() {
651
return "foo";
652
});
653
term.error(Promise.resolve("foo"), {
654
finalize: function(div) {
655
div.addClass('error-string');
656
}
657
});
658
// -------------------------------------------------------------------------
659
// :: exception
660
// -------------------------------------------------------------------------
661
var e = new $.terminal.Exception("error");
662
test_type<JQueryTerminal>(term.exception(e));
663
term.exception(e, "ERROR");
664
// -------------------------------------------------------------------------
665
// :: scroll
666
// -------------------------------------------------------------------------
667
test_type<JQueryTerminal>(term.scroll(10));
668
// -------------------------------------------------------------------------
669
// :: logout
670
// -------------------------------------------------------------------------
671
test_type<JQueryTerminal>(term.logout());
672
term.logout(true);
673
// -------------------------------------------------------------------------
674
// :: token
675
// -------------------------------------------------------------------------
676
test_type<string>(term.token());
677
term.token(true);
678
// -------------------------------------------------------------------------
679
// :: set_token
680
// -------------------------------------------------------------------------
681
test_type<JQueryTerminal>(term.set_token("foo"));
682
term.set_token("foo", true);
683
// -------------------------------------------------------------------------
684
// :: get_token
685
// -------------------------------------------------------------------------
686
test_type<string>(term.get_token());
687
term.get_token(true);
688
// -------------------------------------------------------------------------
689
// :: login_name
690
// -------------------------------------------------------------------------
691
test_type<string>(term.login_name());
692
term.login_name(true);
693
// -------------------------------------------------------------------------
694
// :: name
695
// -------------------------------------------------------------------------
696
test_type<string>(term.name());
697
// -------------------------------------------------------------------------
698
// :: prefix_name
699
// -------------------------------------------------------------------------
700
test_type<string>(term.prefix_name());
701
test_type<string>(term.prefix_name(true));
702
// -------------------------------------------------------------------------
703
// :: read
704
// -------------------------------------------------------------------------
705
term.read("foo", function(s) {
706
s.charCodeAt(0);
707
}).then(function(s) {
708
s.charCodeAt(0);
709
});
710
// -------------------------------------------------------------------------
711
// :: push
712
// -------------------------------------------------------------------------
713
term.push(function(command) {
714
});
715
term.push(function(command, term) {
716
717
});
718
term.push(function(command) {
719
720
});
721
term.push([function(command, term) {
722
723
}]);
724
term.push("foo.php");
725
term.push(["foo.php"]);
726
term.push([obj_interpreter]);
727
term.push(["foo.php", obj_interpreter]);
728
term.push(["foo.php", obj_interpreter, function(command) {
729
}]);
730
term.push("foo", {
731
login: true
732
});
733
term.push("foo", {
734
infiniteLogin: true
735
});
736
term.push("foo", {
737
prompt: "foo"
738
});
739
term.push("foo", {
740
prompt: function(cb) {
741
cb("foo");
742
var s: string = this.get_command();
743
}
744
});
745
term.push("foo", {
746
login: function(username, password, cb) {
747
cb('TOKEN');
748
}
749
});
750
term.push("foo", {
751
completion: ["foo", "bar", "baz"]
752
});
753
term.push("foo", {
754
completion: function(str, cb) {
755
str.charCodeAt(0);
756
cb(["foo", "bar", "baz"]);
757
}
758
});
759
// -------------------------------------------------------------------------
760
// :: pop
761
// -------------------------------------------------------------------------
762
test_type<JQueryTerminal>(term.pop());
763
term.pop("foo");
764
term.pop("foo", true);
765
// -------------------------------------------------------------------------
766
// :: option
767
// -------------------------------------------------------------------------
768
var option: string = term.option('name');
769
term.option({
770
completion: ["foo"]
771
});
772
term.option("completion", ["foo"]);
773
// -------------------------------------------------------------------------
774
// :: invoke_key
775
// -------------------------------------------------------------------------
776
test_type<JQueryTerminal>(term.invoke_key("CTRL+C"));
777
// -------------------------------------------------------------------------
778
// :: keymap
779
// -------------------------------------------------------------------------
780
var keymap_fn: (e: JQueryKeyEventObject) => any = term.keymap('CTRL+K');
781
var keymap = term.keymap();
782
keymap['CTRL+C']($.Event("keypress"));
783
term.keymap("CTRL+C")($.Event("keypress"));
784
term.keymap("CTRL+C", keymap_fn);
785
term.keymap(keymap);
786
// -------------------------------------------------------------------------
787
// :: level
788
// -------------------------------------------------------------------------
789
test_type<number>(term.level());
790
// -------------------------------------------------------------------------
791
// :: reset
792
// -------------------------------------------------------------------------
793
test_type<JQueryTerminal>(term.reset());
794
// -------------------------------------------------------------------------
795
// :: purge
796
// -------------------------------------------------------------------------
797
test_type<JQueryTerminal>(term.purge());
798
// -------------------------------------------------------------------------
799
// :: destroy
800
// -------------------------------------------------------------------------
801
test_type<JQueryTerminal>(term.destroy());
802
// -------------------------------------------------------------------------
803
// :: scroll_to_bottom
804
// -------------------------------------------------------------------------
805
test_type<JQueryTerminal>(term.scroll_to_bottom());
806
// -------------------------------------------------------------------------
807
// :: is_bottom
808
// -------------------------------------------------------------------------
809
test_type<boolean>(term.is_bottom());
810
});
811
812
813
// -----------------------------------------------------------------------------
814
// :: CMD
815
// -----------------------------------------------------------------------------
816
// -----------------------------------------------------------------------------
817
// :: Options
818
// -----------------------------------------------------------------------------
819
(function() {
820
// -------------------------------------------------------------------------
821
// :: prompt
822
// -------------------------------------------------------------------------
823
test_type<Cmd>($('.cmd').cmd());
824
$('<div/>').cmd({
825
prompt: ">>> "
826
});
827
$('<div/>').cmd({
828
prompt: function(cb) {
829
cb(">>> ");
830
}
831
});
832
// -------------------------------------------------------------------------
833
// :: onPositionChange
834
// -------------------------------------------------------------------------
835
$('.cmd').cmd({
836
onPositionChange: function(position) {
837
test_type<number>(position);
838
}
839
});
840
$('.cmd').cmd({
841
onPositionChange: function(position, display_pos) {
842
test_type<number>(display_pos);
843
}
844
});
845
// -------------------------------------------------------------------------
846
// :: historyFilter
847
// -------------------------------------------------------------------------
848
$('.cmd').cmd({
849
historyFilter: /^ /
850
});
851
$('.cmd').cmd({
852
historyFilter: function(command) {
853
return !!command.match(/^ /);
854
}
855
});
856
// -------------------------------------------------------------------------
857
// :: commands
858
// -------------------------------------------------------------------------
859
$('.cmd').cmd({
860
commands: function(command) {
861
test_type<Cmd>(this);
862
test_type<string>(command);
863
}
864
});
865
// -------------------------------------------------------------------------
866
// :: onCommandChange
867
// -------------------------------------------------------------------------
868
$('.cmd').cmd({
869
onCommandChange: function(command) {
870
test_type<Cmd>(this);
871
test_type<string>(command);
872
}
873
});
874
// -------------------------------------------------------------------------
875
// :: keypress
876
// -------------------------------------------------------------------------
877
$('.cmd').cmd({
878
keypress: function(e) {
879
test_type<Cmd>(this);
880
var name: string = e.target.nodeName;
881
}
882
});
883
// -------------------------------------------------------------------------
884
// :: keydown
885
// -------------------------------------------------------------------------
886
$('.cmd').cmd({
887
keydown: function(e) {
888
test_type<Cmd>(this);
889
var name: string = e.target.nodeName;
890
}
891
});
892
});
893
894
// -----------------------------------------------------------------------------
895
// :: Methods
896
// -----------------------------------------------------------------------------
897
(function() {
898
var cmd = $('.cmd').cmd();
899
// -------------------------------------------------------------------------
900
// :: option
901
// -------------------------------------------------------------------------
902
test_type<Cmd>(cmd.option("mask", 10));
903
test_type<string>(cmd.option("mask"));
904
// -------------------------------------------------------------------------
905
// :: name
906
// -------------------------------------------------------------------------
907
test_type<string>(cmd.name());
908
test_type<Cmd>(cmd.name("foo"));
909
// -------------------------------------------------------------------------
910
// :: purge
911
// -------------------------------------------------------------------------
912
test_type<Cmd>(cmd.purge());
913
// -------------------------------------------------------------------------
914
// :: history
915
// -------------------------------------------------------------------------
916
test_type<JQueryTerminal.History<string>>(cmd.history());
917
cmd.history().next();
918
// -------------------------------------------------------------------------
919
// :: delete
920
// -------------------------------------------------------------------------
921
test_type<string>(cmd.delete(10));
922
test_type<string>(cmd.delete(10, true));
923
// -------------------------------------------------------------------------
924
// :: set
925
// -------------------------------------------------------------------------
926
test_type<Cmd>(cmd.set("foo"));
927
test_type<Cmd>(cmd.set("foo", true));
928
test_type<Cmd>(cmd.set("foo", true, true));
929
// -------------------------------------------------------------------------
930
// :: keymap
931
// -------------------------------------------------------------------------
932
var keymap_fn: (e: JQueryKeyEventObject) => any = cmd.keymap('CTRL+K');
933
var keymap = cmd.keymap();
934
keymap['CTRL+C']($.Event("keypress"));
935
cmd.keymap("CTRL+C")($.Event("keypress"));
936
cmd.keymap("CTRL+C", keymap_fn);
937
cmd.keymap(keymap);
938
// -------------------------------------------------------------------------
939
// :: insert
940
// -------------------------------------------------------------------------
941
test_type<Cmd>(cmd.insert("foo"));
942
test_type<Cmd>(cmd.insert("foo", true));
943
// -------------------------------------------------------------------------
944
// :: get
945
// -------------------------------------------------------------------------
946
test_type<string>(cmd.get<string>());
947
// -------------------------------------------------------------------------
948
// :: commands
949
// -------------------------------------------------------------------------
950
cmd.commands()("foo");
951
test_type<Cmd>(cmd.commands(function(command) {
952
this.display_position();
953
test_type<string>(command);
954
}));
955
// -------------------------------------------------------------------------
956
// :: destroy
957
// -------------------------------------------------------------------------
958
test_type<Cmd>(cmd.destroy());
959
// -------------------------------------------------------------------------
960
// :: prompt
961
// -------------------------------------------------------------------------
962
var fn: (cb: (prompt: string) => void) => void = cmd.prompt();
963
var prompt: string = cmd.prompt();
964
965
test_type<Cmd>(cmd.prompt(function(cb) {
966
this.display_position();
967
cb(">>> ");
968
}));
969
test_type<Cmd>(cmd.prompt(">>> "));
970
test_type<string>(cmd.prompt(true));
971
// -------------------------------------------------------------------------
972
// :: position
973
// -------------------------------------------------------------------------
974
test_type<number>(cmd.position<number>());
975
test_type<Cmd>(cmd.position(10));
976
test_type<Cmd>(cmd.position(10, true));
977
// -------------------------------------------------------------------------
978
// :: refresh
979
// -------------------------------------------------------------------------
980
test_type<Cmd>(cmd.refresh());
981
// -------------------------------------------------------------------------
982
// :: display_postion
983
// -------------------------------------------------------------------------
984
test_type<number>(cmd.display_position());
985
test_type<Cmd>(cmd.display_position(10));
986
// -------------------------------------------------------------------------
987
// :: show
988
// -------------------------------------------------------------------------
989
test_type<Cmd>(cmd.show());
990
// -------------------------------------------------------------------------
991
// :: resize
992
// -------------------------------------------------------------------------
993
test_type<Cmd>(cmd.resize());
994
test_type<Cmd>(cmd.resize(100));
995
// -------------------------------------------------------------------------
996
// :: enable
997
// -------------------------------------------------------------------------
998
test_type<Cmd>(cmd.enable());
999
// -------------------------------------------------------------------------
1000
// :: isenabled
1001
// -------------------------------------------------------------------------
1002
test_type<boolean>(cmd.isenabled());
1003
// -------------------------------------------------------------------------
1004
// :: disable
1005
// -------------------------------------------------------------------------
1006
test_type<Cmd>(cmd.disable());
1007
test_type<Cmd>(cmd.disable(true));
1008
// -------------------------------------------------------------------------
1009
// :: mask
1010
// -------------------------------------------------------------------------
1011
test_type<Cmd>(cmd.mask(true));
1012
test_type<Cmd>(cmd.mask("-"));
1013
test_type<string>(cmd.mask());
1014
test_type<boolean>(cmd.mask());
1015
});
1016
1017