Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain original newlines in BrightScript Log output panel, and also strip ansii colors #609

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 187 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"roku-test-automation": "^2.0.10",
"semver": "^7.1.3",
"source-map": "^0.7.3",
"strip-ansi": "^5.2.0",
"thenby": "^1.3.4",
"undent": "^0.1.0",
"uuid": "^9.0.1",
Expand Down
11 changes: 10 additions & 1 deletion src/LogOutputManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { LogDocumentLinkProvider } from './LogDocumentLinkProvider';
import { CustomDocumentLink } from './LogDocumentLinkProvider';
import * as fsExtra from 'fs-extra';
import type { BrightScriptLaunchConfiguration } from './DebugConfigurationProvider';
import stripAnsi from 'strip-ansi';

export class LogLine {
constructor(
Expand Down Expand Up @@ -258,6 +259,12 @@ export class LogOutputManager {
*/
public appendLine(lineText: string, mustInclude = false): void {
let lines = lineText.split(/\r?\n/g);

// Remove the last line if it's empty as a result of a trailing newline
if (lines[lines.length - 1] === '') {
lines.pop();
}

for (let line of lines) {
if (line !== '') {
if (!this.includeStackTraces) {
Expand All @@ -284,7 +291,9 @@ export class LogOutputManager {
}
}
}
if (line) {
if (typeof line === 'string') {
// Strip ANSI color codes
line = stripAnsi(line);
const logLine = new LogLine(line, mustInclude);
this.allLogLines.push(logLine);
if (this.shouldLineBeShown(logLine)) {
Expand Down
Loading