Skip to content

Commit

Permalink
More linting and fixes for missing bits (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evertras authored Mar 5, 2022
1 parent ebd25ab commit 7fa760f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# https://golangci-lint.run/usage/linters/
issues:
exclude-use-default: false
linters:
enable:
- asciicheck
Expand Down
2 changes: 1 addition & 1 deletion examples/pokemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (m Model) View() string {
view := lipgloss.JoinVertical(
lipgloss.Left,
styleSubtle.Render("Press q or ctrl+c to quit - Sorted by # Conversations"),
styleSubtle.Render("Highlighted: " + selected),
styleSubtle.Render("Highlighted: "+selected),
styleSubtle.Render("https://www.nintendolife.com/news/2021/11/these-are-the-most-loved-and-most-hated-pokemon-according-to-a-new-study"),
m.pokeTable.View(),
) + "\n"
Expand Down
7 changes: 7 additions & 0 deletions table/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ package table

import "github.com/charmbracelet/lipgloss"

// StyledCell represents a cell in the table that has a particular style applied.
// The cell style takes highest precedence and will overwrite more general styles
// from the row, column, or table as a whole. This style should be generally
// limited to colors, font style, and alignments - spacing style such as margin
// will break the table format.
type StyledCell struct {
Data interface{}
Style lipgloss.Style
}

// NewStyledCell creates an entry that can be set in the row data and show as
// styled with the given style.
func NewStyledCell(data interface{}, style lipgloss.Style) StyledCell {
return StyledCell{data, style}
}
2 changes: 2 additions & 0 deletions table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (c Column) WithStyle(style lipgloss.Style) Column {
return c
}

// WithFiltered sets whether the column should be considered for filtering (true)
// or not (false).
func (c Column) WithFiltered(filterable bool) Column {
c.filterable = filterable

Expand Down
39 changes: 39 additions & 0 deletions table/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Package table contains a Bubble Tea component for an interactive and customizable
table.
The simplest useful table can be created with table.New(...).WithRows(...). Row
data should map to the column keys, as shown below. Note that extra data will
simply not be shown, while missing data will be safely blank in the row's cell.
const (
// This is not necessary, but recommended to avoid typos
columnKeyName = "name"
columnKeyCount = "count"
)
// Define the columns and how they appear
columns := []table.Column{
table.NewColumn(columnKeyName, "Name", 10),
table.NewColumn(columnKeyCount, "Count", 6),
}
// Define the data that will be in the table, mapping to the column keys
rows := []table.Row{
table.NewRow(table.RowData{
columnKeyName: "Cheeseburger",
columnKeyCount: 3,
}),
table.NewRow(table.RowData{
columnKeyName: "Fries",
columnKeyCount: 2,
}),
}
// Create the table
tbl := table.New(columns).WithRows(rows)
// Use it like any Bubble Tea component in your view
tbl.View()
*/
package table

0 comments on commit 7fa760f

Please sign in to comment.