Im trying to get a echo command to echo what the user types in a JQuery termial.
This is the code I have
<link href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/jquery.terminal/js/jquery.terminal.min.js"></script>
<script>
$('body').terminal({
echo: function(...args) {
this.echo(args)
},
}, {
checkArity: false,
prompt: '>>> ',
strings: {
commandNotFound: "-Error: unknown command: %s",
echoCommand: true,
wrongArity: "'%s' is missing one or more arguments",
},
pasteImage: true,
});
</script>
I tried to use the ...args method but when I do that, it will display what I typed, but add a bunch of spaces between them. For example, if i type: "echo hi bro how are you :)" it will return what I said in a this.echo saying the same thing but with 4 spaces between each word.
How can I remove those spaces so that it will directly show what the user typed.
Looking at the jQuery Terminal library, it looks like it behaves as expected.
Whatever you type after your command is considered an argument. The echo function of jQuery terminal converts that object to a readable output (tab separated).
If you type the following, each word is considered an argument of the echo command
You either have to quote the text you want to echo, just like any terminal.
Or you have to join all your arguments, but it deduped spaces between words.
This will product the following outputs