-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
golang/fmt: Println
do not align line head when using raw mode
#50761
Comments
I can use fmt.Fprintf(os.Stdout, "%s\r\n", "hello")
fmt.Fprintf(os.Stdout, "%s\r\n", "world") to replace it, but that work's hard, isn't? |
When a terminal is placed in raw mode all line ending processing is disabled; fmt.Println appends a \n new line character to the end of its output. As you see, the output continues on a new line, the “paper” the tty is printing on was moved up one line. To move the “carriage”, the print head of to the start of the line, \r carriage return is needed. Normally these are handled by the tty driver in the default “cooked” mode. This is not a bug in Go. Closed as working as intended. |
Sorry, I can't make any sense about why you (or another coder) just put LF(\n), and don't put CR(\r)? func Println(objs ...interface{}){
str := fmt.Sprintln(objs...)
if len(str) > 0 && str[len(str) - 1] == '\n' {
if len(str) > 1 && str[len(str) - 2] == '\r' {
io.WriteString(os.Stdout, str)
return
}
io.WriteString(os.Stdout, str[:len(str) - 1])
}
os.Stdout.Write(crlf)
} That's my solution now, It's not too long but I'd like to use standard library |
because the TTY driver knows to convert it to \r\n. When you shift to raw mode, that logic is disabled. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)? (That's not matter)go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: