I am using bufio and I want to erase a line. The issue I'm running into now is I need to overwrite it with blanks and feels programmatically unsafe. If there an idiomatic way to clear out a line in Stdout?
var Output *bufio.Writer = bufio.NewWriter(os.Stdout)
func MoveCursor(x int, y int) {
fmt.Fprintf(Output, "\033[%d;%dH", y, x)
}
func Print(a ...interface{}) (n int, err error) {
return fmt.Fprint(Output, a...)
}
Output.Flush()
scanner := bufio.NewScanner(os.Stdin)
const BLANK = " "
for {
MoveCursor(1, 1)
Print(BLANK)
MoveCursor(1, 1)
Print("Hello ", scanner.Text())
MoveCursor(1, 4)
Print(BLANK)
MoveCursor(1, 4)
Print("> ")
Output.Flush()
scanner.Scan()
}
One thing that is especially surprising is that Output.Flush() doesn't clear the entire content of the screen.