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

Rewrite of ANSI code handling method #49763

Merged
merged 7 commits into from
May 28, 2018

Conversation

danielfrankcom
Copy link
Contributor

Fixes #47457 and maintains fix from #21423

More robust and expandable way of handling ANSI escape sequences. Future sequences should be able to slot in fairly easily with the new layout, as will be demonstrated by my next pull request.

@isidorn isidorn self-assigned this May 14, 2018
@isidorn isidorn added this to the May 2018 milestone May 14, 2018
@isidorn
Copy link
Contributor

isidorn commented May 14, 2018

@danielfrankcom great work and thanks a lot for this PR!
Did you test out how this wokrs?

Also might you be interested in writting some unit tests for this? For me it seems like this could be unit testable - appendStylizedStringToContainerand handleANSIOutput could be functions since they only depend on the linkDetector which you should be also able to create from tests using TestWorkbenchService.
In case you would like to do that (which would be awesome) than we could move those function to debugUtils.ts and the tests could live in debugUtils.test.ts

The code looks great overall, but unit tests would increase my confidence by a lot.
I will add some minor comments inside the code.

.hc-black .monaco-workbench .repl .repl-tree .monaco-tree .monaco-tree-row > .content > .output.expression .code36, .hc-black .monaco-workbench .repl .repl-tree .monaco-tree .monaco-tree-row > .content > .output.expression .code96 { color: #218D8D; }
.hc-black .monaco-workbench .repl .repl-tree .monaco-tree .monaco-tree-row > .content > .output.expression .code37, .hc-black .monaco-workbench .repl .repl-tree .monaco-tree .monaco-tree-row > .content > .output.expression .code97 { color: #707070; }
/* Regular and bright color codes are currently treated the same. */
.monaco-workbench .repl .repl-tree .monaco-tree .monaco-tree-row > .content > .output.expression .code-fg-30, .monaco-workbench .repl .repl-tree .monaco-tree .monaco-tree-row > .content > .output.expression .code-fg-90 { color: gray; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to add the fg to the code class names? Is that the proper name or?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly considered changing this back to the way it was for this review, but I changed them to match the pattern I used for the background colors (bg). Maybe a more explicit 'foreground'?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 'foreground' would be better
Same for 'background'.
That way it is clearer when somebody reads it a couple of months later

this.insert(this.linkDetector.handleLinks(buffer), currentToken || tokensContainer);
buffer = '';
}
if (char.match(/^[ABCDHIJKfhmpsu]$/)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining this regex

} else if ((code >= 30 && code <= 37) || (code >= 90 && code <= 97)) {
styleNames.push('code-fg-' + code);
} else if (code === 39) {
styleNames = styleNames.filter(style => !style.match(/^code-fg-\d+$/));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here explaining what this does since I am not clear


i = index;
} else if (ansiSequence.match(/^.*[ABCDHIJKfhmpsu]$/)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex seems to be duplicated please extract it above with a clear name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, we don't even need this one. I'll remove it completely.

return;
}

const content: string | HTMLElement = this.linkDetector.handleLinks(stringContent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for explicit types everywhere, ts should nicely infer the types here

@danielfrankcom
Copy link
Contributor Author

I made the changes based on your comments and pushed.

I was thinking about unit tests too, certainly seems like an area where there's a lot of room for error. I did some pretty extensive testing manually, so it shouldn't be too difficult to write some tests that do similar things. I won't be able to get to them this week, but I'll take a look on the weekend.

@isidorn
Copy link
Contributor

isidorn commented May 15, 2018

@danielfrankcom thanks for addressing the comments.
There is no rush in mergining this PR so I woild prefer to wait for tests.
Please note that next week I am on vacation so I might only reply the week after.

Thanks a lot for your hard work!

@danielfrankcom
Copy link
Contributor Author

I haven't finished the tests yet, but I've extracted the functions from the replViewer.ts file.

You mentioned putting them into debugUtils.ts, however it seems that the LinkDetector is located in debug/browser, and depends on a number of things in there. I have created a seperate file at debug/browser/debugANSIHandling.ts, and I will be creating a new test file in the corresponding location. If this is a problem let me know, but I couldn't see a way to deal with the dependencies otherwise.

@isidorn isidorn merged commit a50384a into microsoft:master May 28, 2018
@isidorn
Copy link
Contributor

isidorn commented May 28, 2018

@danielfrankcom this is great great work! Thanks a lot!
Nothing to add, merging it in 🍻

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can not output string with color in debug console after update to 1.22.1
2 participants