func Flush() {
	for idx, str := range strings.SplitAfter(Screen.String(), "\n") {
		if idx > Height() {
			return
		}
		Output.WriteString(str)
	}
	Output.Flush()
	Screen.Reset()
}
Flush buffer and ensure that it will not overflow screen
package goterm
import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strings"
)
const RESET = "\033[0m"
const RESET_COLOR = "\033[32m"
const RESET_LINE = "\r\033[K"
const (
	BLACK = iota
	RED
	GREEN
	YELLOW
	BLUE
	MAGENTA
	CYAN
	WHITE
)
var Output *bufio.Writer = bufio.NewWriter(os.Stdout)
func getColor(code int) string {
	return fmt.Sprintf("\033[3%dm", code)
}
func getBgColor(code int) string {
	return fmt.Sprintf("\033[4%dm", code)
}
const shift = uint(^uint(0)>>63) << 4
const PCT = 0x8000 << shift
type winsize struct {
	Row    uint16
	Col    uint16
	Xpixel uint16
	Ypixel uint16
}
var Screen *bytes.Buffer = new(bytes.Buffer)
func GetXY(x int, y int) (int, int) {
	if y == -1 {
		y = CurrentHeight() + 1
	}
	if x&PCT != 0 {
		x = int((x & 0xFF) * Width() / 100)
	}
	if y&PCT != 0 {
		y = int((y & 0xFF) * Height() / 100)
	}
	return x, y
}
type sf func(int, string) string
func applyTransform(str string, transform sf) (out string) {
	out = ""
	for idx, line := range strings.Split(str, "\n") {
		out += transform(idx, line)
	}
	return
}
func Clear() {
	Output.WriteString("\033[2J")
}
func MoveCursor(x int, y int) {
	fmt.Fprintf(Screen, "\033[%d;%dH", y, x)
}
func MoveCursorUp(bias int) {
	fmt.Fprintf(Screen, "\033[%dA", bias)
}
func MoveCursorDown(bias int) {
	fmt.Fprintf(Screen, "\033[%dB", bias)
}
func MoveCursorForward(bias int) {
	fmt.Fprintf(Screen, "\033[%dC", bias)
}
func MoveCursorBackward(bias int) {
	fmt.Fprintf(Screen, "\033[%dD", bias)
}
func MoveTo(str string, x int, y int) (out string) {
	x, y = GetXY(x, y)
	return applyTransform(str, func(idx int, line string) string {
		return fmt.Sprintf("\033[%d;%dH%s", y+idx, x, line)
	})
}
func ResetLine(str string) (out string) {
	return applyTransform(str, func(idx int, line string) string {
		return fmt.Sprintf("%s%s", RESET_LINE, line)
	})
}
func Bold(str string) string {
	return applyTransform(str, func(idx int, line string) string {
		return fmt.Sprintf("\033[1m%s\033[0m", line)
	})
}
func Color(str string, color int) string {
	return applyTransform(str, func(idx int, line string) string {
		return fmt.Sprintf("%s%s%s", getColor(color), line, RESET)
	})
}
func Highlight(str, substr string, color int) string {
	hiSubstr := Color(substr, color)
	return strings.Replace(str, substr, hiSubstr, -1)
}
func HighlightRegion(str string, from, to, color int) string {
	return str[:from] + Color(str[from:to], color) + str[to:]
}
func Background(str string, color int) string {
	return applyTransform(str, func(idx int, line string) string {
		return fmt.Sprintf("%s%s%s", getBgColor(color), line, RESET)
	})
}
func Width() int {
	ws, err := getWinsize()
	if err != nil {
		return -1
	}
	return int(ws.Col)
}
func Height() int {
	ws, err := getWinsize()
	if err != nil {
		return -1
	}
	return int(ws.Row)
}
func CurrentHeight() int {
	return strings.Count(Screen.String(), "\n")
}