unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Bruno Victal <mirai@makinata.eu>
Cc: 62056@debbugs.gnu.org
Subject: [bug#62056] [PATCH] guix: Only issue erase-current-line sequence for ttys.
Date: Tue, 18 Apr 2023 22:02:00 +0200	[thread overview]
Message-ID: <877cu9hscn.fsf_-_@gnu.org> (raw)
In-Reply-To: <99afbc21-920c-1867-e368-d541ae524283@makinata.eu> (Bruno Victal's message of "Sat, 18 Mar 2023 11:27:12 +0000")

Hi Bruno,

Bruno Victal <mirai@makinata.eu> skribis:

> On 2023-03-16 21:30, Ludovic Courtès wrote:
>> Bruno Victal <mirai@makinata.eu> skribis:
>>>  (define (erase-current-line port)
>>> -  "Write an ANSI erase-current-line sequence to PORT to erase the whole line and
>>> -move the cursor to the beginning of the line."
>>> -  (display "\r\x1b[K" port))
>>> +  "When @var{port} is interactive, write an ANSI erase-current-line sequence
>>> +to erase the whole line and move the cursor to the beginning of the line,
>>> +otherwise write a newline."
>>> +  (if (isatty? port)
>>> +      (display "\r\x1b[K" port)
>>> +      (newline port)))
>> 
>> We should avoid calling ‘isatty?’ every time, it’s too costly, which is
>> why there’s also ‘isatty?*’ somewhere that memoizes things.
>> 
>> However, it seems up to the caller to check that before calling
>> ‘erase-current-line’.  That seems to be the case within progress.scm and
>> in (guix status).
>
> guix/status.scm:471 defines a erase-current-line* which calls isatty?*.
> Does this mean that erase-current-line has to be “wrapped” every time
> we want it to have tty awareness?

‘erase-current-line’ is low-level and often the caller has already done
an ‘isatty?’ check before calling it (for instance in progress bars).  I
think that’s the reason it doesn’t include that check.

> If that's not the case, perhaps we could change the signature of erase-current-line to:
> (define* (erase-current-line port #:optional tty?)

I don’t think so.

>> Could you see which use of ‘erase-current-line’ is causing problems?
>
> guix/scripts/substitute.scm:318

In this particular case, how about returning a different
<progress-reporter> depending on ‘isatty?’?

Thanks,
Ludo’.




  reply	other threads:[~2023-04-18 20:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 15:55 [bug#62056] [PATCH] guix: Only issue erase-current-line sequence for ttys Bruno Victal
2023-03-16 21:30 ` Ludovic Courtès
2023-03-18 11:27   ` Bruno Victal
2023-04-18 20:02     ` Ludovic Courtès [this message]
2023-05-28  9:54       ` Bruno Victal
2024-06-02 20:19 ` [bug#62056] Custom progress reporter for scripts/substitute.scm Richard Sent

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=877cu9hscn.fsf_-_@gnu.org \
    --to=ludo@gnu.org \
    --cc=62056@debbugs.gnu.org \
    --cc=mirai@makinata.eu \
    /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).