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

Rendering a markdown table #424

Open
mfridman opened this issue Nov 2, 2024 · 1 comment
Open

Rendering a markdown table #424

mfridman opened this issue Nov 2, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mfridman
Copy link

mfridman commented Nov 2, 2024

Is your feature request related to a problem? Please describe.

I have a CLI that supports 3 table formats: plain (HiddenBorder), basic (RoundedBorder), and markdown (??). I used lipgloss/table to build a table and would like to output it in all those formats.

Output examples

Plain

  Status   Elapsed                     Package                    Cover   Pass   Fail   Skip  
                                                                                              
   PASS    (cached)   github.com/mfridman/tparse/internal/utils    --      12     0      0    
   PASS    (cached)   github.com/mfridman/tparse/parse             --      43     0      0    
   PASS    (cached)   github.com/mfridman/tparse/tests             --     137     0      0 

Basic (poorly named, "with border")

╭────────┬──────────┬───────────────────────────────────────────┬───────┬──────┬──────┬──────╮
│ Status │ Elapsed  │                  Package                  │ Cover │ Pass │ Fail │ Skip │
├────────┼──────────┼───────────────────────────────────────────┼───────┼──────┼──────┼──────┤
│  PASS  │ (cached) │ github.com/mfridman/tparse/internal/utils │  --   │  12  │  0   │  0   │
│  PASS  │ (cached) │ github.com/mfridman/tparse/parse          │  --   │  43  │  0   │  0   │
│  PASS  │ (cached) │ github.com/mfridman/tparse/tests          │  --   │ 137  │  0   │  0   │
╰────────┴──────────┴───────────────────────────────────────────┴───────┴──────┴──────┴──────╯

Markdown

| Status  | Elapsed  |                  Package                  | Cover | Pass | Fail | Skip |
|---------|----------|-------------------------------------------|-------|------|------|------|
| 🟢 PASS | (cached) | github.com/mfridman/tparse/internal/utils |  --   |  12  |  0   |  0   |
| 🟢 PASS | (cached) | github.com/mfridman/tparse/parse          |  --   |  43  |  0   |  0   |
| 🟢 PASS | (cached) | github.com/mfridman/tparse/tests          |  --   | 137  |  0   |  0   |

Describe the solution you'd like

I'd be nice if there was a lipglosss.MarkdownBorder(), which would allow converting a lipgloss table into a renderable markdown table.

Describe alternatives you've considered

This did the trick for me:

border := lipgloss.Border{
	Top:          "-",
	Bottom:       "-",
	Left:         "|",
	Right:        "|",
	TopLeft:      "", // empty for markdown
	TopRight:     "", // empty for markdown
	BottomLeft:   "", // empty for markdown
	BottomRight:  "", // empty for markdown
	MiddleLeft:   "|",
	MiddleRight:  "|",
	Middle:       "|",
	MiddleTop:    "|",
	MiddleBottom: "|",
}
t = t.Border(border).BorderBottom(false).BorderTop(false)

Additional context

This might be overly specific, but opening this up for discussion and/or if someone else finds this useful.

@meowgorithm
Copy link
Member

Nice, that's actually really good. Want to open a PR?

@bashbunni bashbunni added the help wanted Extra attention is needed label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants