Skip to content

Conversation

@43081j
Copy link
Contributor

@43081j 43081j commented Jul 21, 2025

This adds a renderer package which can be used to parse the "frames" which would've been seen by the user.

For example, if we were to render this (pseudo-ansi):

foo
bar<CURSOR.UP(1)><ERASE.LINE>

We would have two frames:

[
  "foo\nbar",
  "   \nbar"
]

DRAFT

until i write all the tests and settle on a public interface, and try it out in the vitest serializer which will use it

43081j added 2 commits July 21, 2025 19:03
This adds a renderer package which can be used to parse the "frames"
which would've been seen by the user.

For example, if we were to render this (pseudo-ansi):

```
foo
bar<CURSOR.UP(1)><ERASE.LINE>
```

We would have two frames:

```ts
[
  "foo\nbar",
  "   \nbar"
]
```
Copy link
Owner

@webpro webpro left a comment

Choose a reason for hiding this comment

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

Looking great already! And so cool that this parser's already showing some usefulness.

Just FYI, there are few more control codes related to cursor pos/scroll and insert/erase stuff, but haven't even done the research on relevance and usefulness to add in this renderer. Some might even not be used anymore at all and best forgotten.

If the current set of supported commands is sufficient for its purpose then that's totally fine to get the ball rolling. Looking at the implementation with the string[] buffer it should be easy to extend/adapt.

In my view, the name "renderer" is a bit too generic. How about "frame-renderer"? Or something else just a tad more specific.

const renderStreamBrand = Symbol.for('ansi-tools:render-stream');

export class RenderStream extends Writable {
[renderStreamBrand] = true;
Copy link
Owner

Choose a reason for hiding this comment

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

Just wondering: why have this prop?

Copy link
Contributor Author

@43081j 43081j Aug 5, 2025

Choose a reason for hiding this comment

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

Originally it was because vitest runs tests in another realm to the one that runs snapshot serialisation. So you can't use instanceof

But I'm actually leaning more towards the serialiser not using this directly anyway. And instead, it's up to the test author to use this in their test files

I'll remove this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants