Skip to content

Commit

Permalink
Reset stream styles between outputs (#3662)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed May 14, 2022
1 parent f83e184 commit 371e8e6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions static/ansi-to-html.ts
Expand Up @@ -495,4 +495,8 @@ export class Filter {

return buf.join('');
}

public reset() {
this.stickyStack = [];
}
}
3 changes: 3 additions & 0 deletions static/panes/executor.js
Expand Up @@ -511,6 +511,9 @@ Executor.prototype.handleCompileRequestAndResponse = function (request, result,
this.executionStatusSection.append($('<div/>').text('Could not execute the program'));
this.executionStatusSection.append($('<div/>').text('Compiler returned: ' + buildResultCode));
}
// reset stream styles
this.normalAnsiToHtml.reset();
this.errorAnsiToHtml.reset();
if (compileStdout.length > 0) {
this.compilerOutputSection.append($('<div/>').text('Compiler stdout'));
this.handleOutput(compileStdout, this.compilerOutputSection, this.normalAnsiToHtml);
Expand Down
4 changes: 4 additions & 0 deletions static/panes/output.ts
Expand Up @@ -197,6 +197,10 @@ export class Output extends Pane<OutputState> {

this.contentRoot.empty();

// reset stream colors
this.normalAnsiToHtml.reset();
this.errorAnsiToHtml.reset();

if (result.buildsteps) {
for (const step of result.buildsteps) {
this.add('Step ' + step.step + ' returned: ' + step.code);
Expand Down
3 changes: 3 additions & 0 deletions static/panes/tool.js
Expand Up @@ -466,6 +466,9 @@ Tool.prototype.onCompileResult = function (id, compiler, result) {
}
}

// reset stream styles
this.normalAnsiToHtml.reset();

if (toolResult) {
if (toolResult.languageId && toolResult.languageId === 'stderr') {
toolResult.languageId = false;
Expand Down
13 changes: 13 additions & 0 deletions test/ansi-to-html-tests.js
Expand Up @@ -68,4 +68,17 @@ describe('ansi-to-html', () => {
const filter = new Filter(filterOpts);
filter.toHtml('\x1B[7mhello').should.equal('hello');
});

// tests for #3659
it('should stream', () => {
const filter = new Filter(filterOpts);
filter.toHtml('\x1B[38;5;99mfoo');
filter.toHtml('bar').should.equal('<span style="color:#875fff">bar</span>');
});
it('should handle stream reset', () => {
const filter = new Filter(filterOpts);
filter.toHtml('\x1B[38;5;99mfoo');
filter.reset();
filter.toHtml('bar').should.equal('bar');
});
});

0 comments on commit 371e8e6

Please sign in to comment.