Skip to content

Commit fd5f714

Browse files
committed
Add terminal logging tool
1 parent 923fc55 commit fd5f714

File tree

8 files changed

+123
-2
lines changed

8 files changed

+123
-2
lines changed

css/icons.css

+5
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,8 @@ a .icon__more:hover {
288288
.icon-storage.lrg:before { background-position: 0 -2640px }
289289
.compact .icon-storage.lrg:before,
290290
.icon-storage.sml:before { background-position: -60px -2640px }
291+
292+
.icon-log.lrg:before { background-position: 0 -2700px }
293+
.compact .icon-log.lrg:before,
294+
.icon-log.sml:before { background-position: -60px -2700px }
295+

extras/make_icons.sh

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ i svg/appbar.connection.bluetooth bluetooth
9595
i svg/appbar.hardware.headphones headphone
9696
i svg/appbar.network network
9797
i svg/appbar.database storage
98+
i svg/appbar.paper log
9899

99100
# Now put them all together into one file
100101
convert icons/oldicons.png $IMAGES -append $ICONFILE

img/icons.png

788 Bytes
Loading

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ <h5 class="title-bar__title">Espruino Web IDE</h5>
188188
<script src="EspruinoTools/core/modules.js"></script>
189189
<script src="EspruinoTools/core/env.js"></script>
190190
<script src="EspruinoTools/core/flasher.js"></script>
191-
<script src="EspruinoTools/core/flasherESP8266.js"></script>
191+
<script src="EspruinoTools/core/flasherESP8266.js"></script>
192192
<script src="js/libs/secure-dfu.js"></script>
193193

194194
<script src="js/core/editorBlockly.js"></script>
@@ -242,6 +242,7 @@ <h5 class="title-bar__title">Espruino Web IDE</h5>
242242
<script src="js/libs/imageconverter.js"></script> <!-- for storage.js -->
243243
<script src="js/plugins/emulator_banglejs.js"></script> <!-- for storage.js -->
244244
<script src="js/plugins/keyShortcuts.js"></script>
245+
<script src="js/plugins/terminalLogger.js"></script>
245246
<!-- js/plugins/_examplePlugin.js -->
246247

247248
<script>

js/core/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@
406406
element.classList.add(elementClass);
407407
},
408408
setInfo : function(text) {
409+
options.info = text;
409410
if (info) info.innerHTML = text;
410411
},
411412
remove : function() {

js/plugins/terminalLogger.js

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
Copyright 2014 Gordon Williams ([email protected])
3+
4+
This Source Code is subject to the terms of the Mozilla Public
5+
License, v2.0. If a copy of the MPL was not distributed with this
6+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
8+
------------------------------------------------------------------
9+
An Example Plugin
10+
------------------------------------------------------------------
11+
**/
12+
"use strict";
13+
(function(){
14+
15+
var icon;
16+
var log = [];
17+
var logStarted = false;
18+
19+
function init() {
20+
Espruino.Core.Config.add("SHOW_TERMINAL_LOGGER_ICON", {
21+
section : "General",
22+
name : "Terminal Log Icon",
23+
description : "Show an icon in the terminal window that allows you to record the contents of the terminal to a file",
24+
type : "boolean",
25+
defaultValue : false,
26+
onChange : function(newValue) { showIcon(newValue); }
27+
});
28+
showIcon(Espruino.Config.SHOW_TERMINAL_LOGGER_ICON);
29+
Espruino.addProcessor("terminalNewLine", function(line, callback) {
30+
if (logStarted) {
31+
log.push(line);
32+
icon.setInfo(getLogStateMessage());
33+
}
34+
callback(line);
35+
});
36+
}
37+
38+
function getLogStateMessage() {
39+
if (logStarted) {
40+
return "&#x1F534; "+log.length;
41+
} else {
42+
if (log.length) return "&#x2B55; "+log.length;
43+
else return "&#x2B55; IDLE";
44+
}
45+
}
46+
47+
function showIcon(show) {
48+
if (icon!==undefined) {
49+
icon.remove();
50+
icon = undefined;
51+
}
52+
if (show) {
53+
icon = Espruino.Core.App.addIcon({
54+
id: "termLog",
55+
icon: "log",
56+
title : "Terminal Logging",
57+
//order: -90,
58+
area: {
59+
name: "terminal",
60+
position: "top"
61+
},
62+
click: showMenu,
63+
info : getLogStateMessage()
64+
});
65+
}
66+
}
67+
68+
function showMenu() {
69+
var buttons = [];
70+
if (logStarted) {
71+
buttons.push({ name:"Stop", callback : function() {
72+
logStarted = false;
73+
icon.setInfo(getLogStateMessage());
74+
popup.close();
75+
}});
76+
} else {
77+
buttons.push({ name:"Start", callback : function() {
78+
logStarted = true;
79+
icon.setInfo(getLogStateMessage());
80+
popup.close();
81+
}});
82+
}
83+
if (log.length) {
84+
buttons.push({ name:"Save", callback : function() {
85+
Espruino.Core.Utils.fileSaveDialog(log.join("\r\n"), "log.txt", function() {
86+
icon.setInfo(getLogStateMessage());
87+
popup.close();
88+
});
89+
}});
90+
buttons.push({ name:"Clear", callback : function() {
91+
log = [];
92+
icon.setInfo(getLogStateMessage());
93+
popup.close();
94+
}});
95+
}
96+
var popup = Espruino.Core.App.openPopup({
97+
title: "Terminal Logging",
98+
padding: true,
99+
contents: `<p>Logging allows you to store the data from the terminal into a file.</p>
100+
<p>You currently have ${log.length} lines recorded</p>`,
101+
position: "center",
102+
buttons : buttons
103+
});
104+
}
105+
106+
Espruino.Plugins.TerminalLogger = {
107+
init : init,
108+
};
109+
}());

js/plugins/webcam.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@
8383
$('<video autoplay id="videotag" style="'+filters+'"></video>').prependTo(".editor--terminal .editor__canvas");
8484
} else {
8585
hadWebCam = false;
86-
if (icon!==undefined) icon.remove();
86+
if (icon!==undefined) {
87+
icon.remove();
88+
icon = undefined;
89+
}
8790
}
8891
if (hadWebCam) toggleWebCam();
8992
}

main.html

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ <h5 class="title-bar__title">Espruino Web IDE</h5>
223223
<script src="js/plugins/storage.js"></script>
224224
<script src="js/libs/imageconverter.js"></script> <!-- for storage.js -->
225225
<script src="js/plugins/keyShortcuts.js"></script>
226+
<script src="js/plugins/terminalLogger.js"></script>
226227
<!-- js/plugins/_examplePlugin.js -->
227228

228229
</body>

0 commit comments

Comments
 (0)