Skip to content
Jakub T. Jankiewicz edited this page Oct 20, 2023 · 2 revisions

The Terminal uses a buffer similar to a real terminal or PHP with ob_ functions.

When you echo something it add the thing to buffer and flush immediately. But you can change that behavior with echo flush: false and explicit flush:

term.echo('Hello, there', {flush: false});
term.echo('Message from the dark side there is', {flush: false});
term.flush();

You can also echo stuff to buffer get the output and clear the buffer:

term.echo('Hello, there', {flush: false});
term.echo('Message from the dark side there is', {flush: false});
console.log(term.get_output_buffer());
/*
"Hello, there
Message from the dark side there is"
*/
term.clear_buffer();

You can also use formatters with buffers:

$.terminal.new_formatter([/(hello|message)/i, '[[;blue;]$1]']);

term.echo('Hello, there', {flush: false});
term.echo('Message from the dark side there is', {flush: false});
console.log(term.get_output_buffer());
/*
"[[;blue;]Hello], there
[[;blue;]Message] from the dark side there is"
*/
term.clear_buffer();

See Codepen demo