Fix command execution (this is being committed from my Apple //e)

This commit is contained in:
Terence Boldt 2020-12-24 09:01:46 -05:00
parent 8d62b0c57e
commit 52a86cc8a1

View File

@ -9,6 +9,7 @@ import (
"periph.io/x/periph/conn/gpio" "periph.io/x/periph/conn/gpio"
"periph.io/x/periph/conn/gpio/gpioreg" "periph.io/x/periph/conn/gpio/gpioreg"
"periph.io/x/periph/host" "periph.io/x/periph/host"
"strings"
"time" "time"
) )
@ -124,7 +125,8 @@ func handleExecCommand() {
return return
} }
fmt.Printf("Command output: %s\n", cmdOut) fmt.Printf("Command output: %s\n", cmdOut)
err = writeString(string(cmdOut)) apple2string := strings.Replace(string(cmdOut), "\n", "\r", -1)
err = writeString(apple2string)
if err != nil { if err != nil {
fmt.Printf("Failed to send command output\n") fmt.Printf("Failed to send command output\n")
return return
@ -219,14 +221,15 @@ func dumpBlock(buffer []byte) {
} }
func readString() (string, error) { func readString() (string, error) {
inByte := byte(255)
var inBytes bytes.Buffer var inBytes bytes.Buffer
var err error for {
for inByte != 0 { inByte,err := readByte()
inByte,err = readByte()
if err != nil { if err != nil {
return "", err return "", err
} }
if inByte == 0 {
break
}
inBytes.WriteByte(inByte) inBytes.WriteByte(inByte)
} }
return string(inBytes.Bytes()), nil return string(inBytes.Bytes()), nil
@ -234,7 +237,6 @@ func readString() (string, error) {
func writeString(outString string) error { func writeString(outString string) error {
for _, character := range outString { for _, character := range outString {
fmt.Printf("Out: %s\n", character);
err := writeByte(byte(character)|128) err := writeByte(byte(character)|128)
if err != nil { if err != nil {
fmt.Printf("Failed to write string\n") fmt.Printf("Failed to write string\n")