Skip to content

Commit 4bd2f26

Browse files
committed
Merge pull request #101 from parallaxinc/logging
Updated terminal logging to use new events, Improved console buffer.
2 parents 9bf180e + 759ec64 commit 4bd2f26

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "test"
88
},
99
"dependencies": {
10-
"bs2-serial": "^0.6.0",
10+
"bs2-serial": "^0.7.1",
1111
"codemirror": "^4.13.0",
1212
"frylord": "^0.5.0",
1313
"holovisor": "^0.2.0",

plugins/editor/console-buffer.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
function ConsoleBuffer(options){
4+
var opts = options || {};
5+
this._length = 0;
6+
this._text = '';
7+
this._bufferSize = opts.bufferSize || 2048;
8+
this._trimOffset = opts.trimOffset || 256;
9+
10+
if(this._bufferSize < 1){
11+
throw new Error('Invalid buffer length!');
12+
}
13+
if(this._trimOffset < 0 || this._trimOffset >= this._bufferSize){
14+
throw new Error('Invalid trim offset length!');
15+
}
16+
}
17+
18+
ConsoleBuffer.prototype.update = function(evt){
19+
//assume text events for now
20+
var text = evt.data || '';
21+
this._text += text;
22+
23+
if(this._text.length > this._bufferSize){
24+
this._text = this._text.substr(this._text.length - (this._bufferSize - this._trimOffset));
25+
}
26+
this._length = this._text.length;
27+
};
28+
29+
ConsoleBuffer.prototype.clear = function(){
30+
this._length = 0;
31+
this._text = '';
32+
};
33+
34+
ConsoleBuffer.prototype.getConsoleHTML = function(){
35+
return this._text;
36+
};
37+
38+
39+
module.exports = ConsoleBuffer;

plugins/editor/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,32 @@ require('codemirror/lib/codemirror.css');
1010
require('../../assets/theme/parallax.css');
1111

1212
var CodeMirror = require('codemirror');
13+
1314
var keyExtension = require('./key-extension');
15+
var ConsoleBuffer = require('./console-buffer');
1416

1517
require('./pbasic')(CodeMirror);
1618

1719
function editor(app, opts, done){
1820

1921
var codeEditor;
2022
var outputConsole;
23+
var buffer = new ConsoleBuffer();
2124

2225
var space = app.workspace;
2326

24-
function output(text){
27+
function output(evt){
28+
buffer.update(evt);
2529
if(outputConsole){
26-
outputConsole.innerHTML += text;
30+
outputConsole.innerHTML = buffer.getConsoleHTML();
2731
outputConsole.scrollTop = outputConsole.scrollHeight;
2832
}
2933
}
3034

3135
function clearOutput(){
36+
buffer.clear();
3237
if(outputConsole){
33-
outputConsole.innerHTML = '';
38+
outputConsole.innerHTML = buffer.getConsoleHTML();
3439
}
3540
}
3641

plugins/sidebar/overlays/download.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,14 @@ class DownloadOverlay extends React.Component {
5959

6060
const board = irken.getBoard(device);
6161

62-
board.on('progress', this.updateProgress);
62+
board.removeListener('terminal', logger);
6363

64-
const log = through(function(chunk, enc, cb){
65-
logger(chunk.toString());
66-
cb(null, chunk);
67-
});
64+
board.on('progress', this.updateProgress);
6865

6966
board.compile(source)
7067
.tap(() => logger.clear())
7168
.then((memory) => board.bootload(memory))
72-
.then(() => board.read().pipe(log))
69+
.then(() => board.on('terminal', logger))
7370
.tap(() => toast.clear())
7471
.tap(() => handleSuccess(`'${name}' downloaded successfully`))
7572
.catch(handleError)

0 commit comments

Comments
 (0)