GithubHelp home page GithubHelp logo

Comments (3)

JoshuaWilkes avatar JoshuaWilkes commented on June 25, 2024

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.

JoshuaWilkes avatar JoshuaWilkes commented on June 25, 2024

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

from huh.

maaslalani avatar maaslalani commented on June 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.