func (s *renderStyle) buildReplaceContent(bad string) {
	replacement := fmt.Sprintf("&#x%02x;", bad)
	s.replaceContent = func(old string) string {
		return strings.Replace(old, bad, replacement, -1)
	}
}
buildReplaceContent creates a function closure, with minimal bound lexical
state, which replaces content
package termtables
import (
	"fmt"
	"strings"
	"unicode/utf8"
)
type TableAlignment int
const (
	AlignLeft   = TableAlignment(1)
	AlignCenter = TableAlignment(2)
	AlignRight  = TableAlignment(3)
)
type TableStyle struct {
	SkipBorder        bool
	BorderX           string
	BorderY           string
	BorderI           string
	BorderTop         string
	BorderBottom      string
	BorderRight       string
	BorderLeft        string
	BorderTopLeft     string
	BorderTopRight    string
	BorderBottomLeft  string
	BorderBottomRight string
	PaddingLeft       int
	PaddingRight      int
	Width             int
	Alignment         TableAlignment
	htmlRules         htmlStyleRules
}
type CellStyle struct {
	Alignment TableAlignment
	ColSpan int
}
var DefaultStyle = &TableStyle{
	SkipBorder: false,
	BorderX:    "-", BorderY: "|", BorderI: "+",
	PaddingLeft: 1, PaddingRight: 1,
	Width:     80,
	Alignment: AlignLeft,
}
type renderStyle struct {
	cellWidths map[int]int
	columns    int
	replaceContent func(string) string
	TableStyle
}
func (s *TableStyle) setUtfBoxStyle() {
	s.BorderX = "─"
	s.BorderY = "│"
	s.BorderI = "┼"
	s.BorderTop = "┬"
	s.BorderBottom = "┴"
	s.BorderLeft = "├"
	s.BorderRight = "┤"
	s.BorderTopLeft = "╭"
	s.BorderTopRight = "╮"
	s.BorderBottomLeft = "╰"
	s.BorderBottomRight = "╯"
}
func (s *TableStyle) setAsciiBoxStyle() {
	s.BorderX = "-"
	s.BorderY = "|"
	s.BorderI = "+"
	s.BorderTop, s.BorderBottom, s.BorderLeft, s.BorderRight = "", "", "", ""
	s.BorderTopLeft, s.BorderTopRight, s.BorderBottomLeft, s.BorderBottomRight = "", "", "", ""
	s.fillStyleRules()
}
func (s *TableStyle) fillStyleRules() {
	if s.BorderTop == "" {
		s.BorderTop = s.BorderI
	}
	if s.BorderBottom == "" {
		s.BorderBottom = s.BorderI
	}
	if s.BorderLeft == "" {
		s.BorderLeft = s.BorderI
	}
	if s.BorderRight == "" {
		s.BorderRight = s.BorderI
	}
	if s.BorderTopLeft == "" {
		s.BorderTopLeft = s.BorderI
	}
	if s.BorderTopRight == "" {
		s.BorderTopRight = s.BorderI
	}
	if s.BorderBottomLeft == "" {
		s.BorderBottomLeft = s.BorderI
	}
	if s.BorderBottomRight == "" {
		s.BorderBottomRight = s.BorderI
	}
}
func createRenderStyle(table *Table) *renderStyle {
	style := &renderStyle{TableStyle: *table.Style, cellWidths: map[int]int{}}
	style.TableStyle.fillStyleRules()
	if table.outputMode == outputMarkdown {
		style.buildReplaceContent(table.Style.BorderY)
	}
	for _, element := range table.elements {
		if _, ok := element.(*Separator); ok {
			continue
		}
		if row, ok := element.(*Row); ok {
			for i, cell := range row.cells {
				if cell.colSpan > 1 {
					continue
				}
				if style.cellWidths[i] < cell.Width() {
					style.cellWidths[i] = cell.Width()
				}
			}
		}
	}
	style.columns = len(style.cellWidths)
	width := utf8.RuneCountInString(style.BorderLeft)  
	internalBorderWidth := utf8.RuneCountInString(style.BorderI)
	lastIndex := 0
	for i, v := range style.cellWidths {
		width += v + style.PaddingLeft + style.PaddingRight + internalBorderWidth
		if i > lastIndex {
			lastIndex = i
		}
	}
	if internalBorderWidth != utf8.RuneCountInString(style.BorderRight) {
		width += utf8.RuneCountInString(style.BorderRight) - internalBorderWidth
	}
	if table.titleCell != nil {
		titleMinWidth := 0 +
			table.titleCell.Width() +
			utf8.RuneCountInString(style.BorderLeft) +
			utf8.RuneCountInString(style.BorderRight) +
			style.PaddingLeft +
			style.PaddingRight
		if width < titleMinWidth {
			style.cellWidths[lastIndex] += (titleMinWidth - width)
			width = titleMinWidth
		}
	}
	style.Width = width
	return style
}
func (s *renderStyle) CellWidth(i int) int {
	return s.cellWidths[i]
}