func (tb *TextBuf) Text(x, y int, txt string, align int) {
	if align <= 1 {
		switch align {
		case 0:
			x -= StrLen(txt) / 2
		case 1:
			x -= StrLen(txt)
		}
		i := 0
		for _, r := range txt {
			tb.Put(x+i, y, r)
			i++
		}
	} else {
		switch align {
		case 3:
			y -= StrLen(txt) / 2
		case 2:
			x -= StrLen(txt)
		}
		i := 0
		for _, r := range txt {
			tb.Put(x, y+i, r)
			i++
		}
	}
}
Print text txt at (x,y). Horizontal display for align in [-1,1],
vasrtical alignment for align in [2,4]
align: -1: left; 0: centered; 1: right; 2: top, 3: center, 4: bottom
package txtg
import (
	"log"
)
var Edge = [][4]rune{{'+', '+', '+', '+'}, {'.', '.', '\'', '\''}, {'/', '\\', '\\', '/'}}
type TextBuf struct {
	Buf  []rune  
	W, H int     
}
func NewTextBuf(w, h int) (tb *TextBuf) {
	tb = new(TextBuf)
	tb.W, tb.H = w, h
	tb.Buf = make([]rune, (w+1)*h)
	for i, _ := range tb.Buf {
		tb.Buf[i] = ' '
	}
	for i := 0; i < h; i++ {
		tb.Buf[i*(w+1)+w] = '\n'
	}
	return
}
func (tb *TextBuf) Put(x, y int, c rune) {
	if x < 0 || y < 0 || x >= tb.W || y >= tb.H || c < ' ' {
		return
	}
	i := (tb.W+1)*y + x
	tb.Buf[i] = c
}
func (tb *TextBuf) Rect(x, y, w, h int, style int, fill rune) {
	style = style % len(Edge)
	if h < 0 {
		h = -h
		y -= h
	}
	if w < 0 {
		w = -w
		x -= w
	}
	tb.Put(x, y, Edge[style][0])
	tb.Put(x+w, y, Edge[style][1])
	tb.Put(x, y+h, Edge[style][2])
	tb.Put(x+w, y+h, Edge[style][3])
	for i := 1; i < w; i++ {
		tb.Put(x+i, y, '-')
		tb.Put(x+i, y+h, '-')
	}
	for i := 1; i < h; i++ {
		tb.Put(x+w, y+i, '|')
		tb.Put(x, y+i, '|')
		if fill > 0 {
			for j := x + 1; j < x+w; j++ {
				tb.Put(j, y+i, fill)
			}
		}
	}
}
func (tb *TextBuf) Block(x, y, w, h int, fill rune) {
	if h < 0 {
		h = -h
		y -= h
	}
	if w < 0 {
		w = -w
		x -= w
	}
	for i := 0; i < w; i++ {
		for j := 0; j <= h; j++ {
			tb.Put(x+i, y+j, fill)
		}
	}
}
func StrLen(s string) (n int) {
	for _, _ = range s {
		n++
	}
	return
}