Skip to content

Instantly share code, notes, and snippets.

@shazow
Last active April 26, 2019 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shazow/5cedec7ac685eb6de10f826b22acb01d to your computer and use it in GitHub Desktop.
Save shazow/5cedec7ac685eb6de10f826b22acb01d to your computer and use it in GitHub Desktop.
Demonstrating a rendering bug
/*
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