GNU bug report logs - #62056
[PATCH] guix: Only issue erase-current-line sequence for ttys.

Previous Next

Package: guix-patches;

Reported by: Bruno Victal <mirai <at> makinata.eu>

Date: Wed, 8 Mar 2023 15:57:01 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 62056 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#62056; Package guix-patches. (Wed, 08 Mar 2023 15:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Bruno Victal <mirai <at> makinata.eu>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 08 Mar 2023 15:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: guix-patches <at> gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>
Subject: [PATCH] guix: Only issue erase-current-line sequence for ttys.
Date: Wed,  8 Mar 2023 15:55:56 +0000
* guix/progress.scm (erase-current-line): Only issue erase-current-line sequence for ttys.
---

Avoids cluttering log lines with �[K when output is logged to a file.

 guix/progress.scm | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/guix/progress.scm b/guix/progress.scm
index 33cf6f4a1a..a1cdd25557 100644
--- a/guix/progress.scm
+++ b/guix/progress.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2015 Steve Sprang <scs <at> stevesprang.com>
 ;;; Copyright © 2017, 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2018 Clément Lassieur <clement <at> lassieur.org>
+;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -209,9 +210,12 @@ (define* (progress-bar % #:optional (bar-width 20))
                    (string (progress-bar-style-stop bar-style)))))
 
 (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)))
 
 (define* (display-download-progress file size
                                     #:key

base-commit: 85d4e8af5baf9b0a9cadf95d802674d0254433da
-- 
2.39.1





Information forwarded to guix-patches <at> gnu.org:
bug#62056; Package guix-patches. (Thu, 16 Mar 2023 21:31:02 GMT) Full text and rfc822 format available.

Message #8 received at 62056 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Bruno Victal <mirai <at> makinata.eu>
Cc: 62056 <at> debbugs.gnu.org
Subject: Re: bug#62056: [PATCH] guix: Only issue erase-current-line sequence
 for ttys.
Date: Thu, 16 Mar 2023 22:30:06 +0100
Hi,

Bruno Victal <mirai <at> makinata.eu> skribis:

> * guix/progress.scm (erase-current-line): Only issue erase-current-line sequence for ttys.
> ---
>
> Avoids cluttering log lines with �[K when output is logged to a file.

+1!

>  (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).

Could you see which use of ‘erase-current-line’ is causing problems?

TIA,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#62056; Package guix-patches. (Sat, 18 Mar 2023 11:45:01 GMT) Full text and rfc822 format available.

Message #11 received at 62056 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 62056 <at> debbugs.gnu.org
Subject: Re: bug#62056: [PATCH] guix: Only issue erase-current-line sequence
 for ttys.
Date: Sat, 18 Mar 2023 11:27:12 +0000
Hi Ludo’,

On 2023-03-16 21:30, Ludovic Courtès wrote:
> Bruno Victal <mirai <at> 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?

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


> Could you see which use of ‘erase-current-line’ is causing problems?

guix/scripts/substitute.scm:318


Cheers,
Bruno




Information forwarded to guix-patches <at> gnu.org:
bug#62056; Package guix-patches. (Tue, 18 Apr 2023 20:03:02 GMT) Full text and rfc822 format available.

Message #14 received at 62056 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Bruno Victal <mirai <at> makinata.eu>
Cc: 62056 <at> debbugs.gnu.org
Subject: Re: bug#62056: [PATCH] guix: Only issue erase-current-line sequence
 for ttys.
Date: Tue, 18 Apr 2023 22:02:00 +0200
Hi Bruno,

Bruno Victal <mirai <at> makinata.eu> skribis:

> On 2023-03-16 21:30, Ludovic Courtès wrote:
>> Bruno Victal <mirai <at> 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’.




Information forwarded to guix-patches <at> gnu.org:
bug#62056; Package guix-patches. (Sun, 28 May 2023 09:55:02 GMT) Full text and rfc822 format available.

Message #17 received at 62056 <at> debbugs.gnu.org (full text, mbox):

From: Bruno Victal <mirai <at> makinata.eu>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 62056 <at> debbugs.gnu.org
Subject: Re: bug#62056: [PATCH] guix: Only issue erase-current-line sequence
 for ttys.
Date: Sun, 28 May 2023 10:54:36 +0100
Hi Ludo’,

On 2023-04-18 21:02, Ludovic Courtès wrote:
> Bruno Victal <mirai <at> makinata.eu> skribis:
>> On 2023-03-16 21:30, Ludovic Courtès wrote:
>>> 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?’?

It looks like the problem was not just at that particular line, rather
anywhere that happens to call (erase-current-line …) which in addition
to guix/scripts/substitute.scm are guix/status.scm and guix/progress.scm.

Perhaps every instance of <progress-reporter> under guix/ should be
checking whether or not they are running under a tty?

WDYT?

-- 
Furthermore, I consider that nonfree software must be eradicated.

Cheers,
Bruno.




Information forwarded to guix-patches <at> gnu.org:
bug#62056; Package guix-patches. (Sun, 02 Jun 2024 20:20:02 GMT) Full text and rfc822 format available.

Message #20 received at 62056 <at> debbugs.gnu.org (full text, mbox):

From: Richard Sent <richard <at> freakingpenguin.com>
To: 62056 <at> debbugs.gnu.org 
Subject: Custom progress reporter for scripts/substitute.scm
Date: Sun, 02 Jun 2024 16:19:02 -0400
I started investigating this issue for the substitutes script
specifically and it's more challenging than a straightforward isatty?
call. I opened an issue for that here:
https://issues.guix.gnu.org/71299

I agree that modifying erase-current-line isn't the right solution. I
think it's the responsibility of the caller to ensure that the output
port is appropriate.

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.




This bug report was last modified 1 year and 78 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.