From 524c3176bb3a156b0fd998cf625e480123db671d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 15 Jun 2024 23:05:48 -0500 Subject: Implement verbatim piping --- lib/emit.scm | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'lib') 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 @@ (chicken irregex) (chicken port) (chicken process) + (chicken process-context) (chicken string) (only utf8-srfi-13 string-join) (jimmy util)) @@ -79,24 +80,30 @@ (format/filter el 'stanza text))))) (define (format-verb stanza) + (define (emit-verbatim t) + (printf (get-format 'verb 'stanza) + ((get-filter 'verb 'stanza) t))) (let ((el (car stanza)) - (text (apply append (cdr stanza)))) + (text (string-join (apply append (cdr stanza)) "\n"))) (with-output-to-string (lambda () (cond ((and (pair? (cdr el)) (equal? (cadr el) "|")) ;; special case: pipe to an external process - (let ((cmdline (cddr el))) - (if (find-command (car cmdline) #;) + (let* ((cmdline (cddr el)) + (command (find-command (car cmdline)) #;)) + (if command (receive (in out pid) - (process (car cmdline) (cdr cmdline) - `(("JIMMY_OUTPUT" . ,(->string (output-type))))) + (process command (cdr cmdline) + (cons `("JIMMY_OUTPUT" . ,(->string (output-type))) + (get-environment-variables))) (display (ensure-newline text) out) - (read-string #f in))))) - (else ; verbatim baby - (printf (get-format 'verb 'stanza) - ((get-filter 'verb 'stanza) text)))))))) + (close-output-port out) + (display (read-string #f in)) + (newline)) + (emit-verbatim t)))) + (else (emit-verbatim t))))))) ;;; Utilities -- cgit 1.4.1-21-gabe81