syscalls: 'terminal-columns' ignores non-file ports.

* guix/build/syscalls.scm (terminal-columns): Call
'terminal-window-size' only when PORT is a file port.
* tests/syscalls.scm ("terminal-columns non-file port"): New test.
This commit is contained in:
Ludovic Courtès 2016-04-15 19:47:35 +02:00
parent 9f088725c0
commit 6d2b43915f
2 changed files with 10 additions and 4 deletions

View File

@ -915,10 +915,12 @@ always a positive integer."
(catch 'system-error (catch 'system-error
(lambda () (lambda ()
(match (window-size-columns (terminal-window-size port)) (if (file-port? port)
;; Things like Emacs shell-mode return 0, which is unreasonable. (match (window-size-columns (terminal-window-size port))
(0 (fall-back)) ;; Things like Emacs shell-mode return 0, which is unreasonable.
((? number? columns) columns))) (0 (fall-back))
((? number? columns) columns))
(fall-back)))
(lambda args (lambda args
(let ((errno (system-error-errno args))) (let ((errno (system-error-errno args)))
(if (= errno ENOTTY) (if (= errno ENOTTY)

View File

@ -257,4 +257,8 @@
(test-assert "terminal-columns" (test-assert "terminal-columns"
(> (terminal-columns) 0)) (> (terminal-columns) 0))
(test-assert "terminal-columns non-file port"
(> (terminal-columns (open-input-string "Join us now, share the software!"))
0))
(test-end) (test-end)