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

Max column width for tables #344

Open
testinfected opened this issue Sep 3, 2024 · 12 comments
Open

Max column width for tables #344

testinfected opened this issue Sep 3, 2024 · 12 comments
Labels
question Further information is requested

Comments

@testinfected
Copy link

Since the last update using lipgloss to render tables, it's no longer possible to have columns with a max width and text wrapping, unless I'm missing something. This produces some pretty awful rendering of tables that expand to take the entire terminal width or else cut their cell content instead of wrapping.

We'd like to be able to set a max column width and decide if we wrap or cut content (with ellipsis).

An alternative would be to have multiline cells, using for instance line breaks in the cell content itself. Obviously this wouldn't be controlled by style, but still acceptable.

@testinfected testinfected added the enhancement New feature or request label Sep 3, 2024
@testinfected
Copy link
Author

Any news/comment on this from the maintainer team?

This is a real blocker for us

Thanks!

@meowgorithm
Copy link
Member

meowgorithm commented Dec 3, 2024

Hey, @testinfected! Thanks for the follow-up, and apologies for the delay here. Can you post some example code (and ideally some screenshots). As simple as it might seem, this will greatly help us in looking into this.

@bashbunni
Copy link
Member

Seconding meow's comment above. If I'm understanding the issue correctly, you're looking to add width constraints to the table? If so, you can set that with WordWrap. The table adjusts its width to match the block element that it belongs to, same as the text.

That said, this is just a guess at what you're hoping to achieve here. Example code would definitely help us better understand what you're looking for :)

        defaultWidth := 80
        // ...
	// Create a new renderer.
	r, err := glamour.NewTermRenderer(
		glamour.WithEnvironmentConfig(),
		glamour.WithWordWrap(defaultWidth),

r, err := glamour.NewTermRenderer(
glamour.WithEnvironmentConfig(),
glamour.WithWordWrap(defaultWidth),

@bashbunni bashbunni added question Further information is requested and removed enhancement New feature or request labels Dec 3, 2024
@testinfected
Copy link
Author

testinfected commented Dec 5, 2024

I will post some screenshots. I already tried word wrap, but it ellipsis the string (if that's even a word) instead of wrapping to a new line. Am I missing something?

@testinfected
Copy link
Author

With glamour 0.8 and lipgloss 0.10, using:

r, err := glamour.NewTermRenderer( 
 	glamour.WithEnvironmentConfig(), 
 	glamour.WithWordWrap(80), 
)

I get this:

Screenshot at 2024-12-05 11-04-44

Whereas with 0.7 I would get this:

Screenshot at 2024-12-05 11-08-46

@testinfected
Copy link
Author

ping

@bashbunni
Copy link
Member

Ah okay, thank you for the screenshots, those are super helpful. We will look into it and keep you updated here

@testinfected
Copy link
Author

@bashbunni sorry to ping again, do you have any news on this?

@meowgorithm
Copy link
Member

meowgorithm commented Jan 21, 2025

Sorry for the hold-up on this, @testinfected. Wow, this is really, really bad. We're looking into this.

Here's the full source code to reproduce this.

go get github.com/MakeNowJust/heredoc
go get github.com/charmbracelet/glamour
package main

import (
	"fmt"
	"os"

	"github.com/MakeNowJust/heredoc"
	"github.com/charmbracelet/glamour"
)

var md = heredoc.Doc(`
    |Name|Description|Type|Required|Default|
    |----|-----------|----|--------|-------|
    |command|A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures.|[`string`]|yes||
`)

func main() {
	r, err := glamour.NewTermRenderer(
		glamour.WithEnvironmentConfig(),
		glamour.WithWordWrap(80),
	)

	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create renderer: %v", err)
		os.Exit(1)
	}

	var out string
	out, err = r.Render(md)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to render markdown: %v", err)
		os.Exit(1)
	}

	fmt.Println(out)
}

@meowgorithm
Copy link
Member

Off the cuff, it looks like a few things need to happen:

  • Headers should not be truncated, if possible
  • Content should not be truncated, if possible
  • Content should be padded with two cells on each side
  • Content should word-wrap

@bashbunni
Copy link
Member

bashbunni commented Jan 24, 2025

Update: made some good progress on this. Needs more refinement though and need to add some tests for edge cases. Just wanted to let you know we are thinking about it and actively working on it :)

@testinfected
Copy link
Author

Thanks so much for working on this. I’m looking forward to be able to update to 0.8, it has so many nice improvements over 0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants