unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 36390@debbugs.gnu.org
Subject: [bug#36390] [PATCH 2/3] syscalls: Add 'terminal-rows'.
Date: Wed, 26 Jun 2019 10:59:03 +0200	[thread overview]
Message-ID: <20190626085904.3560-2-ludo@gnu.org> (raw)
In-Reply-To: <20190626085904.3560-1-ludo@gnu.org>

* guix/build/syscalls.scm (terminal-dimension): New procedure.
(terminal-columns): Rewrite in terms of 'terminal-dimension'.
(terminal-rows): New procedure.
* tests/syscalls.scm ("terminal-rows"): New test.
---
 guix/build/syscalls.scm | 37 +++++++++++++++++++++++++------------
 tests/syscalls.scm      |  5 ++++-
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 5c2eb3c14d..eb045cbd1c 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -146,6 +146,7 @@
             window-size-y-pixels
             terminal-window-size
             terminal-columns
+            terminal-rows
 
             utmpx?
             utmpx-login-type
@@ -1871,23 +1872,17 @@ corresponds to the TIOCGWINSZ ioctl."
                (list (strerror err))
                (list err)))))
 
-(define* (terminal-columns #:optional (port (current-output-port)))
-  "Return the best approximation of the number of columns of the terminal at
-PORT, trying to guess a reasonable value if all else fails.  The result is
-always a positive integer."
-  (define (fall-back)
-    (match (and=> (getenv "COLUMNS") string->number)
-      (#f 80)
-      ((? number? columns)
-       (if (> columns 0) columns 80))))
-
+(define (terminal-dimension window-dimension port fall-back)
+  "Return the terminal dimension defined by WINDOW-DIMENSION, one of
+'window-size-columns' or 'window-size-rows' for PORT.  If PORT does not
+correspond to a terminal, return the value returned by FALL-BACK."
   (catch 'system-error
     (lambda ()
       (if (file-port? port)
-          (match (window-size-columns (terminal-window-size port))
+          (match (window-dimension (terminal-window-size port))
             ;; Things like Emacs shell-mode return 0, which is unreasonable.
             (0 (fall-back))
-            ((? number? columns) columns))
+            ((? number? n) n))
           (fall-back)))
     (lambda args
       (let ((errno (system-error-errno args)))
@@ -1900,6 +1895,24 @@ always a positive integer."
             (fall-back)
             (apply throw args))))))
 
+(define* (terminal-columns #:optional (port (current-output-port)))
+  "Return the best approximation of the number of columns of the terminal at
+PORT, trying to guess a reasonable value if all else fails.  The result is
+always a positive integer."
+  (define (fall-back)
+    (match (and=> (getenv "COLUMNS") string->number)
+      (#f 80)
+      ((? number? columns)
+       (if (> columns 0) columns 80))))
+
+  (terminal-dimension window-size-columns port fall-back))
+
+(define* (terminal-rows #:optional (port (current-output-port)))
+  "Return the best approximation of the number of rows of the terminal at
+PORT, trying to guess a reasonable value if all else fails.  The result is
+always a positive integer."
+  (terminal-dimension window-size-rows port (const 25)))
+
 \f
 ;;;
 ;;; utmpx.
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index 3e267c9f01..eeb223b950 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -538,6 +538,9 @@
   (> (terminal-columns (open-input-string "Join us now, share the software!"))
      0))
 
+(test-assert "terminal-rows"
+  (> (terminal-rows) 0))
+
 (test-assert "utmpx-entries"
   (match (utmpx-entries)
     (((? utmpx? entries) ...)
-- 
2.22.0

  reply	other threads:[~2019-06-26  9:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26  8:43 [bug#36390] [PATCH 0/3] Improve 'guix search' relevance and display Ludovic Courtès
2019-06-26  8:59 ` [bug#36390] [PATCH 1/3] ui: 'relevance' considers regexps connected with a logical and Ludovic Courtès
2019-06-26  8:59   ` Ludovic Courtès [this message]
2019-06-26  8:59   ` [bug#36390] [PATCH 3/3] ui: Add 'display-search-results' and use it Ludovic Courtès
2019-06-26  9:57 ` [bug#36390] [PATCH 0/3] Improve 'guix search' relevance and display Ricardo Wurmus
2019-06-27  9:19   ` bug#36390: " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190626085904.3560-2-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=36390@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).