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

Enable tables to carry a title #160

Open
yoshuawuyts opened this issue Dec 10, 2024 · 5 comments
Open

Enable tables to carry a title #160

yoshuawuyts opened this issue Dec 10, 2024 · 5 comments
Labels
f: help wanted Feel free to start working on this t: feature A new feature

Comments

@yoshuawuyts
Copy link

yoshuawuyts commented Dec 10, 2024

A detailed description of the feature you would like to see added.

I was looking to implement bytecodealliance/wasm-tools#1923 using comfy-table to get a duf-like output, but it doesn't seem comfy-table is able to set titles. It would be neat if it could though.

Explain your usecase of the requested feature

When printing many tables in a row, being able to render a title adds some visual rhythm, making it easier to scan for the section you're looking for.

Alternatives

No response

Additional context

This is the output I'm trying to create:

ascii tables in a terminal

┌──────────────────────────────────────┐                                            
│ component sample-wasi-http-rust      │                                            
├──────────┬────────────────┬──────────┤                                            
│ KIND     │ PRODUCER       │ VERSION  │                                            
├──────────┼────────────────┼──────────┤                                            
│ tool     │ wit-component  │ 0.216.0  │                                            
└──────────┴────────────────┴──────────┘                                            
┌──────────────────────────────────────────────────────────────────────────────────┐
│ module sample_wasi_http_rust.wasm                                                │
├──────────┬──────────────────┬────────────────────────────────────────────────────┤
│ KIND     │ PRODUCER         │ VERSION                                            │
├──────────┼──────────────────┼────────────────────────────────────────────────────┤
│ language │ Rust             │ -                                                  │
├──────────┼──────────────────┼────────────────────────────────────────────────────┤
│ language │ C11              │ -                                                  │
├──────────┼──────────────────┼────────────────────────────────────────────────────┤
│ tool     │ rustc            │ 1.82.0 (f6e511eec 2024-10-15)                      │
├──────────┼──────────────────┼────────────────────────────────────────────────────┤
│ tool     │ clang            │ 18.1.2-wasi-sdk                                    │
│          │                  │ (https://github.com/llvm/llvm-project              │
├──────────┼──────────────────┼────────────────────────────────────────────────────┤
│ tool     │ wit-component    │ 0.20.1                                             │
├──────────┼──────────────────┼────────────────────────────────────────────────────┤
│ tool     │ wit-bindgen-rust │ 0.20.1                                             │
├──────────┼──────────────────┼────────────────────────────────────────────────────┤
│ tool     │ wit-bindgen-c    │ 0.20.1                                             │
└──────────┴──────────────────┴────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────┐                            
│ module wit-component:adapter:wasi_snapshot_preview1: │                            
├──────────┬──────────┬────────────────────────────────┤                            
│ KIND     │ PRODUCER │ VERSION                        │                            
├──────────┼──────────┼────────────────────────────────┤                            
│ language │ Rust     │ -                              │                            
├──────────┼──────────┼────────────────────────────────┤                            
│ tool     │ rustc    │ 1.82.0 (f6e511eec 2024-10-15)  │                            
└──────────┴──────────┴────────────────────────────────┘                            
┌────────────────────────────────────┐                                              
│ module wit-component-shim          │                                              
├──────────┬───────────────┬─────────┤                                              
│ KIND     │ PRODUCER      │ VERSION │                                              
├──────────┼───────────────┼─────────┤                                              
│ language │ Rust          │ -       │                                              
├──────────┼───────────────┼─────────┤                                              
│ tool     │ wit-component │ 0.216.0 │                                              
└──────────┴───────────────┴─────────┘                                              
┌────────────────────────────────────┐                                              
│ module wit-component:fixups        │                                              
├──────────┬───────────────┬─────────┤                                              
│ KIND     │ PRODUCER      │ VERSION │                                              
├──────────┼───────────────┼─────────┤                                              
│ language │ Rust          │ -       │                                              
├──────────┼───────────────┼─────────┤                                              
│ tool     │ wit-component │ 0.216.0 │                                              
└──────────┴───────────────┴─────────┘                                              
@Nukesor
Copy link
Owner

Nukesor commented Dec 10, 2024

I like that!

Should also be fairly easy to implement as the last step before the rendered table is returned :)

@Nukesor
Copy link
Owner

Nukesor commented Dec 10, 2024

A few things must be done for this to be implemented properly:

  • It must support alignment
  • Padding?
  • Same border display logic as the rest of the table
  • Styling?

Most of this logic can probably be re-used from the formatting module, the current code will need a bit of refactoring though. It's very much entangled with ColumnDisplayInfo and Cell.

Should we re-use the Cell for this and let table.set_title(title: Cell) accept a cell?

@yoshuawuyts
Copy link
Author

Yay, I'm glad you like it!

Should we re-use the Cell for this and let table.set_title(title: Cell) accept a cell?

That seems reasonable to me. It essentially is one big cell, so that doesn't seem like a bad starting point.

Padding?

This would be nice to have, yes. At least for my use case I don't think we will immediately need it, but I could see us using this.

@Nukesor
Copy link
Owner

Nukesor commented Dec 10, 2024

If you got some spare time, feel free to start tackling this one :)

Otherwise I might get to it eventually (I hope :D), should be a fun task.

@yoshuawuyts
Copy link
Author

I probably won't get around to taking a stab at this myself for a while, so please don't let me hold you back from implementing something fun ^^

@Nukesor Nukesor added the f: help wanted Feel free to start working on this label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: help wanted Feel free to start working on this t: feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants