about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-06-15 23:05:48 -0500
committerCase Duckworth2024-06-15 23:05:48 -0500
commit524c3176bb3a156b0fd998cf625e480123db671d (patch)
treedf2dc916f655ffe486e98d86005ce2e8183e8371
parentRemove coment (diff)
downloadjimmy-524c3176bb3a156b0fd998cf625e480123db671d.tar.gz
jimmy-524c3176bb3a156b0fd998cf625e480123db671d.zip
Implement verbatim piping
-rw-r--r--lib/emit.scm25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/emit.scm b/lib/emit.scm index 546ec5c..68912cf 100644 --- a/lib/emit.scm +++ b/lib/emit.scm
@@ -6,6 +6,7 @@
6 (chicken irregex) 6 (chicken irregex)
7 (chicken port) 7 (chicken port)
8 (chicken process) 8 (chicken process)
9 (chicken process-context)
9 (chicken string) 10 (chicken string)
10 (only utf8-srfi-13 string-join) 11 (only utf8-srfi-13 string-join)
11 (jimmy util)) 12 (jimmy util))
@@ -79,24 +80,30 @@
79 (format/filter el 'stanza text))))) 80 (format/filter el 'stanza text)))))
80 81
81(define (format-verb stanza) 82(define (format-verb stanza)
83 (define (emit-verbatim t)
84 (printf (get-format 'verb 'stanza)
85 ((get-filter 'verb 'stanza) t)))
82 (let ((el (car stanza)) 86 (let ((el (car stanza))
83 (text (apply append (cdr stanza)))) 87 (text (string-join (apply append (cdr stanza)) "\n")))
84 (with-output-to-string 88 (with-output-to-string
85 (lambda () 89 (lambda ()
86 (cond 90 (cond
87 ((and (pair? (cdr el)) 91 ((and (pair? (cdr el))
88 (equal? (cadr el) "|")) 92 (equal? (cadr el) "|"))
89 ;; special case: pipe to an external process 93 ;; special case: pipe to an external process
90 (let ((cmdline (cddr el))) 94 (let* ((cmdline (cddr el))
91 (if (find-command (car cmdline) #;<TODO:JIMMY_PATH>) 95 (command (find-command (car cmdline)) #;<TODO:JIMMY_PATH>))
96 (if command
92 (receive (in out pid) 97 (receive (in out pid)
93 (process (car cmdline) (cdr cmdline) 98 (process command (cdr cmdline)
94 `(("JIMMY_OUTPUT" . ,(->string (output-type))))) 99 (cons `("JIMMY_OUTPUT" . ,(->string (output-type)))
100 (get-environment-variables)))
95 (display (ensure-newline text) out) 101 (display (ensure-newline text) out)
96 (read-string #f in))))) 102 (close-output-port out)
97 (else ; verbatim baby 103 (display (read-string #f in))
98 (printf (get-format 'verb 'stanza) 104 (newline))
99 ((get-filter 'verb 'stanza) text)))))))) 105 (emit-verbatim t))))
106 (else (emit-verbatim t)))))))
100 107
101;;; Utilities 108;;; Utilities
102 109