diff --git a/js/gui.js b/js/gui.js
index 9e7e46e660..8a95c88246 100644
--- a/js/gui.js
+++ b/js/gui.js
@@ -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
diff --git a/js/serial_backend.js b/js/serial_backend.js
index d08568ff7b..3ababf34be 100644
--- a/js/serial_backend.js
+++ b/js/serial_backend.js
@@ -1,5 +1,6 @@
var configuration_received = false;
var CLI_active = false;
+var CLI_valid = false;
var CONFIG = {
version: 0,
diff --git a/tabs/cli.js b/tabs/cli.js
index 633a9db4b8..6913c6b06a 100644
--- a/tabs/cli.js
+++ b/tabs/cli.js
@@ -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(/
/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 += "
";
- }
- break;
- case 13: // carriage return
- if (GUI.operating_system == "MacOS") {
- text += "
";
- }
- 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 += "
";
+ }
+ break;
+ case 13: // carriage return
+ if (GUI.operating_system == "MacOS") {
+ text += "
";
+ }
+ 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'
# ";
+ }
+
$('.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?
}