/**
* @author Wolfgang Kowarschick <kowa@hs-augsburg.de>
* @copyright 2016-2018
* @license CC-BY-NC-SA-4.0
*/
/**
* @module wk/util/terminal.terminal
*/
const terminal =
{ /**
* Adds an paragraph to a HTML tag identified by <code>id="terminal"</code>.
* This paragraph contains the message passed via <code>p_message</code>.
* If an CSS class name is passed via the optional parameter <code>p_class</code>,
* it is prepended by <code>terminal_</code> and then added to the paragraph tag.
*
* @method writeLine
* @static
* @param {?string} p_message - the message to be displayed
* @param {string} [p_tag = 'p'] - the HTML tag that wraps the message
* @param {?string} p_class - the name of a CSS class that is added to the tag
*/
writeLine:
function (p_message = null, p_tag = 'p', p_class = null)
{ if (p_message === 'clear')
{ terminal.clear();
return;
}
let l_node = document.createElement(p_tag);
if (p_class != null)
l_node.classList.add(p_class);
if (p_message == null || p_message.length === 0)
{ l_node = document.createElement('pre');
p_message = ' ';
}
l_node.appendChild(document.createTextNode(p_message));
document.getElementById('terminal').appendChild(l_node);
},
/**
* Concatenates a list of messages passed a arguments to a single
* message and calls <code>writeLine</code> for that message.
*
* @function log
* @static
*/
log:
function()
{ terminal.writeLine(Array.prototype.slice.call(arguments).join(' ')); }
};
export {terminal};
export default terminal;