0

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:

...
sg-
  • 2,196
  • 1
  • 15
  • 16
  • 1
    This is not possible out of the box, there is hack (very hacky) that allow to have echo without newline (in examples) but this should be used if you really have to, it's not nice code. This was asked multiple times by users and the answer is that it's fundamental architecture change, because I don't want to have that hack in the library. – jcubic Jul 31 '19 at 15:07

1 Answers1

1

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).

jcubic
  • 61,973
  • 54
  • 229
  • 402