all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thievol@posteo.net>
To: Jim Porter <jporterbugs@gmail.com>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 54774@debbugs.gnu.org
Subject: bug#54774: 28.1; ansi-color with no colors in Emacs-28
Date: Sat, 09 Apr 2022 18:18:18 +0000	[thread overview]
Message-ID: <87ee262jta.fsf@posteo.net> (raw)
In-Reply-To: <fa1a0da8-7a3f-0712-87a7-5b8f7db2d987@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3279 bytes --]


Jim Porter <jporterbugs@gmail.com> writes:

> On 4/9/2022 12:25 AM, Thierry Volpiatto wrote:
>> Apart advicing `ansi-color-get-face-1` I couldn't find how to fix my
>> code as your changes are binding ansi-code 5 to `ansi-color-slow-blink`
>> face which create unwanted squares.
>
> I had a chance to look into this a bit more.

Many thanks to take the time to look into this.

> ansi-color.el has mis-parsed 256-color and 24-bit color escapes for a
> long time. For example, you can try this under Emacs 27.2:
>
>   (ansi-color-apply "\033[38;5;2mhi\033[0m")
>     -> #("hi" 0 2 (font-lock-face success))
>
> This should actually be equivalent to the 8-color green value (ANSI
> SGR value 32). (Note: Under Emacs 27.2, the "slow blink" face is
> mapped to `success', whereas in 28.1, it's mapped to
> `ansi-color-slow-blink'. In Emacs 29, this properly sets the
> foreground to green.)
>
> Normally this isn't an issue, since Emacs' shell/term modes indicate
> that they only support 8-color mode, so commands usually don't emit 
> 256-color sequences. However, in your case this looks to be some text
> from a web service, so it obviously can't inspect your terminal 
> capabilities (unless there's a way to send them in the request?).

Ok, thanks for explaining.

> Looking at your code in more detail, I think you just got lucky that
> things worked ok in Emacs 27. See here:
>
>             (while (re-search-forward "38;5;\\([0-9]+\\)m" nil t)
>                ;; ...
>                (replace-match (pcase (match-string 1)
>                                ("154" "32")
>                                ("190" "31")
>                                ("118" "32")
>                                ("208" "37")
>                                ("202" "34")
>                                ("214" "35")
>                                ("220" "36")
>                                ("226" "33")
>                                (r     r))
>                              t t nil 1))
>
> This replaces an ANSI escape like "\033[38;5;154m" with
> "\033[38;5;32m". So the 256-color ANSI escape is still there, just
> slightly transformed. I think you want the result to be "\033[32m"
> instead, so that you're not using 256-color escape sequences at all.
>
> If you adjust the regexp/replacement to remove the "38;5;" bit, I
> think your existing code should work fine in both Emacs 27 and 28.

Indeed following your advice it work fine with both Emacs-28 and
Emacs-27:

    (while (re-search-forward "\\(38;5;[0-9]+\\)m" nil t)
      (when (< emacs-major-version 29)
        (replace-match (pcase (match-string 1)
                         ("38;5;154" "32")             ; green
                         ("38;5;190" "31")             ; red
                         ("38;5;118" "32")             ; green
                         ("38;5;208" "37")             ; white
                         ("38;5;202" "34")             ; blue
                         ("38;5;214" "35")             ; magenta
                         ("38;5;220" "36")             ; cyan
                         ("38;5;226" "33")             ; yellow
                         (r     r))
                       t t nil 1)))

-- 
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]

  reply	other threads:[~2022-04-09 18:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07 19:49 bug#54774: 28.1; ansi-color with no colors in Emacs-28 Thierry Volpiatto
2022-04-07 20:10 ` Thierry Volpiatto
2022-04-07 20:24   ` Thierry Volpiatto
2022-04-08 13:23 ` Lars Ingebrigtsen
2022-04-08 17:48   ` Thierry Volpiatto
2022-04-08 18:23   ` Jim Porter
2022-04-09  7:25     ` Thierry Volpiatto
2022-04-09 17:31       ` Jim Porter
2022-04-09 18:18         ` Thierry Volpiatto [this message]
2022-04-10 12:01           ` Lars Ingebrigtsen

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

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

  git send-email \
    --in-reply-to=87ee262jta.fsf@posteo.net \
    --to=thievol@posteo.net \
    --cc=54774@debbugs.gnu.org \
    --cc=jporterbugs@gmail.com \
    --cc=larsi@gnus.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.