2017-02-26 22:04:24 +00:00
|
|
|
package compact
|
|
|
|
|
|
|
|
// Common helper functions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-25 20:17:53 +00:00
|
|
|
|
2017-02-26 22:04:24 +00:00
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
2017-03-06 00:15:32 +00:00
|
|
|
const colSpacing = 1
|
|
|
|
|
2017-02-26 22:04:24 +00:00
|
|
|
func centerParText(p *ui.Par) {
|
|
|
|
var text string
|
|
|
|
var padding string
|
|
|
|
|
|
|
|
// strip existing left-padding
|
|
|
|
for i, ch := range p.Text {
|
|
|
|
if string(ch) != " " {
|
|
|
|
text = p.Text[i:]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
padlen := (p.InnerWidth() - len(text)) / 2
|
|
|
|
for i := 0; i < padlen; i++ {
|
|
|
|
padding += " "
|
|
|
|
}
|
|
|
|
p.Text = fmt.Sprintf("%s%s", padding, text)
|
|
|
|
}
|