Last active
April 26, 2019 20:31
-
-
Save shazow/5cedec7ac685eb6de10f826b22acb01d to your computer and use it in GitHub Desktop.
Demonstrating a rendering bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Bug screenshot: https://tmp.shazow.net/screenshots/screenshot_2019-04-26_dd60.png | |
Output paste: | |
$ go run *.go | |
echo: "test" | |
echo: "foo" | |
echo: "bar" | |
echo: "😼" | |
echo: "why do emojis break the echo indent?" | |
echo: "" | |
echo: "😼😼😼" | |
echo: "even erasing them and then hitting enter still breaks the indent" | |
prompt: | |
*/ | |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"strings" | |
"golang.org/x/crypto/ssh/terminal" | |
) | |
type rw struct { | |
io.Reader | |
io.Writer | |
} | |
func main() { | |
oldState, err := terminal.MakeRaw(0) | |
if err != nil { | |
panic(err) | |
} | |
defer terminal.Restore(0, oldState) | |
screen := &rw{os.Stdin, os.Stdout} | |
t := terminal.NewTerminal(screen, "prompt: ") | |
t.SetEnterClear(true) | |
var out bytes.Buffer | |
for { | |
line, err := t.ReadLine() | |
if err == io.EOF { | |
return | |
} else if err != nil { | |
log.Fatal(err) | |
} | |
if strings.HasPrefix(line, "/quit") { | |
fmt.Fprintf(t, "Bye!\n") | |
return | |
} | |
fmt.Fprintf(t, "echo: %q\n", line) | |
out.Reset() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment