Comments (3)
As an alternative I suppose it would also be reasonable to use the Description as the header.
Or maybe have an optional Header added as well instead of a specific table mode for the Field type.
from huh.
Coming back to this,
As a workaround you can format the description and options to look like a table.
Something along the lines of this to render your header and rows
cols := []Column{{Title: "hello", Width: 20}, {Title: "world", Width: 15}, {Title: "new", Width: 10}, {Title: "column", Width: 30}}
var s = make([]string, 0, len(cols))
for _, col := range cols {
style := lipgloss.NewStyle().Width(col.Width).MaxWidth(col.Width).Inline(true)
renderedCell := style.Render(runewidth.Truncate(col.Title, col.Width, "…"))
s = append(s, lipgloss.NewStyle().Bold(true).Padding(0, 1).Render(renderedCell))
}
header := lipgloss.JoinHorizontal(lipgloss.Left, s...)
rows := []string{}
var cells = make([]string, 0, 4)
for i, value := range []string{"a", "b", "c", "d"} {
style := lipgloss.NewStyle().Width(cols[i].Width).MaxWidth(cols[i].Width).Inline(true)
renderedCell := lipgloss.NewStyle().Bold(true).Padding(0, 1).Render(style.Render(runewidth.Truncate(value, cols[i].Width, "…")))
cells = append(cells, renderedCell)
}
row := lipgloss.JoinHorizontal(lipgloss.Left, cells...)
rows = append(rows, row, row)
huh.NewSelect[string]().
Options(huh.NewOptions(rows...)...).
Title("Choose your burger with columns").
Description(header)
![image](https://private-user-images.githubusercontent.com/14214200/295893250-c94cef8b-8140-41d4-8d4a-adf0ab7e771d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyODM1NTQsIm5iZiI6MTcxOTI4MzI1NCwicGF0aCI6Ii8xNDIxNDIwMC8yOTU4OTMyNTAtYzk0Y2VmOGItODE0MC00MWQ0LThkNGEtYWRmMGFiN2U3NzFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI1VDAyNDA1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFmNGI0MmJkODQ1MzI0MjAzNzIxOWQ4ZjU1YjdkMzJhNDgzZGEzZjU2NzZmNDNmNmE5OTkwNzg5YTljYzMwMzkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.9frhOQ9mmkQbMvoiEuKzlKJpjNqJFkmzeYx4iUtkiyc)
from huh.
Hey! Thank you so much for creating this issue!
We definitely want to introduce new field types in the future and table may be one of them.
I'm just going to consolidate to clean up some issues and close this in favour of #61 to have all the ideas in one place.
from huh.
Related Issues (20)
- Empty string as negative confirm should show only one affirmative button HOT 3
- Foreground color on any of the Focused.* fields do not apply HOT 3
- Foreground color not working on new line HOT 2
- FilePicker example doesn't compile HOT 1
- If the spinner drops out prematurely, input is invisible HOT 1
- Theme not applied to input HOT 1
- Black and white color Spinner HOT 1
- Releaase 0.3.1 for File Picker HOT 1
- Theme.FieldSeparator no longer supported in 0.4.x? HOT 1
- MultiSelect's filterable set to "false" will have no effect.
- Add Filterable for Select HOT 2
- Empty confirmation considered invalid in accessible mode HOT 1
- Add "Select All" and "Invert" Shortcuts to Multiselect
- Add `WithInput` to specify input stream
- Overriding KeyMaps and KeyBinds
- Fullscreen / AltScreen does not take the full screen - there seems to be a maximum height
- Multiple forms can interfere with each other
- Keypresses are ignored upon reaching 2nd form (examples/gh)
- Windows: Tab/Enter keys not handled correctly HOT 1
- bug: note.render should escape everything in code block
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from huh.