mirror of
https://github.com/tjboldt/Apple2-IO-RPi.git
synced 2025-01-05 01:30:29 +00:00
Fix line wrap with nano and top (#49)
This commit is contained in:
parent
de69c54007
commit
04e967e64d
@ -20,35 +20,27 @@ func sendCharacter(comm A2Io, b byte) {
|
|||||||
escapeSequence = "^["
|
escapeSequence = "^["
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if b == 13 {
|
if b == 0x0d {
|
||||||
// fmt.Printf("\nCR\n")
|
|
||||||
comm.WriteByte('H')
|
comm.WriteByte('H')
|
||||||
comm.WriteByte(0)
|
comm.WriteByte(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if b > 0x0d && b < 0x20 || b > 0x80 && b < 0xa0 {
|
if b > 0x0d && b < 0x20 || b > 0x80 && b < 0xa0 {
|
||||||
// fmt.Printf("Control code: %02X\n", b)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if b >= 0xa0 {
|
if b >= 0xa0 {
|
||||||
comm.WriteByte('+' | 0x80)
|
comm.WriteByte('+' | 0x80)
|
||||||
// fmt.Printf("Code: %02X\n", b)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(escapeSequence) == 0 {
|
|
||||||
fmt.Printf("%c", b)
|
|
||||||
}
|
|
||||||
if len(escapeSequence) > 0 {
|
if len(escapeSequence) > 0 {
|
||||||
// Parse the escape codes that don't end with a letter
|
// Parse the escape codes that don't end with a letter
|
||||||
escapeSequence += string(b)
|
escapeSequence += string(b)
|
||||||
if escapeSequence == "^[]" {
|
if escapeSequence == "^[]" {
|
||||||
// fmt.Printf("Start operating system sequence\n")
|
|
||||||
operatingSystemSequence = true
|
operatingSystemSequence = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if operatingSystemSequence {
|
if operatingSystemSequence {
|
||||||
if b == 0x07 {
|
if b == 0x07 {
|
||||||
// fmt.Printf("Operating system sequence: %s\n", escapeSequence)
|
|
||||||
operatingSystemSequence = false
|
operatingSystemSequence = false
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
}
|
}
|
||||||
@ -72,58 +64,54 @@ func sendCharacter(comm A2Io, b byte) {
|
|||||||
// Set/clear application mode for cursor
|
// Set/clear application mode for cursor
|
||||||
case "^[[?1h":
|
case "^[[?1h":
|
||||||
//applicationMode = true
|
//applicationMode = true
|
||||||
// fmt.Printf("Start application mode: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[[?1l":
|
case "^[[?1l":
|
||||||
//applicationMode = false
|
//applicationMode = false
|
||||||
comm.WriteByte('T')
|
comm.WriteByte('T')
|
||||||
comm.WriteByte(0x00)
|
comm.WriteByte(0x00)
|
||||||
comm.WriteByte('B')
|
comm.WriteByte('B')
|
||||||
comm.WriteByte(0x18)
|
comm.WriteByte(0x18)
|
||||||
// fmt.Printf("End application mode: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
// Tab to home position
|
// Tab to home position
|
||||||
case "^[[f", "^[[;f":
|
case "^[[f", "^[[;f":
|
||||||
comm.WriteByte(0x19) // ^Y moves to home position
|
comm.WriteByte(0x19) // ^Y moves to home position
|
||||||
// fmt.Printf("Home: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
// Clear screen
|
// Clear screen
|
||||||
case "^[[2J", "^[[c":
|
case "^[[2J", "^[[c":
|
||||||
comm.WriteByte(0x0c) // ^L clears the screen
|
comm.WriteByte(0x0c) // ^L clears the screen
|
||||||
// fmt.Printf("Clear screen: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
|
||||||
case "^[E":
|
|
||||||
comm.WriteByte(0x0A) // ^J moves cursor down
|
|
||||||
// fmt.Printf("Move down: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[D":
|
case "^[D":
|
||||||
comm.WriteByte(0x17) // ^W scrolls up
|
comm.WriteByte(0x17) // ^W scrolls up
|
||||||
// fmt.Printf("Scroll up: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[[K", "^[[0K":
|
case "^[[K", "^[[0K":
|
||||||
comm.WriteByte(0x1d) // ^] clears to end of line
|
comm.WriteByte(0x1d) // ^] clears to end of line
|
||||||
// fmt.Printf("Clear line right: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[[2K":
|
case "^[[2K":
|
||||||
comm.WriteByte(0x1a) // ^Z clears line
|
comm.WriteByte(0x1a) // ^Z clears line
|
||||||
// fmt.Printf("Clear line: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[M":
|
case "^[M":
|
||||||
comm.WriteByte(0x16) // ^V scrolls down
|
comm.WriteByte(0x16) // ^V scrolls down
|
||||||
// fmt.Printf("Scroll down: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[[J":
|
case "^[[J":
|
||||||
comm.WriteByte(0x0b) // ^K clears to end of screen
|
comm.WriteByte(0x0b) // ^K clears to end of screen
|
||||||
// fmt.Printf("Clear below cursor: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[[7m":
|
case "^[[7m":
|
||||||
comm.WriteByte(0x0f) // ^O inverse video
|
comm.WriteByte(0x0f) // ^O inverse video
|
||||||
// fmt.Printf("Inverse: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
case "^[[m", "^[[0m", "^[[0;7m", "^[[0;1m":
|
case "^[[m", "^[[0m", "^[[0;7m", "^[[0;1m":
|
||||||
comm.WriteByte(0x0e) // ^N normal video
|
comm.WriteByte(0x0e) // ^N normal video
|
||||||
// fmt.Printf("Normal: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse escape codes that need further parsing
|
// Parse escape codes that need further parsing
|
||||||
@ -132,7 +120,6 @@ func sendCharacter(comm A2Io, b byte) {
|
|||||||
case 'H', 'f':
|
case 'H', 'f':
|
||||||
if escapeSequence == "^[[H" || escapeSequence == "^[[;H" {
|
if escapeSequence == "^[[H" || escapeSequence == "^[[;H" {
|
||||||
comm.WriteByte(0x19) // ^Y moves to home position
|
comm.WriteByte(0x19) // ^Y moves to home position
|
||||||
// fmt.Printf("Home: %s\n", escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
} else {
|
} else {
|
||||||
var ignore string
|
var ignore string
|
||||||
@ -150,7 +137,6 @@ func sendCharacter(comm A2Io, b byte) {
|
|||||||
comm.WriteByte(byte(htab))
|
comm.WriteByte(byte(htab))
|
||||||
comm.WriteByte('V')
|
comm.WriteByte('V')
|
||||||
comm.WriteByte(byte(vtab))
|
comm.WriteByte(byte(vtab))
|
||||||
// fmt.Printf("Set Cursor (%d, %d): %s\n", htab, vtab, escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
}
|
}
|
||||||
case 'r':
|
case 'r':
|
||||||
@ -160,19 +146,16 @@ func sendCharacter(comm A2Io, b byte) {
|
|||||||
comm.WriteByte(byte(windowTop))
|
comm.WriteByte(byte(windowTop))
|
||||||
comm.WriteByte('B')
|
comm.WriteByte('B')
|
||||||
comm.WriteByte(byte(windowBottom))
|
comm.WriteByte(byte(windowBottom))
|
||||||
// fmt.Printf("Set Window (%d, %d): %s\n", windowTop, windowBottom, escapeSequence)
|
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
case 'A':
|
case 'A':
|
||||||
if escapeSequence == "^[[A" || escapeSequence == "^[A" {
|
if escapeSequence == "^[[A" || escapeSequence == "^[A" {
|
||||||
comm.WriteByte('U')
|
comm.WriteByte('U')
|
||||||
// fmt.Printf("Up: %s\n", escapeSequence)
|
|
||||||
} else {
|
} else {
|
||||||
var up int
|
var up int
|
||||||
fmt.Sscanf(escapeSequence, "^[[%dA", &up)
|
fmt.Sscanf(escapeSequence, "^[[%dA", &up)
|
||||||
for i := 0; i < up; i++ {
|
for i := 0; i < up; i++ {
|
||||||
comm.WriteByte('U')
|
comm.WriteByte('U')
|
||||||
}
|
}
|
||||||
// fmt.Printf("Up (%d): %s\n", up, escapeSequence)
|
|
||||||
}
|
}
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
case 'B':
|
case 'B':
|
||||||
@ -180,40 +163,34 @@ func sendCharacter(comm A2Io, b byte) {
|
|||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
} else if escapeSequence == "^[[B" {
|
} else if escapeSequence == "^[[B" {
|
||||||
comm.WriteByte(0x0a)
|
comm.WriteByte(0x0a)
|
||||||
// fmt.Printf("Down: %s\n", escapeSequence)
|
|
||||||
} else {
|
} else {
|
||||||
var down int
|
var down int
|
||||||
fmt.Sscanf(escapeSequence, "^[[%dB", &down)
|
fmt.Sscanf(escapeSequence, "^[[%dB", &down)
|
||||||
for i := 0; i < down; i++ {
|
for i := 0; i < down; i++ {
|
||||||
comm.WriteByte(0x0a)
|
comm.WriteByte(0x0a)
|
||||||
}
|
}
|
||||||
// fmt.Printf("Down (%d): %s\n", down, escapeSequence)
|
|
||||||
}
|
}
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
case 'C':
|
case 'C':
|
||||||
if escapeSequence == "^[[C" || escapeSequence == "^[C" {
|
if escapeSequence == "^[[C" || escapeSequence == "^[C" {
|
||||||
comm.WriteByte(0x1c)
|
comm.WriteByte(0x1c)
|
||||||
// fmt.Printf("Right: %s\n", escapeSequence)
|
|
||||||
} else {
|
} else {
|
||||||
var right int
|
var right int
|
||||||
fmt.Sscanf(escapeSequence, "^[[%dC", &right)
|
fmt.Sscanf(escapeSequence, "^[[%dC", &right)
|
||||||
for i := 0; i < right; i++ {
|
for i := 0; i < right; i++ {
|
||||||
comm.WriteByte(0x1c)
|
comm.WriteByte(0x1c)
|
||||||
}
|
}
|
||||||
// fmt.Printf("Right (%d): %s\n", right, escapeSequence)
|
|
||||||
}
|
}
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
case 'D':
|
case 'D':
|
||||||
if escapeSequence == "^[[D" || escapeSequence == "^[D" {
|
if escapeSequence == "^[[D" {
|
||||||
comm.WriteByte(0x08)
|
comm.WriteByte(0x08)
|
||||||
// fmt.Printf("Left: %s\n", escapeSequence)
|
|
||||||
} else {
|
} else {
|
||||||
var left int
|
var left int
|
||||||
fmt.Sscanf(escapeSequence, "^[[%dD", &left)
|
fmt.Sscanf(escapeSequence, "^[[%dD", &left)
|
||||||
for i := 0; i < left; i++ {
|
for i := 0; i < left; i++ {
|
||||||
comm.WriteByte(0x08)
|
comm.WriteByte(0x08)
|
||||||
}
|
}
|
||||||
// fmt.Printf("Left (%d): %s\n", left, escapeSequence)
|
|
||||||
}
|
}
|
||||||
escapeSequence = ""
|
escapeSequence = ""
|
||||||
}
|
}
|
||||||
@ -225,7 +202,6 @@ func sendCharacter(comm A2Io, b byte) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//fmt.Print(string(b))
|
|
||||||
switch b {
|
switch b {
|
||||||
// convert LF to CR for Apple II compatiblity
|
// convert LF to CR for Apple II compatiblity
|
||||||
case 10:
|
case 10:
|
||||||
|
@ -21,11 +21,11 @@ func ShellCommand() {
|
|||||||
cmd.Env = append(os.Environ(),
|
cmd.Env = append(os.Environ(),
|
||||||
"TERM=vt100",
|
"TERM=vt100",
|
||||||
"LINES=24",
|
"LINES=24",
|
||||||
"COLUMNS=80",
|
"COLUMNS=79",
|
||||||
)
|
)
|
||||||
|
|
||||||
var ws pty.Winsize
|
var ws pty.Winsize
|
||||||
ws.Cols = 80
|
ws.Cols = 79
|
||||||
ws.Rows = 24
|
ws.Rows = 24
|
||||||
ws.X = 0
|
ws.X = 0
|
||||||
ws.Y = 0
|
ws.Y = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user