Skip to content

Commit

Permalink
fix: double styles
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Jul 22, 2024
1 parent c7ed991 commit 2e84e54
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions ansi/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
ctx.table.lipgloss = table.New().
Width(width).
StyleFunc(func(row, col int) lipgloss.Style {
st := lipgloss.NewStyle().
MaxWidth(width)
st := lipgloss.NewStyle()
if m := ctx.options.Styles.Table.Margin; m != nil {
st = st.Margin(0, int(*m))
}
Expand Down Expand Up @@ -99,33 +98,9 @@ func (e *TableElement) setBorders(ctx RenderContext) {
ctx.table.lipgloss.BorderBottom(false)
}

func (e *TableElement) setStyles(ctx RenderContext) {
ctx.table.lipgloss.StyleFunc(func(row, col int) lipgloss.Style {
st := lipgloss.NewStyle()
if m := ctx.options.Styles.Table.Margin; m != nil {
st = st.Padding(0, int(*m))
}
if row == 0 {
st = st.Bold(true)
}

switch e.table.Alignments[col] {
case astext.AlignCenter:
st = st.Align(lipgloss.Center)
case astext.AlignRight:
st = st.Align(lipgloss.Right)
case astext.AlignLeft:
st = st.Align(lipgloss.Left)
}

return st
})
}

func (e *TableElement) Finish(_ io.Writer, ctx RenderContext) error {
rules := ctx.options.Styles.Table

e.setStyles(ctx)
e.setBorders(ctx)

ow := ctx.blockStack.Current().Block
Expand Down

0 comments on commit 2e84e54

Please sign in to comment.