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

Add DocBox printer for 2D layout. #8

Merged
merged 6 commits into from
Feb 18, 2022
Merged

Add DocBox printer for 2D layout. #8

merged 6 commits into from
Feb 18, 2022

Conversation

natefaubion
Copy link
Owner

Fixes #7

@natefaubion
Copy link
Owner Author

@srghma Do you want to give this branch a try before I merge?

@natefaubion
Copy link
Owner Author

Screen Shot 2022-02-06 at 4 51 43 PM

@natefaubion
Copy link
Owner Author

There's currently a bug when resuming from horizontal contexts (printing halts).

@natefaubion
Copy link
Owner Author

Alright this is fixed up. Would love to get some feedback!

@srghma
Copy link
Contributor

srghma commented Feb 12, 2022

tnx, I can try to replace purescript-boxes lib with this new implementation in the https://github.com/srghma/purescript-envparse lib, but I see already that it should work without problems

TODO: check what will happen IF

e.g. root is 100, c1 and c2 are 40

|-------------------|
||------||------|   |
||  c1  ||  c2  |   |
||------||------|   |
|      root         |
|-------------------|

but what will happen if I change root to 60?

will it render to?

|-------------|
||------|     |
||  c1  |     |
||------|     |
||------|     |
||  c2  |     |
||------|     |
|      root   |
|-------------|

P.S. ideally I would like to get width for root from process.stdout.cols and lib should render tables in a responsive manner (like flexboxes are rendered by browser)

like https://github.com/vadimdemedes/ink#box does

@natefaubion
Copy link
Owner Author

natefaubion commented Feb 12, 2022

This PR does not implement a higher-level reflowing API for boxes, but that should be possible to implement on top of the existing APIs (using things like withPosition). If you have thoughts on what that API might look like I could give a more detailed answer.

@natefaubion
Copy link
Owner Author

Some things that might help when writing higher-level layout APIs would be adding the full print configuration to withPosition, or providing a separate with style function. locally only lets you modify the settings, but you can't use them to influence the generation of the Doc. This would allow you to thread options down to a box printer since it's going to have to bake in indentation as alignment. I also think withPosition could specify whether anything has already been printed on the current line, which might be required if you want a conditional break.

@natefaubion
Copy link
Owner Author

I've added withLocalOptions which lets your document depend on the local options while also potentially returning new options.

I also think withPosition could specify whether anything has already been printed on the current line, which might be required if you want a conditional break.

I think this can already be inferred by checking the indent, column, and nextIndent in withPosition.

@natefaubion natefaubion merged commit 3295054 into master Feb 18, 2022
@srghma
Copy link
Contributor

srghma commented Feb 18, 2022

tnx @natefaubion , sorry that I couldn't try the branch, I just see that it should work just fine)
tnx for additional info

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.

is it possible to print simple tables separated by space?
2 participants