|
7 | 7 | * \/ /____/ version {{VER}}
|
8 | 8 | *
|
9 | 9 | * This file is part of jQuery Terminal. http://terminal.jcubic.pl
|
10 |
| - * Copyright (c) 2010-2018 Jakub Jankiewicz <http://jcubic.pl/me> |
| 10 | + * Copyright (c) 2010-2022 Jakub T. Jankiewicz <http://jcubic.pl/me> |
11 | 11 | * Released under the MIT license
|
12 | 12 | *
|
13 | 13 | * Image Credit: Author Peter Hamer, source Wikipedia
|
@@ -251,6 +251,9 @@ require('../js/pipe')(global.$);
|
251 | 251 | require('../js/autocomplete_menu')(global.$);
|
252 | 252 | require('../js/less')(global.$);
|
253 | 253 |
|
| 254 | +// this is needed for testing less plugin |
| 255 | +global.$.terminal.defaults.imagePause = false; |
| 256 | + |
254 | 257 | var fs = require('fs');
|
255 | 258 | var util = require('util');
|
256 | 259 | fs.readFileAsync = util.promisify(fs.readFile);
|
@@ -678,6 +681,18 @@ describe('Terminal utils', function() {
|
678 | 681 | expect($.terminal.substring(input, spec[0], 200)).toEqual(spec[1]);
|
679 | 682 | });
|
680 | 683 | });
|
| 684 | + it('should partition the string with brackets outside of formatting', function() { |
| 685 | + // issue #792 |
| 686 | + var text = "[this] is some [[random]] text [[;red;]hello], [[world]]"; |
| 687 | + var len = $.terminal.length(text); |
| 688 | + var result = []; |
| 689 | + for (var i = 0; i < len; ++i) { |
| 690 | + result.push($.terminal.substring(text, i,i+1)); |
| 691 | + } |
| 692 | + for (let str of result) { |
| 693 | + expect($.terminal.length(str)).toEqual(1); |
| 694 | + } |
| 695 | + }); |
681 | 696 | it('should return substring when input starts from normal text', function() {
|
682 | 697 | var input = 'Lorem Ipsum [[;;]Dolor]';
|
683 | 698 | expect($.terminal.substring(input, 10, 200)).toEqual('m [[;;]Dolor]');
|
@@ -5075,6 +5090,14 @@ describe('Terminal plugin', function() {
|
5075 | 5090 | await term.insert('_world', { typing: true, delay: 0});
|
5076 | 5091 | expect(term.get_command()).toEqual('hello_world');
|
5077 | 5092 | });
|
| 5093 | + // issue #797 |
| 5094 | + it('should resolve animation after async command', async () => { |
| 5095 | + term.echo(delay(0, () => "A")); |
| 5096 | + const fn = jest.fn(); |
| 5097 | + term.echo("B", { typing: true, delay: 0 }).then(fn); |
| 5098 | + await delay(200); |
| 5099 | + expect(fn).toHaveBeenCalled(); |
| 5100 | + }); |
5078 | 5101 | });
|
5079 | 5102 |
|
5080 | 5103 | describe('exec', function() {
|
@@ -5716,72 +5739,68 @@ describe('Terminal plugin', function() {
|
5716 | 5739 | });
|
5717 | 5740 | it('should flush correctly with newline : false', function(){
|
5718 | 5741 | var term = $('<div/>').terminal($.noop, {
|
5719 |
| - greetings : "greet" |
| 5742 | + greetings : 'greet' |
5720 | 5743 | });
|
5721 |
| - var cmd = term.find(".cmd"); |
| 5744 | + var cmd = term.find('.cmd'); |
5722 | 5745 |
|
5723 |
| - expect(term.find(".partial")[0]).toEqual(undefined); |
5724 |
| - expect(term.find("[data-index='0']").text()).toEqual("greet"); |
| 5746 | + expect(term.find('.partial')[0]).toEqual(undefined); |
| 5747 | + expect(term.find('[data-index="0"]').text()).toEqual('greet'); |
5725 | 5748 |
|
5726 | 5749 | function getLastLineRect(partial){
|
5727 | 5750 | let child = partial[0].lastElementChild;
|
5728 |
| - child.style.width = ""; |
| 5751 | + child.style.width = ''; |
5729 | 5752 | let rect = child.getBoundingClientRect();
|
5730 |
| - child.style.width = "100%"; |
| 5753 | + child.style.width = '100%'; |
5731 | 5754 | return rect;
|
5732 | 5755 | }
|
5733 | 5756 |
|
5734 |
| - term.echo("###", {newline : false}); |
| 5757 | + term.echo('###', {newline : false}); |
5735 | 5758 |
|
5736 |
| - var prompt = term.find(".cmd-prompt"); |
5737 |
| - var partial = term.find(".partial"); |
| 5759 | + var prompt = term.find('.cmd-prompt'); |
| 5760 | + var partial = term.find('.partial'); |
5738 | 5761 | var partial_children = partial.children();
|
5739 | 5762 | var last_line_rect = getLastLineRect(partial);
|
5740 |
| - expect(partial.attr("data-index")).toEqual("1"); |
| 5763 | + expect(partial.attr('data-index')).toEqual('1'); |
5741 | 5764 | expect(partial_children.length).toEqual(1);
|
5742 |
| - expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`); |
5743 |
| - expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`); |
5744 |
| - expect(partial_children.first().text()).toEqual("###"); |
| 5765 | + expect(cmd.css('top')).toEqual(`${-last_line_rect.height}px`); |
| 5766 | + expect(partial_children.first().text()).toEqual('###'); |
5745 | 5767 |
|
5746 |
| - term.echo("aaa\nbbb\nccc", {newline : false}); |
| 5768 | + term.echo('aaa\nbbb\nccc', {newline : false}); |
5747 | 5769 |
|
5748 |
| - prompt = term.find(".cmd-prompt"); |
5749 |
| - partial = term.find(".partial"); |
| 5770 | + prompt = term.find('.cmd-prompt'); |
| 5771 | + partial = term.find('.partial'); |
5750 | 5772 | partial_children = partial.children();
|
5751 | 5773 | last_line_rect = getLastLineRect(partial);
|
5752 |
| - expect(partial.attr("data-index")).toEqual("1"); |
| 5774 | + expect(partial.attr('data-index')).toEqual('1'); |
5753 | 5775 | expect(partial_children.length).toEqual(3);
|
5754 |
| - expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`); |
5755 |
| - expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`); |
5756 |
| - expect(partial_children.eq(0).text()).toEqual("###aaa"); |
5757 |
| - expect(partial_children.eq(1).text()).toEqual("bbb"); |
5758 |
| - expect(partial_children.eq(2).text()).toEqual("ccc"); |
| 5776 | + expect(cmd.css('top')).toEqual(`${-last_line_rect.height}px`); |
| 5777 | + expect(partial_children.eq(0).text()).toEqual('###aaa'); |
| 5778 | + expect(partial_children.eq(1).text()).toEqual('bbb'); |
| 5779 | + expect(partial_children.eq(2).text()).toEqual('ccc'); |
5759 | 5780 | term.refresh();
|
5760 | 5781 |
|
5761 |
| - prompt = term.find(".cmd-prompt"); |
5762 |
| - partial = term.find(".partial"); |
| 5782 | + prompt = term.find('.cmd-prompt'); |
| 5783 | + partial = term.find('.partial'); |
5763 | 5784 | partial_children = partial.children();
|
5764 | 5785 | last_line_rect = getLastLineRect(partial);
|
5765 |
| - expect(partial.attr("data-index")).toEqual("1"); |
| 5786 | + expect(partial.attr('data-index')).toEqual('1'); |
5766 | 5787 | expect(partial_children.length).toEqual(3);
|
5767 |
| - expect(cmd.css("top")).toEqual(`${-last_line_rect.height}px`); |
5768 |
| - expect(prompt[0].style.marginLeft).toEqual(`${last_line_rect.width}px`); |
5769 |
| - expect(partial_children.eq(0).text()).toEqual("###aaa"); |
5770 |
| - expect(partial_children.eq(1).text()).toEqual("bbb"); |
5771 |
| - expect(partial_children.eq(2).text()).toEqual("ccc"); |
| 5788 | + expect(cmd.css('top')).toEqual(`${-last_line_rect.height}px`); |
| 5789 | + expect(partial_children.eq(0).text()).toEqual('###aaa'); |
| 5790 | + expect(partial_children.eq(1).text()).toEqual('bbb'); |
| 5791 | + expect(partial_children.eq(2).text()).toEqual('ccc'); |
5772 | 5792 |
|
5773 |
| - enter(term, "!!!"); |
| 5793 | + enter(term, '!!!'); |
5774 | 5794 |
|
5775 |
| - prompt = term.find(".cmd-prompt"); |
5776 |
| - expect(cmd.css("top")).toEqual(`0px`); |
5777 |
| - expect(prompt[0].style.marginLeft).toEqual(`0px`); |
5778 |
| - expect(term.find("[data-index='1']").length).toEqual(1); |
5779 |
| - expect(term.find("[data-index='1']").children().last().text()).toEqual(nbsp("ccc> !!!")); |
5780 |
| - expect(term.find(".partial")[0]).toEqual(undefined); |
| 5795 | + prompt = term.find('.cmd-prompt'); |
| 5796 | + expect(cmd.css('top')).toEqual(''); |
| 5797 | + expect(term.find('[data-index="1"]').length).toEqual(1); |
| 5798 | + expect(term.find('[data-index="1"]').children().last().text()).toEqual(nbsp('ccc> !!!')); |
| 5799 | + expect(term.find('.partial')[0]).toEqual(undefined); |
5781 | 5800 |
|
5782 | 5801 | term.refresh();
|
5783 |
| - expect(term.find("[data-index='1']").length).toEqual(1); |
5784 |
| - expect(term.find("[data-index='1']").children().last().text()).toEqual(nbsp("ccc> !!!")); |
| 5802 | + expect(term.find('[data-index="1"]').length).toEqual(1); |
| 5803 | + expect(term.find('[data-index="1"]').children().last().text()).toEqual(nbsp('ccc> !!!')); |
5785 | 5804 | });
|
5786 | 5805 | });
|
5787 | 5806 | describe('output_buffer', function() {
|
|
0 commit comments