jquery-terminal

JQuery Terminal: How to echo without line break


Is it possible to echo without causing a line break? For example, say I wanted to have three dots appear one second after each other:

this.echo(".");
await sleep(1000);
this.echo(".");
await sleep(1000);
this.echo(".");

Currently that appears as:

.
.
.

however I need it to appear as:

...

Solution

  • With version 2.8.0 you can just use:

    <script src="https://unpkg.com/jquery.terminal@2.8.0/js/echo_newline.js"></script>
    

    it will add new option to echo (the script is monkey patch over echo but it's little bit better then the one in examples and it have unit test coverage).

    this.echo(".", {newline: false});
    await sleep(1000);
    this.echo(".", {newline: false});
    await sleep(1000);
    this.echo(".", {newline: false});
    

    then if you enter command "foo" you will:

    ...> foo
    > |
    

    and if you echo dot with newline (true is default) you will have:

    ....
    > |
    

    You can even use:

    term.echo('hello ', {newline: false});
    term.echo('foo\n', {newline: false});
    

    in future version I may introduce option newline for whole terminal that way you will always need to add \n for the terminal that have this option in (but you will still need that echo_newline.js file).

    EDIT: from version 2.31.0 echo newline: false is part of the library, no need to include additional files anymore.