// Align Align the Ascii art over width width with alignment a
432153
func (i *ASCIIArt) Align(a TextAlignment, width int) {
	// First get the width of the longest string in the slice
	var newContents []string
	incomingLength := 0
	for _, line := range i.contents {
		if len(line) > incomingLength {
			incomingLength = len(line)
		}
	}
	for _, line := range i.contents {
		newContents = append(newContents, AlignText(AlignText(line, incomingLength, AlignLeft), width, a))
	}
	i.contents = newContents
}
804844
func (s Style) Dim(on bool) Style {
	return s.setAttrs(Style(AttrDim), on)
}
247329
func (sc *StringConstraint) Format(f string) *StringConstraint {
	sc.format = f
	return sc
}
1269607
func (win *Window) LayoutFitWidth(id int, minwidth int) {
	layout := win.layout
	if layout.Row.Type != layoutStatic || len(layout.Row.WidthArr) > 0 {
		panic(WrongLayoutErr)
	}
	if win.adjust == nil {
		win.adjust = make(map[int]map[int]*adjustCol)
	}
	adjust, ok := win.adjust[layout.Cnt]
	if !ok {
		adjust = make(map[int]*adjustCol)
		win.adjust[layout.Cnt] = adjust
	}
	col, ok := adjust[layout.Row.Index2]
	if !ok || col.id != id || col.font != win.ctx.Style.Font {
		if !ok {
			col = &adjustCol{id: id, width: minwidth}
			win.adjust[layout.Cnt][layout.Row.Index2] = col
		}
		col.id = id
		col.font = win.ctx.Style.Font
		col.width = minwidth
		col.first = true
		win.ctx.trashFrame = true
		win.LayoutSetWidth(minwidth)
		layout.Row.CalcMaxWidth = true
		return
	}
	win.LayoutSetWidthScaled(col.width)
	layout.Row.CalcMaxWidth = col.first
}
586274
func alignmentShift(block []byte) int {
	if len(block) == 0 {
		return 0
	}
	return int(uintptr(unsafe.Pointer(&block[0])) & uintptr(alignment-1))
}
1193151
func Format(i int64, units Units, width int) string {
	switch units {
	case U_BYTES:
		return FormatBytes(i)
	default:
		// by default just convert to string
		return fmt.Sprintf(fmt.Sprintf("%%%dd", width), i)
	}
}
181140
func (cb *CellBuffer) Fill(r rune, style Style) {
	for i := range cb.cells {
		c := &cb.cells[i]
		c.currMain = r
		c.currComb = nil
		c.currStyle = style
		c.width = 1
	}
}
735134
func setAlignment(formatStyle *formatStyle) *xlsxAlignment {
	var alignment xlsxAlignment
	if formatStyle.Alignment != nil {
		alignment.Horizontal = formatStyle.Alignment.Horizontal
		alignment.Indent = formatStyle.Alignment.Indent
		alignment.JustifyLastLine = formatStyle.Alignment.JustifyLastLine
		alignment.ReadingOrder = formatStyle.Alignment.ReadingOrder
		alignment.RelativeIndent = formatStyle.Alignment.RelativeIndent
		alignment.ShrinkToFit = formatStyle.Alignment.ShrinkToFit
		alignment.TextRotation = formatStyle.Alignment.TextRotation
		alignment.Vertical = formatStyle.Alignment.Vertical
		alignment.WrapText = formatStyle.Alignment.WrapText
	}
	return &alignment
}
75214
func (d Date) Format(layout string) string {
	return d.t.Format(layout)
}
114829
func Margin(size Size) *trees.Style {
	return &trees.Style{Name: "margin", Value: string(size)}
}
1148634
func formatKV(in []string) string {
	columnConf := columnize.DefaultConfig()
	columnConf.Empty = "<none>"
	columnConf.Glue = " = "
	return columnize.Format(in, columnConf)
}
893753
func asciiEqualFold(s, t []byte) bool {
	if len(s) != len(t) {
		return false
	}
	for i, sb := range s {
		tb := t[i]
		if sb == tb {
			continue
		}
		if ('a' <= sb && sb <= 'z') || ('A' <= sb && sb <= 'Z') {
			if sb&caseMask != tb&caseMask {
				return false
			}
		} else {
			return false
		}
	}
	return true
}
1058051
func (win *Window) Label(str string, alignment label.Align) {
	win.LabelColored(str, alignment, win.ctx.Style.Text.Color)
}
1197705
func alignBox(m [][]Pixel, x, y int) {
	// box
	align := Alignment.Pixel()
	for dy := 0; dy < 5; dy++ {
		for dx := 0; dx < 5; dx++ {
			p := align
			if dx == 0 || dx == 4 || dy == 0 || dy == 4 || dx == 2 && dy == 2 {
				p |= Black
			}
			m[y+dy][x+dx] = p
		}
	}
}
536731
func (b *bitWriter) flushAlign() {
	nbBytes := (b.nBits + 7) >> 3
	for i := uint8(0); i < nbBytes; i++ {
		b.out = append(b.out, byte(b.bitContainer>>(i*8)))
	}
	b.nBits = 0
	b.bitContainer = 0
}
787749
func Indent(width int, indent, s string) string {
	if width == 0 {
		return s
	}
	if width > 1 {
		indent = strings.Repeat(indent, width)
	}
	var res []byte
	bol := true
	for i := 0; i < len(s); i++ {
		c := s[i]
		if bol && c != '\n' {
			res = append(res, indent...)
		}
		res = append(res, c)
		bol = c == '\n'
	}
	return string(res)
}
786796
func (i *ASCIIArt) SetWidth(w int) {
	// Find the longest line
	for j := range i.contents {
		mkUp := w - len(i.contents[j])
		if mkUp > 0 {
			i.contents[j] = i.contents[j] + strings.Repeat(" ", mkUp)
		} else {
			i.contents[j] = i.contents[j][:w]
		}
	}
}