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

Align mid-line? #221

Open
isovector opened this issue Jan 30, 2022 · 2 comments
Open

Align mid-line? #221

isovector opened this issue Jan 30, 2022 · 2 comments

Comments

@isovector
Copy link

isovector commented Jan 30, 2022

I have a doc that currently pretty prints as

S : Set   (not in scope)
A : Set        (not in scope)
B : Set      (not in scope)
ma : State' S A 
f : A → State' S B 
s : S 
s' : S 
a : A 

but would instead like to produce

S  : Set        (not in scope)
A  : Set        (not in scope)
B  : Set        (not in scope)
ma : State' S A 
f  : A → State' S B 
s  : S 
s' : S 
a  : A 

aligning on both the : and the (not in scope). Is this possible? I can't figure out how to get align to do this.

@sjakobi
Copy link
Collaborator

sjakobi commented Feb 8, 2022

I don't know how to do this. AFAIK Wadler-Leijen prettyprinters don't really support this.

#53, especially #53 (comment) is related.

natefaubion/purescript-dodo-printer#8 is related work: Maybe it can be done after all?! We'll see.

@natefaubion
Copy link

natefaubion commented Feb 12, 2022

The dodo-printer PR handles this by:

  • Having a separate type for box alignment.
  • Line based docs can be lifted into the box type (in dodo this is done through a printer interface).
  • Vertical composition is straightforward (concatenation through line breaks)
  • Horizontal composition scans one line at a time, appending columns.

It also has stuff for box alignment (like align-self in CSS) and padding, and omits trailing line alignment. This is kind of ridiculously complicated in PureScript because of stack safety and efficiency, but can be done straightforwardly in Haskell (depending on how you'd scan lines).

Edit: I should also say it assumes distributivity of annotations, which works well for things like ansi colors, but doesn't necessarily work for everything.

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

No branches or pull requests

3 participants