5 // terminalImageRequest reads /image with one path and an optional caption.
6 // Single and double quotes permit spaces in a path, with no shell expansion. An
7 // invalid path argument becomes an empty path for the daemon to refuse.
8 func terminalImageRequest(line string) (SocketRequest, bool) {
9 rest, found := strings.CutPrefix(strings.TrimLeft(line, " \t"), "/image")
10 if !found || (rest != "" && rest[0] != ' ' && rest[0] != '\t') {
11 return SocketRequest{}, false
14 request := SocketRequest{Type: "image"}
15 rest = strings.TrimLeft(rest, " \t")
20 if rest[0] == '\'' || rest[0] == '"' {
21 end := strings.IndexByte(rest[1:], rest[0])
26 request.Path = rest[1 : 1+end]
28 if rest != "" && rest[0] != ' ' && rest[0] != '\t' {
33 end := strings.IndexAny(rest, " \t")
39 request.Path = rest[:end]
43 request.Text = strings.TrimLeft(rest, " \t")