Path: blob/master/web-gui/buildyourownbotnet/assets/js/jquery-terminal/test.ts
1293 views
/// <reference path="./js/jquery.terminal.d.ts" />12import "jquery";3import "jquery.terminal";456function test_type<T>(x: T) {};7// -----------------------------------------------------------------------------8// :: instance9// -----------------------------------------------------------------------------1011$('.term').terminal(function(command, term) {1213});14$('.term').terminal(function(command) {1516});17$('.term').terminal([function(command, term) {18return Promise.resolve(document.createElement('div'));19}]);20$('.term').terminal("foo.php");21$('.term').terminal(["foo.php"]);22var obj_interpreter: JQueryTerminal.ObjectInterpreter = {23foo: function(...args) {24return $('<div/>');25},26bar: function(a, b) {27// user should typecheck the arguments in JavaScript28(<RegExp>a).test('x');29return Promise.resolve("foo");30},31baz: {32a: function() {33return document.createElement('canvas');34},35b: {36c: function() {37return "xxx";38}39}40}41};42$('.term').terminal([obj_interpreter]);43$('.term').terminal(["foo.php", obj_interpreter]);44$('.term').terminal(["foo.php", obj_interpreter, function(command) {45}]);4647class Foo {48x: string;49constructor(x: string) {50this.x = x;51}52}53// -----------------------------------------------------------------------------54// :: formatters55// -----------------------------------------------------------------------------56$.terminal.nested_formatting.__inherit__ = true;57$.terminal.nested_formatting.__warn__ = true;58$.terminal.nested_formatting.__meta__ = true;5960// -----------------------------------------------------------------------------61// :: Options62// -----------------------------------------------------------------------------63(function() {64// -------------------------------------------------------------------------65// :: prompt66// -------------------------------------------------------------------------67$('.term').terminal($.noop, {68prompt: function() {69return Promise.resolve(">>> ");70}71});72$('.term').terminal($.noop, {73prompt: ">>> "74});75$('.term').terminal($.noop, {76prompt: function(cb) {77cb(">>> ");78console.log(this.get_command());79}80});81// -------------------------------------------------------------------------82// :: keymap83// -------------------------------------------------------------------------84$('.term').terminal($.noop, {85keymap: {86'CTRL+C': function(e, original) {87console.log(e.target);88original(e);89}90}91});92// -------------------------------------------------------------------------93// :: exceptionHandler94// -------------------------------------------------------------------------95$('.term').terminal($.noop, {96exceptionHandler: function(e, label) {97test_type<JQueryTerminal>(this);98this.error(e.message);99}100});101// -------------------------------------------------------------------------102// :: onCommandChange103// -------------------------------------------------------------------------104$('.term').terminal($.noop, {105onCommandChange: function(command) {106test_type<JQueryTerminal>(this);107test_type<string>(command);108}109});110// -------------------------------------------------------------------------111// :: processRPCResponse112// -------------------------------------------------------------------------113$('.term').terminal($.noop, {114processRPCResponse: function(data) {115data.result = 10;116}117});118// -------------------------------------------------------------------------119// :: greetings120// -------------------------------------------------------------------------121$('.term').terminal($.noop, {122greetings: "hello"123});124$('.term').terminal($.noop, {125greetings: null126});127$('.term').terminal($.noop, {128greetings: function(cb) {129cb("hello");130}131});132$('.term').terminal($.noop, {133greetings: function() {134console.log(this.get_command());135return Promise.resolve("Hello");136}137});138// -------------------------------------------------------------------------139// :: scrollObject140// -------------------------------------------------------------------------141$('.term').terminal($.noop, {142scrollObject: "html"143});144$('.term').terminal($.noop, {145scrollObject: $("body")146});147$('.term').terminal($.noop, {148scrollObject: document.body149});150// -------------------------------------------------------------------------151// :: historyFilter152// -------------------------------------------------------------------------153$('.term').terminal($.noop, {154historyFilter: /^ /155});156$('.term').terminal($.noop, {157historyFilter: function(command) {158return !!command.match(/^ /);159}160});161// -------------------------------------------------------------------------162// :: login163// -------------------------------------------------------------------------164$('.term').terminal($.noop, {165login: true166});167$('.term').terminal($.noop, {168login: function(username, password) {169return Promise.resolve("TOKEN");170}171});172$('.term').terminal($.noop, {173login: function(username, password, cb) {174cb("TOKEN");175}176});177// -------------------------------------------------------------------------178// :: onAjaxError179// -------------------------------------------------------------------------180$('.term').terminal($.noop, {181onAjaxError: function(xhr, status, error) {182xhr.getAllResponseHeaders();183status.charCodeAt(0);184error.charCodeAt(0);185}186});187// -------------------------------------------------------------------------188// :: request189// -------------------------------------------------------------------------190$('.term').terminal($.noop, {191request: function(xhr, json, term) {192term.echo("foo");193}194});195$('.term').terminal($.noop, {196request: function(xhr, data) {197data.params.unshift("token");198this.echo(JSON.stringify(data));199var term = this;200xhr.then(function(value) {201term.echo(value);202});203}204});205// -------------------------------------------------------------------------206// :: response207// -------------------------------------------------------------------------208$('.term').terminal($.noop, {209response: function(xhr, data) {210data.result = 10;211this.echo(JSON.stringify(data));212var term = this;213xhr.then(function(value) {214term.echo(value);215});216}217});218// -------------------------------------------------------------------------219// :: onRPCError220// -------------------------------------------------------------------------221$('.term').terminal($.noop, {222onRPCError: function(error) {223this.echo(error.error.message);224}225});226// -------------------------------------------------------------------------227// :: doubleTab228// -------------------------------------------------------------------------229$('.term').terminal($.noop, {230doubleTab: function(str, matched, echo_Command) {231echo_Command();232this.echo(matched.slice(1).concat([str]));233}234});235// -------------------------------------------------------------------------236// :: completion237// -------------------------------------------------------------------------238$('.term').terminal($.noop, {239completion: ["foo", "bar", "baz"]240});241$('.term').terminal($.noop, {242completion: function(str, cb) {243str.charCodeAt(0);244cb(["foo", "bar", "baz"]);245}246});247// -------------------------------------------------------------------------248// :: Simple events249// -------------------------------------------------------------------------250$('.term').terminal($.noop, {251onInit: function(term) {252this.echo('event');253}254});255$('.term').terminal($.noop, {256onClear: function(term) {257this.echo('event');258}259});260$('.term').terminal($.noop, {261onBlur: function(term) {262this.echo('event');263}264});265$('.term').terminal($.noop, {266onFocus: function(term) {267this.echo('event');268}269});270$('.term').terminal($.noop, {271onExit: function(term) {272this.echo('event');273}274});275$('.term').terminal($.noop, {276onAfterRedraw: function(term) {277this.echo('event');278}279});280$('.term').terminal($.noop, {281onFlush: function(term) {282this.echo('event');283}284});285// -------------------------------------------------------------------------286// :: onPush287// -------------------------------------------------------------------------288$('.term').terminal($.noop, {289onPush: function(before, after) {290before.interpreter.call(this, "init", this);291}292});293// -------------------------------------------------------------------------294// :: onPush295// -------------------------------------------------------------------------296$('.term').terminal($.noop, {297onPop: function(before, after) {298before.interpreter.call(this, "init", this);299}300});301// -------------------------------------------------------------------------302// :: keypress303// -------------------------------------------------------------------------304$('.term').terminal($.noop, {305keypress: function(e) {306this.echo(e.key);307}308});309// -------------------------------------------------------------------------310// :: keydown311// -------------------------------------------------------------------------312$('.term').terminal($.noop, {313keydown: function(e) {314this.echo(e.key);315}316});317// -------------------------------------------------------------------------318// :: onEchoCommand319// -------------------------------------------------------------------------320$('.term').terminal($.noop, {321onEchoCommand: function(div, command) {322div.css('color', 'red');323this.echo(command.charCodeAt(0).toString());324}325});326// -------------------------------------------------------------------------327// :: renderHandler328// -------------------------------------------------------------------------329$('.term').terminal($.noop, {330renderHandler: function(value) {331// value here is any you should typecheck the value in JS332// and return string, DOM node or jQuery object333if (value instanceof Foo) {334return $('<span>' + value.x + '</span>');335}336if (value === true) {337this.echo('true value');338return false;339}340if (value === false) {341var div = document.createElement('div');342div.innerHTML = 'false value';343return div;344}345}346});347});348349// -----------------------------------------------------------------------------350// :: Methods351// -----------------------------------------------------------------------------352(function() {353var term = $('.term').terminal();354// -------------------------------------------------------------------------355// :: id356// -------------------------------------------------------------------------357test_type<number>(term.id());358// -------------------------------------------------------------------------359// :: clear360// -------------------------------------------------------------------------361term.clear().clear();362// -------------------------------------------------------------------------363// :: import/export364// -------------------------------------------------------------------------365term.import_view(term.export_view());366// -------------------------------------------------------------------------367// :: save_state368// -------------------------------------------------------------------------369term.save_state("foo");370term.save_state("foo", true);371term.save_state("foo", undefined, 10);372term.save_state("foo", false, 10);373// -------------------------------------------------------------------------374// :: exec375// -------------------------------------------------------------------------376term.exec("foo");377term.exec("foo", true);378term.exec("foo", true, jQuery.Deferred()).then(function() {379});380// -------------------------------------------------------------------------381// :: autologin382// -------------------------------------------------------------------------383term.autologin("username", "TOKEN").clear();384term.autologin("username", "TOKEN", true).clear();385// -------------------------------------------------------------------------386// :: login387// -------------------------------------------------------------------------388term.login(function(username, password, callback) {389390}).clear();391term.login(function(username, password) {392393}).clear();394term.login(function(username, password) {395396}, true, () => {}).clear();397term.login(function(username, password) {398399}, undefined, () => {}).clear();400term.login(function(username, password) {401402}, true, () => {}, () => {}).clear();403// -------------------------------------------------------------------------404// :: settings405// -------------------------------------------------------------------------406term.before_cursor().charCodeAt(0);407term.before_cursor(true).charCodeAt(0);408// -------------------------------------------------------------------------409// ::410// -------------------------------------------------------------------------411term.set_interpreter(function(command) {412});413term.set_interpreter(function(command, term) {414415});416term.set_interpreter(function(command) {417418});419term.set_interpreter([function(command, term) {420421}]);422term.set_interpreter("foo.php");423term.set_interpreter(["foo.php"]);424term.set_interpreter([obj_interpreter]);425term.set_interpreter(["foo.php", obj_interpreter]);426term.set_interpreter(["foo.php", obj_interpreter, function(command) {427}]);428term.set_interpreter("foo.php", true);429term.set_interpreter("foo.php", "login");430term.set_interpreter("foo.php", function(user, password) {431});432term.set_interpreter("foo.php", function(user, password, cb) {433cb("Foo");434});435// -------------------------------------------------------------------------436// :: greetings437// -------------------------------------------------------------------------438term.greetings().echo("foo");439// -------------------------------------------------------------------------440// :: paused441// -------------------------------------------------------------------------442test_type<boolean>(term.paused());443// -------------------------------------------------------------------------444// :: pause445// -------------------------------------------------------------------------446term.pause().echo("foo");447// -------------------------------------------------------------------------448// :: resume449// -------------------------------------------------------------------------450term.resume().echo("foo");451// -------------------------------------------------------------------------452// :: cols453// -------------------------------------------------------------------------454test_type<number>(term.cols());455// -------------------------------------------------------------------------456// :: rows457// -------------------------------------------------------------------------458test_type<number>(term.rows());459// -------------------------------------------------------------------------460// :: history461// -------------------------------------------------------------------------462test_type<JQueryTerminal.History<string>>(term.history())463// -------------------------------------------------------------------------464// :: history_state465// -------------------------------------------------------------------------466term.history_state(true).echo("foo");467// -------------------------------------------------------------------------468// :: clear_history_state469// -------------------------------------------------------------------------470term.clear_history_state().echo("foo");471// -------------------------------------------------------------------------472// :: next473// -------------------------------------------------------------------------474term.next().echo("foo");475// -------------------------------------------------------------------------476// :: focus477// -------------------------------------------------------------------------478term.focus().echo("foo");479term.focus(true).echo("foo");480// -------------------------------------------------------------------------481// :: freeze482// -------------------------------------------------------------------------483term.freeze().echo("foo");484term.freeze(true).echo("foo");485// -------------------------------------------------------------------------486// :: fronzen487// -------------------------------------------------------------------------488test_type<boolean>(term.frozen());489// -------------------------------------------------------------------------490// :: enable491// -------------------------------------------------------------------------492term.enable().echo("foo");493term.enable(true);494// -------------------------------------------------------------------------495// :: disable496// -------------------------------------------------------------------------497term.disable().echo("foo");498term.disable(true);499// -------------------------------------------------------------------------500// :: enabled501// -------------------------------------------------------------------------502test_type<boolean>(term.enabled());503// -------------------------------------------------------------------------504// :: signature505// -------------------------------------------------------------------------506test_type<string>(term.signature());507// -------------------------------------------------------------------------508// :: version509// -------------------------------------------------------------------------510test_type<string>(term.version());511// -------------------------------------------------------------------------512// :: cmd513// -------------------------------------------------------------------------514test_type<Cmd>(term.cmd());515// -------------------------------------------------------------------------516// :: get_command517// -------------------------------------------------------------------------518test_type<string>(term.get_command());519// -------------------------------------------------------------------------520// :: set_command521// -------------------------------------------------------------------------522term.set_command("foo").echo("foo");523term.set_command("foo", true);524// -------------------------------------------------------------------------525// :: get_position526// -------------------------------------------------------------------------527test_type<number>(term.get_position());528// -------------------------------------------------------------------------529// :: insert530// -------------------------------------------------------------------------531test_type<JQueryTerminal>(term.insert("foo"));532term.insert("foo", true);533// -------------------------------------------------------------------------534// :: set_prompt535// -------------------------------------------------------------------------536test_type<JQueryTerminal>(term.set_prompt(">>> "));537term.set_prompt(function(cb) {538cb(">>> ");539this.get_command();540});541term.set_prompt(function() {542this.get_command();543return Promise.resolve(">>> ");544});545// -------------------------------------------------------------------------546// :: get_prompt547// -------------------------------------------------------------------------548var fn: (cb: (prompt: string) => void) => void = term.get_prompt();549var prompt: string = term.get_prompt();550// -------------------------------------------------------------------------551// :: set_mask552// -------------------------------------------------------------------------553test_type<JQueryTerminal>(term.set_mask(true));554term.set_mask("-");555// -------------------------------------------------------------------------556// :: get_output557// -------------------------------------------------------------------------558test_type<string[]>(term.get_output());559var lines: JQueryTerminal.Lines = term.get_output();560test_type<number>(lines[0].index);561var div = $('<div/>');562lines[0].options.finalize.call(term, div);563lines[0].options.onClear.call(term, div);564lines[0].options.unmount.call(term, div);565// -------------------------------------------------------------------------566// :: resize567// -------------------------------------------------------------------------568test_type<JQueryTerminal>(term.resize());569term.resize(100);570term.resize(100, 200);571// -------------------------------------------------------------------------572// :: refresh573// -------------------------------------------------------------------------574test_type<JQueryTerminal>(term.refresh());575// -------------------------------------------------------------------------576// :: flush577// -------------------------------------------------------------------------578test_type<JQueryTerminal>(term.flush());579term.flush({update: true});580term.flush({scroll: true});581// -------------------------------------------------------------------------582// :: update583// -------------------------------------------------------------------------584test_type<JQueryTerminal>(term.update(10, ">>>"));585term.update(10, ">>>", {586finalize: function(div) {587div.css('color', 'red');588}589});590// -------------------------------------------------------------------------591// :: remove_line592// -------------------------------------------------------------------------593test_type<JQueryTerminal>(term.remove_line(10));594// -------------------------------------------------------------------------595// :: echo596// -------------------------------------------------------------------------597term.echo("foo");598term.echo(["foo", "bar"]);599term.echo(function(): string {600return "foo";601});602term.echo(function(): string[] {603return ["foo", "bar"];604});605term.echo(Promise.resolve("foo"));606term.echo(Promise.resolve(["foo"]));607term.echo(Promise.resolve(function(): string {608return "foo";609}));610term.echo(Promise.resolve(function(): string[] {611return ["foo"];612}));613// add in version 2.9.0614term.echo(document.createElement('div'));615term.echo($('<div/>'));616term.echo($(document.createElement('div')));617// special case when Foo class is processed by renderHandler618// this is wordaround since echo can accept anything619term.echo<Foo>(new Foo('hello'));620// function options621term.echo(document.createElement('canvas'), {622onClear: function(div) {623div.find('canvas');624console.log(this.get_command());625(div[0] as any).pause = true;626},627unmount: function(div) {628div.find('canvas');629console.log(this.get_command());630},631finalize: function(div) {632div.find('canvas');633console.log(this.get_command());634var canvas = <HTMLCanvasElement>(div.find('cavas')[0]);635canvas.width = canvas.height = 100;636var ctx = canvas.getContext("2d");637if (ctx === null) {638return;639}640ctx.clearRect(0, 0, 100, 100);641ctx.fillStyle = "#00FF00";642ctx.fillRect(10, 10, 90, 90);643}644});645// -------------------------------------------------------------------------646// :: error647// -------------------------------------------------------------------------648test_type<JQueryTerminal>(term.error("foo"));649term.error(function() {650return "foo";651});652term.error(Promise.resolve("foo"), {653finalize: function(div) {654div.addClass('error-string');655}656});657// -------------------------------------------------------------------------658// :: exception659// -------------------------------------------------------------------------660var e = new $.terminal.Exception("error");661test_type<JQueryTerminal>(term.exception(e));662term.exception(e, "ERROR");663// -------------------------------------------------------------------------664// :: scroll665// -------------------------------------------------------------------------666test_type<JQueryTerminal>(term.scroll(10));667// -------------------------------------------------------------------------668// :: logout669// -------------------------------------------------------------------------670test_type<JQueryTerminal>(term.logout());671term.logout(true);672// -------------------------------------------------------------------------673// :: token674// -------------------------------------------------------------------------675test_type<string>(term.token());676term.token(true);677// -------------------------------------------------------------------------678// :: set_token679// -------------------------------------------------------------------------680test_type<JQueryTerminal>(term.set_token("foo"));681term.set_token("foo", true);682// -------------------------------------------------------------------------683// :: get_token684// -------------------------------------------------------------------------685test_type<string>(term.get_token());686term.get_token(true);687// -------------------------------------------------------------------------688// :: login_name689// -------------------------------------------------------------------------690test_type<string>(term.login_name());691term.login_name(true);692// -------------------------------------------------------------------------693// :: name694// -------------------------------------------------------------------------695test_type<string>(term.name());696// -------------------------------------------------------------------------697// :: prefix_name698// -------------------------------------------------------------------------699test_type<string>(term.prefix_name());700test_type<string>(term.prefix_name(true));701// -------------------------------------------------------------------------702// :: read703// -------------------------------------------------------------------------704term.read("foo", function(s) {705s.charCodeAt(0);706}).then(function(s) {707s.charCodeAt(0);708});709// -------------------------------------------------------------------------710// :: push711// -------------------------------------------------------------------------712term.push(function(command) {713});714term.push(function(command, term) {715716});717term.push(function(command) {718719});720term.push([function(command, term) {721722}]);723term.push("foo.php");724term.push(["foo.php"]);725term.push([obj_interpreter]);726term.push(["foo.php", obj_interpreter]);727term.push(["foo.php", obj_interpreter, function(command) {728}]);729term.push("foo", {730login: true731});732term.push("foo", {733infiniteLogin: true734});735term.push("foo", {736prompt: "foo"737});738term.push("foo", {739prompt: function(cb) {740cb("foo");741var s: string = this.get_command();742}743});744term.push("foo", {745login: function(username, password, cb) {746cb('TOKEN');747}748});749term.push("foo", {750completion: ["foo", "bar", "baz"]751});752term.push("foo", {753completion: function(str, cb) {754str.charCodeAt(0);755cb(["foo", "bar", "baz"]);756}757});758// -------------------------------------------------------------------------759// :: pop760// -------------------------------------------------------------------------761test_type<JQueryTerminal>(term.pop());762term.pop("foo");763term.pop("foo", true);764// -------------------------------------------------------------------------765// :: option766// -------------------------------------------------------------------------767var option: string = term.option('name');768term.option({769completion: ["foo"]770});771term.option("completion", ["foo"]);772// -------------------------------------------------------------------------773// :: invoke_key774// -------------------------------------------------------------------------775test_type<JQueryTerminal>(term.invoke_key("CTRL+C"));776// -------------------------------------------------------------------------777// :: keymap778// -------------------------------------------------------------------------779var keymap_fn: (e: JQueryKeyEventObject) => any = term.keymap('CTRL+K');780var keymap = term.keymap();781keymap['CTRL+C']($.Event("keypress"));782term.keymap("CTRL+C")($.Event("keypress"));783term.keymap("CTRL+C", keymap_fn);784term.keymap(keymap);785// -------------------------------------------------------------------------786// :: level787// -------------------------------------------------------------------------788test_type<number>(term.level());789// -------------------------------------------------------------------------790// :: reset791// -------------------------------------------------------------------------792test_type<JQueryTerminal>(term.reset());793// -------------------------------------------------------------------------794// :: purge795// -------------------------------------------------------------------------796test_type<JQueryTerminal>(term.purge());797// -------------------------------------------------------------------------798// :: destroy799// -------------------------------------------------------------------------800test_type<JQueryTerminal>(term.destroy());801// -------------------------------------------------------------------------802// :: scroll_to_bottom803// -------------------------------------------------------------------------804test_type<JQueryTerminal>(term.scroll_to_bottom());805// -------------------------------------------------------------------------806// :: is_bottom807// -------------------------------------------------------------------------808test_type<boolean>(term.is_bottom());809});810811812// -----------------------------------------------------------------------------813// :: CMD814// -----------------------------------------------------------------------------815// -----------------------------------------------------------------------------816// :: Options817// -----------------------------------------------------------------------------818(function() {819// -------------------------------------------------------------------------820// :: prompt821// -------------------------------------------------------------------------822test_type<Cmd>($('.cmd').cmd());823$('<div/>').cmd({824prompt: ">>> "825});826$('<div/>').cmd({827prompt: function(cb) {828cb(">>> ");829}830});831// -------------------------------------------------------------------------832// :: onPositionChange833// -------------------------------------------------------------------------834$('.cmd').cmd({835onPositionChange: function(position) {836test_type<number>(position);837}838});839$('.cmd').cmd({840onPositionChange: function(position, display_pos) {841test_type<number>(display_pos);842}843});844// -------------------------------------------------------------------------845// :: historyFilter846// -------------------------------------------------------------------------847$('.cmd').cmd({848historyFilter: /^ /849});850$('.cmd').cmd({851historyFilter: function(command) {852return !!command.match(/^ /);853}854});855// -------------------------------------------------------------------------856// :: commands857// -------------------------------------------------------------------------858$('.cmd').cmd({859commands: function(command) {860test_type<Cmd>(this);861test_type<string>(command);862}863});864// -------------------------------------------------------------------------865// :: onCommandChange866// -------------------------------------------------------------------------867$('.cmd').cmd({868onCommandChange: function(command) {869test_type<Cmd>(this);870test_type<string>(command);871}872});873// -------------------------------------------------------------------------874// :: keypress875// -------------------------------------------------------------------------876$('.cmd').cmd({877keypress: function(e) {878test_type<Cmd>(this);879var name: string = e.target.nodeName;880}881});882// -------------------------------------------------------------------------883// :: keydown884// -------------------------------------------------------------------------885$('.cmd').cmd({886keydown: function(e) {887test_type<Cmd>(this);888var name: string = e.target.nodeName;889}890});891});892893// -----------------------------------------------------------------------------894// :: Methods895// -----------------------------------------------------------------------------896(function() {897var cmd = $('.cmd').cmd();898// -------------------------------------------------------------------------899// :: option900// -------------------------------------------------------------------------901test_type<Cmd>(cmd.option("mask", 10));902test_type<string>(cmd.option("mask"));903// -------------------------------------------------------------------------904// :: name905// -------------------------------------------------------------------------906test_type<string>(cmd.name());907test_type<Cmd>(cmd.name("foo"));908// -------------------------------------------------------------------------909// :: purge910// -------------------------------------------------------------------------911test_type<Cmd>(cmd.purge());912// -------------------------------------------------------------------------913// :: history914// -------------------------------------------------------------------------915test_type<JQueryTerminal.History<string>>(cmd.history());916cmd.history().next();917// -------------------------------------------------------------------------918// :: delete919// -------------------------------------------------------------------------920test_type<string>(cmd.delete(10));921test_type<string>(cmd.delete(10, true));922// -------------------------------------------------------------------------923// :: set924// -------------------------------------------------------------------------925test_type<Cmd>(cmd.set("foo"));926test_type<Cmd>(cmd.set("foo", true));927test_type<Cmd>(cmd.set("foo", true, true));928// -------------------------------------------------------------------------929// :: keymap930// -------------------------------------------------------------------------931var keymap_fn: (e: JQueryKeyEventObject) => any = cmd.keymap('CTRL+K');932var keymap = cmd.keymap();933keymap['CTRL+C']($.Event("keypress"));934cmd.keymap("CTRL+C")($.Event("keypress"));935cmd.keymap("CTRL+C", keymap_fn);936cmd.keymap(keymap);937// -------------------------------------------------------------------------938// :: insert939// -------------------------------------------------------------------------940test_type<Cmd>(cmd.insert("foo"));941test_type<Cmd>(cmd.insert("foo", true));942// -------------------------------------------------------------------------943// :: get944// -------------------------------------------------------------------------945test_type<string>(cmd.get<string>());946// -------------------------------------------------------------------------947// :: commands948// -------------------------------------------------------------------------949cmd.commands()("foo");950test_type<Cmd>(cmd.commands(function(command) {951this.display_position();952test_type<string>(command);953}));954// -------------------------------------------------------------------------955// :: destroy956// -------------------------------------------------------------------------957test_type<Cmd>(cmd.destroy());958// -------------------------------------------------------------------------959// :: prompt960// -------------------------------------------------------------------------961var fn: (cb: (prompt: string) => void) => void = cmd.prompt();962var prompt: string = cmd.prompt();963964test_type<Cmd>(cmd.prompt(function(cb) {965this.display_position();966cb(">>> ");967}));968test_type<Cmd>(cmd.prompt(">>> "));969test_type<string>(cmd.prompt(true));970// -------------------------------------------------------------------------971// :: position972// -------------------------------------------------------------------------973test_type<number>(cmd.position<number>());974test_type<Cmd>(cmd.position(10));975test_type<Cmd>(cmd.position(10, true));976// -------------------------------------------------------------------------977// :: refresh978// -------------------------------------------------------------------------979test_type<Cmd>(cmd.refresh());980// -------------------------------------------------------------------------981// :: display_postion982// -------------------------------------------------------------------------983test_type<number>(cmd.display_position());984test_type<Cmd>(cmd.display_position(10));985// -------------------------------------------------------------------------986// :: show987// -------------------------------------------------------------------------988test_type<Cmd>(cmd.show());989// -------------------------------------------------------------------------990// :: resize991// -------------------------------------------------------------------------992test_type<Cmd>(cmd.resize());993test_type<Cmd>(cmd.resize(100));994// -------------------------------------------------------------------------995// :: enable996// -------------------------------------------------------------------------997test_type<Cmd>(cmd.enable());998// -------------------------------------------------------------------------999// :: isenabled1000// -------------------------------------------------------------------------1001test_type<boolean>(cmd.isenabled());1002// -------------------------------------------------------------------------1003// :: disable1004// -------------------------------------------------------------------------1005test_type<Cmd>(cmd.disable());1006test_type<Cmd>(cmd.disable(true));1007// -------------------------------------------------------------------------1008// :: mask1009// -------------------------------------------------------------------------1010test_type<Cmd>(cmd.mask(true));1011test_type<Cmd>(cmd.mask("-"));1012test_type<string>(cmd.mask());1013test_type<boolean>(cmd.mask());1014});101510161017