drop junk in input buffer before entering CLI

this could use some polishing but i think it will do for now
close #21
pull/3/head
cTn 11 years ago
parent c0937ddbd4
commit 39075c06ab

@ -228,7 +228,8 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) {
// we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched
// we could probably implement this someday
GUI.timeout_add('waiting_for_bootup', function() {
CLI_active = false;
CLI_active = false;
CLI_valid = false;
if (callback) callback();
}, 5000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one

@ -1,5 +1,6 @@
var configuration_received = false;
var CLI_active = false;
var CLI_valid = false;
var CONFIG = {
version: 0,

@ -72,11 +72,6 @@ function tab_initialize_cli() {
// give input element user focus
$('.tab-cli textarea').focus();
// if user clicks inside the console window, input element gets re-focused
$('.tab-cli .window').click(function() {
$('.tab-cli textarea').focus();
});
$('.tab-cli .copy').click(function() {
var text = $('.tab-cli .window .wrapper').html();
text = text.replace(/<br\s*\/?>/mg,"\n"); // replacing br tags with \n to keep some of the formating
@ -118,45 +113,58 @@ function send_slowly(out_arr, i, timeout_needle) {
*/
var sequence_elements = 0;
var CLI_validate_text = "";
function handle_CLI(readInfo) {
var data = new Uint8Array(readInfo.data);
var text = "";
for (var i = 0; i < data.length; i++) {
if (data[i] == 27 || sequence_elements > 0) { // ESC + other
sequence_elements++;
// delete previous space
if (sequence_elements == 1) {
text = text.substring(0, text.length -1);
if (CLI_valid) {
if (data[i] == 27 || sequence_elements > 0) { // ESC + other
sequence_elements++;
// delete previous space
if (sequence_elements == 1) {
text = text.substring(0, text.length -1);
}
// Reset
if (sequence_elements >= 5) {
sequence_elements = 0;
}
}
// Reset
if (sequence_elements >= 5) {
sequence_elements = 0;
}
}
if (sequence_elements == 0) {
switch (data[i]) {
case 10: // line feed
if (GUI.operating_system == "Windows" || GUI.operating_system == "Linux" || GUI.operating_system == "UNIX") {
text += "<br />";
}
break;
case 13: // carriage return
if (GUI.operating_system == "MacOS") {
text += "<br />";
}
break;
default:
text += String.fromCharCode(data[i]);
if (sequence_elements == 0) {
switch (data[i]) {
case 10: // line feed
if (GUI.operating_system == "Windows" || GUI.operating_system == "Linux" || GUI.operating_system == "UNIX") {
text += "<br />";
}
break;
case 13: // carriage return
if (GUI.operating_system == "MacOS") {
text += "<br />";
}
break;
default:
text += String.fromCharCode(data[i]);
}
}
} else {
// try to catch part of valid CLI enter message
CLI_validate_text += String.fromCharCode(data[i]);
}
char_counter++;
}
if (!CLI_valid && CLI_validate_text.indexOf('CLI') != -1) {
CLI_valid = true;
CLI_validate_text = "";
text = "Entering CLI Mode, type 'exit' to return, or 'help'<br /><br /># ";
}
$('.tab-cli .window .wrapper').append(text);
$('.tab-cli .window').scrollTop($('.tab-cli .window .wrapper').height()); // there seems to be some sort of initial rendering glitch in 33+, why?
}

Loading…
Cancel
Save