tasks: handle carriage returns in task output

When we're running commands as part of a task that use carriage returns
(\r) to update the currently displayed line, we want to see the same
output in the web representation, so if we encounter a \r in the output
we need to look back to the last newline, truncate to that and then
start appending.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-04-09 11:20:54 +12:00
parent 51bf00c15a
commit 49bb85c944

View File

@ -61,7 +61,22 @@
url: '{{ log_url }}?start=' + posn,
success: function( data, code, xhr ) {
task_log = $("#task_log")
task_log.append(data);
if( data.indexOf('\r') > -1 ) {
orig = task_log.html();
for (var i = 0; i < data.length; i++) {
ch = data.charAt(i);
if( ch == '\r' ) {
orig = orig.substring(0, orig.lastIndexOf('\n')+1);
}
else {
orig += ch;
}
}
task_log.html(orig);
}
else {
task_log.append(data);
}
if(scrolling) {
task_log.animate({ scrollTop: task_log.prop('scrollHeight') }, "slow");
}