From df556ad1bdbacc414d4ac9c23361875a09985314 Mon Sep 17 00:00:00 2001 From: Chris Charles Date: Tue, 16 May 2017 08:11:32 +0100 Subject: [PATCH] cli output save button --- _locales/en/messages.json | 4 +++- tabs/cli.css | 4 ++++ tabs/cli.html | 3 +++ tabs/cli.js | 42 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 04bd7aba..9049c409 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1366,7 +1366,9 @@ "cliReboot": { "message": "CLI reboot detected" }, - + "cliSaveToFileBtn": { + "message": "Save" + }, "loggingNote": { "message": "Data will be logged in this tab only, leaving the tab will cancel logging and application will return to its normal \"configurator\" state.
You are free to select the global update period, data will be written into the log file every 1 second for performance reasons." }, diff --git a/tabs/cli.css b/tabs/cli.css index 0b14cc53..a82a2e97 100644 --- a/tabs/cli.css +++ b/tabs/cli.css @@ -59,4 +59,8 @@ .tab-cli .window .wrapper { white-space: pre-wrap; +} + +.tab-cli .save { + color: white; } \ No newline at end of file diff --git a/tabs/cli.html b/tabs/cli.html index 19872413..7026b51b 100644 --- a/tabs/cli.html +++ b/tabs/cli.html @@ -5,6 +5,9 @@

+
+ +
diff --git a/tabs/cli.js b/tabs/cli.js index 5cdd3935..4072ede3 100644 --- a/tabs/cli.js +++ b/tabs/cli.js @@ -5,7 +5,8 @@ TABS.cli = { 'currentLine': "", 'sequenceElements': 0, lineDelayMs: 15, - profileSwitchDelayMs: 100 + profileSwitchDelayMs: 100, + outputHistory: "" }; TABS.cli.initialize = function (callback) { @@ -15,6 +16,8 @@ TABS.cli.initialize = function (callback) { GUI.active_tab = 'cli'; } + self.outputHistory = ""; + $('#content').load("./tabs/cli.html", function () { // translate to user-selected language localize(); @@ -23,6 +26,42 @@ TABS.cli.initialize = function (callback) { var textarea = $('.tab-cli textarea'); + $('.tab-cli .save').click(function() { + + var prefix = 'cli'; + var suffix = 'txt'; + + var filename = generateFilename(prefix, suffix); + + var accepts = [{ + extensions: [suffix], + }]; + + chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, accepts: accepts}, function(entry) { + if (chrome.runtime.lastError) { + console.error(chrome.runtime.lastError.message); + return; + } + + if (!entry) { + console.log('No file selected'); + return; + } + + entry.createWriter(function(writer) { + writer.onerror = function (){ + console.error('Failed to write file'); + }; + writer.onwriteend = function(e) { + console.log('write complete'); + }; + writer.write(new Blob([self.outputHistory], {type: 'text/plain'})); + },function (){ + console.error('Failed to get file writer'); + }); + }); + }); + textarea.keypress(function (event) { if (event.which == 13) { // enter event.preventDefault(); // prevent the adding of new line @@ -153,6 +192,7 @@ TABS.cli.read = function (readInfo) { text += String.fromCharCode(data[i]); this.currentLine += String.fromCharCode(data[i]); } + this.outputHistory += String.fromCharCode(data[i]) } if (this.currentLine == 'Rebooting') { CONFIGURATOR.cliActive = false;