mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-15 17:33:22 +00:00
wip: filepicker, help, list, table, textarea, textinput, viewport
This commit is contained in:
+4
-4
@@ -115,10 +115,10 @@ func (m *Model) SetStyles(s Styles) {
|
||||
type Option func(*Model)
|
||||
|
||||
// New creates a new model for the table widget.
|
||||
func New(opts ...Option) Model {
|
||||
func New(ctx *tea.Context, opts ...Option) Model {
|
||||
m := Model{
|
||||
cursor: 0,
|
||||
viewport: viewport.New(0, 20),
|
||||
viewport: viewport.New(ctx, 0, 20),
|
||||
|
||||
KeyMap: DefaultKeyMap(),
|
||||
styles: DefaultStyles(),
|
||||
@@ -380,7 +380,7 @@ func (m *Model) FromValues(value, separator string) {
|
||||
}
|
||||
|
||||
func (m Model) headersView() string {
|
||||
var s = make([]string, 0, len(m.cols))
|
||||
s := make([]string, 0, len(m.cols))
|
||||
for _, col := range m.cols {
|
||||
style := lipgloss.NewStyle().Width(col.Width).MaxWidth(col.Width).Inline(true)
|
||||
renderedCell := style.Render(runewidth.Truncate(col.Title, col.Width, "…"))
|
||||
@@ -390,7 +390,7 @@ func (m Model) headersView() string {
|
||||
}
|
||||
|
||||
func (m *Model) renderRow(rowID int) string {
|
||||
var s = make([]string, 0, len(m.cols))
|
||||
s := make([]string, 0, len(m.cols))
|
||||
for i, value := range m.rows[rowID] {
|
||||
style := lipgloss.NewStyle().Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true)
|
||||
renderedCell := m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")))
|
||||
|
||||
+10
-3
@@ -1,10 +1,16 @@
|
||||
package table
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func TestFromValues(t *testing.T) {
|
||||
input := "foo1,bar1\nfoo2,bar2\nfoo3,bar3"
|
||||
table := New(WithColumns([]Column{{Title: "Foo"}, {Title: "Bar"}}))
|
||||
ctx := &tea.Context{Renderer: lipgloss.DefaultRenderer()}
|
||||
table := New(ctx, WithColumns([]Column{{Title: "Foo"}, {Title: "Bar"}}))
|
||||
table.FromValues(input, ",")
|
||||
|
||||
if len(table.rows) != 3 {
|
||||
@@ -22,8 +28,9 @@ func TestFromValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFromValuesWithTabSeparator(t *testing.T) {
|
||||
ctx := &tea.Context{Renderer: lipgloss.DefaultRenderer()}
|
||||
input := "foo1.\tbar1\nfoo,bar,baz\tbar,2"
|
||||
table := New(WithColumns([]Column{{Title: "Foo"}, {Title: "Bar"}}))
|
||||
table := New(ctx, WithColumns([]Column{{Title: "Foo"}, {Title: "Bar"}}))
|
||||
table.FromValues(input, "\t")
|
||||
|
||||
if len(table.rows) != 2 {
|
||||
|
||||
Reference in New Issue
Block a user