-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#30 This adds a line in the console to send Lua code directly to the …
…nodemcu. Handy in diagnosing and trying stuff out.
- Loading branch information
1 parent
2fc259a
commit a63864e
Showing
6 changed files
with
82 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Create a console to output data in visible in the UI. | ||
* @param output_element A DOM element to use for output. | ||
* @constructor | ||
*/ | ||
var OutputConsole = function (output_element) { | ||
this.output_element = output_element; | ||
this.lineTypedHandler = null; | ||
this.writeLine('Console initialised.'); | ||
}; | ||
|
||
/** | ||
* Write some data to the output. HTML is escaped. | ||
* @param data Data to write. | ||
*/ | ||
OutputConsole.prototype.write = function(data) { | ||
var safe_data = goog.string.htmlEscape(data); | ||
safe_data = goog.string.newLineToBr(safe_data); | ||
this.output_element.append(safe_data); | ||
}; | ||
|
||
/** | ||
* Write a line of data. | ||
* @param line | ||
*/ | ||
OutputConsole.prototype.writeLine = function(line) { | ||
this.write(line + '\n') | ||
}; | ||
|
||
/** | ||
* Set a handler for a line being typed. Only one handler allowed here. | ||
* @param handler The handler to call. Expects only a "line" parameter - a string of input. | ||
*/ | ||
OutputConsole.prototype.lineTyped = function(handler) { | ||
this.lineTypedHandler = handler; | ||
}; | ||
|
||
OutputConsole.prototype.setupInput = function(inputElement) { | ||
var _oc = this; | ||
inputElement.keypress(function(e) { | ||
/* If it's an enter key */ | ||
if(e.which == 13) { | ||
var line = inputElement.val(); | ||
_oc.lineTypedHandler(line + "\n"); | ||
inputElement.val(''); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters