1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-16 12:55:13 +03:00

some custom handling of ANSI escape codes

This commit is contained in:
cTn 2013-05-19 19:36:57 +02:00
parent b040b01be8
commit 906bc4230a

View file

@ -62,20 +62,40 @@ function leave_CLI(callback) {
Linux and Unix only understand LF
Windows understands (both) CRLF
*/
var sequence_elements = 0;
function handle_CLI(data) {
switch (data) {
case 10: // line feed
if (OS == "Windows" || OS == "Linux" || OS == "UNIX") {
$('.tab-cli .window .wrapper').append("<br />");
}
break;
case 13: // carriage return
if (OS == "MacOS") {
$('.tab-cli .window .wrapper').append("<br />");
}
break;
default:
$('.tab-cli .window .wrapper').append(String.fromCharCode(data));
$('.tab-cli .window').scrollTop($('.tab-cli .window .wrapper').height());
if (data == 27 || sequence_elements > 0) { // ESC + other
sequence_elements++;
// delete previous space
if (sequence_elements == 1) {
var content_string = $('.tab-cli .window .wrapper').html();
var new_string = content_string.substring(0, content_string.length -1);
$('.tab-cli .window .wrapper').html(new_string);
}
// Reset
if (sequence_elements >= 5) {
sequence_elements = 0;
}
}
if (sequence_elements == 0) {
switch (data) {
case 10: // line feed
if (OS == "Windows" || OS == "Linux" || OS == "UNIX") {
$('.tab-cli .window .wrapper').append("<br />");
}
break;
case 13: // carriage return
if (OS == "MacOS") {
$('.tab-cli .window .wrapper').append("<br />");
}
break;
default:
$('.tab-cli .window .wrapper').append(String.fromCharCode(data));
$('.tab-cli .window').scrollTop($('.tab-cli .window .wrapper').height());
}
}
}