Fix prefix & suffix not rendering around tables

This commit is contained in:
Christian Muehlhaeuser
2019-12-09 13:09:04 +01:00
parent 00c809072e
commit cbd7714ca8
+10 -3
View File
@@ -8,6 +8,7 @@ import (
type TableElement struct { type TableElement struct {
writer *tablewriter.Table writer *tablewriter.Table
indentWriter io.Writer
header []string header []string
cell []string cell []string
} }
@@ -24,6 +25,8 @@ type TableCellElement struct {
} }
func (e *TableElement) Render(w io.Writer, ctx RenderContext) error { func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack
var indent uint var indent uint
var margin uint var margin uint
rules := ctx.style[Table] rules := ctx.style[Table]
@@ -34,23 +37,27 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
margin = *rules.Margin margin = *rules.Margin
} }
iw := &IndentWriter{ ctx.table.indentWriter = &IndentWriter{
Indent: indent + margin, Indent: indent + margin,
IndentFunc: func(wr io.Writer) { IndentFunc: func(wr io.Writer) {
renderText(w, ctx.blockStack.Parent().Style, " ") renderText(w, bs.Current().Style, " ")
}, },
Forward: &AnsiWriter{ Forward: &AnsiWriter{
Forward: w, Forward: w,
}, },
} }
ctx.table.writer = tablewriter.NewWriter(iw) renderText(ctx.table.indentWriter, bs.Current().Style, rules.Prefix)
ctx.table.writer = tablewriter.NewWriter(ctx.table.indentWriter)
return nil return nil
} }
func (e *TableElement) Finish(w io.Writer, ctx RenderContext) error { func (e *TableElement) Finish(w io.Writer, ctx RenderContext) error {
ctx.table.writer.Render() ctx.table.writer.Render()
ctx.table.writer = nil ctx.table.writer = nil
rules := ctx.style[Table]
renderText(ctx.table.indentWriter, ctx.blockStack.Current().Style, rules.Suffix)
return nil return nil
} }