Now that we have seen how to create a basic pseudo-terminal, we will see how to improve it with some additional features.
Improving the PTY
Multiline input
The first thing that can be improved is the relationship between arguments and spacing, by adding support for quoted strings. This can be done with bufio.Scanner with a custom split function that behaves like bufio.ScanWords apart from the fact that it's aware of quotes. The following code demonstrates this:Â
func ScanArgs(data []byte, atEOF bool) (advance int, token []byte, err error) {
// first space
start, first := 0, rune(0)
for width := 0; start < len(data); start += width {
first, width = utf8.DecodeRune(data[start:])
...