I am creating a CLI for an API in Go and I am struggling with displaying the output.
In Linux you can simply print \033[%dA
to \033[%dD
to move in certain directions, but Powershell and Command Prompt try to print these, leading to
[2K192.168.212.182...successful
[28D[2K192.168.212.28....requested
[27D[2A[2K192.168.212.182...successful
[28D[2K192.168.212.28....successful
[28D
instead of
192.168.212.182...successful
192.168.212.28....successful
The Code for displaying this is the following
for i := 0; i < len(localName); i++ {
dotc := maxlength - len(localName[i])
dots := "..."
for j := 0; j < dotc; j++ {
dots += "."
}
terminal.Stdout.ClearLine().Print(localName[i] + dots + localStatus[i]).Nl().Left(len(localName[i] + dots + localStatus[i]))
}
The function Left(int)
simply prints \033[%dD
x times