* bug#54774: 28.1; ansi-color with no colors in Emacs-28
@ 2022-04-07 19:49 Thierry Volpiatto
2022-04-07 20:10 ` Thierry Volpiatto
2022-04-08 13:23 ` Lars Ingebrigtsen
0 siblings, 2 replies; 10+ messages in thread
From: Thierry Volpiatto @ 2022-04-07 19:49 UTC (permalink / raw)
To: 54774
[-- Attachment #1: Type: text/plain, Size: 10871 bytes --]
Hello,
it seems using ansi-color-apply in Emacs-28 is not working properly,
there is no colors. In Emacs-29 it is working properly (very nice)
without needing a workaround used previously in emacs-27 (code commented).
See code below to reproduce and Screenshots attached.
Thanks.
#+begin_src elisp
(defvar wttr-weather-history nil)
(defvar wttr-weather-default-location "Guillestre")
(defvar wttr-weather-last-location nil)
;;;###autoload
(defun wttr-weather (place)
"Weather forecast with wttr.in.
With a prefix arg refresh buffer if some.
See <https://github.com/chubin/wttr.in>."
(interactive (list (read-string (format "Place (%s): "
wttr-weather-default-location)
nil
'wttr-weather-history
wttr-weather-default-location)))
(let ((buf (get-buffer-create (format "*wttr.in %s*" place))))
(switch-to-buffer buf)
(when current-prefix-arg
(set (make-local-variable 'wttr-weather-last-location) nil))
(unless wttr-weather-last-location
(wttr-weather-update place)
(wttr-weather-mode)
(set (make-local-variable 'wttr-weather-last-location) place))))
(defun wttr-weather-update (place)
(let* ((inhibit-read-only t)
ansi
(data
(with-temp-buffer
(call-process
"curl" nil '(t t) nil
"-s" (format "fr.wttr.in/~%s?m" (shell-quote-argument place)))
(goto-char (point-min))
;; Commenting this part which is for Emacs-27.
;; `ansi' is not set but it is not a problem for just
;; debugging this.
;;
;; (while (re-search-forward "38;5;\\([0-9]+\\)m" nil t)
;; ;; If we have ansi sequences, that's mean we had weather
;; ;; output, otherwise we have a simple message notifying
;; ;; weather report is not available.
;; (setq ansi t)
;; ;; Need a 256 color ansi library, emacs supports only basic
;; ;; ansi colors as now, so replace all 38;5 foreground
;; ;; specs by simple ansi sequences.
;; (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))
(ansi-color-apply (buffer-string)))))
(erase-buffer)
(save-excursion
(if data
(insert data)
;; Probaly check error status instead (it is 52).
(insert "Empy reply from server"))
(forward-line -1)
(when (and ansi ; Keep notification when no weather report.
(re-search-backward "^$" nil t))
(delete-region (point) (point-max))))
(while (re-search-forward "\\s\\" (point-at-eol) t) (replace-match ""))
(goto-char (point-at-eol))
(insert (format-time-string " le %d/%m/%Y à %H:%M:%S"))))
(defun wttr-weather-revert-fn (_ignore-auto _no_confirm)
(wttr-weather-update wttr-weather-last-location))
(define-derived-mode wttr-weather-mode special-mode "wttr"
(make-local-variable 'wttr-weather-last-location)
(set (make-local-variable 'revert-buffer-function) 'wttr-weather-revert-fn))
#+end_src
In GNU Emacs 28.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
of 2022-04-05 built on IPad-S340
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Linux Mint 20.2
Configured using:
'configure CFLAGS=-O8 --with-mailutils --with-cairo
--with-native-compilation'
Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB
Important settings:
value of $LANG: fr_FR.UTF-8
locale-coding-system: utf-8-unix
Major mode: ƐĽ
Minor modes in effect:
bug-reference-prog-mode: t
global-undo-tree-mode: t
undo-tree-mode: t
psession-mode: t
psession-savehist-mode: t
global-git-gutter-mode: t
git-gutter-mode: t
display-time-mode: t
winner-mode: t
helm-epa-mode: t
helm-descbinds-mode: t
helm-adaptive-mode: t
helm-mode: t
helm-minibuffer-history-mode: t
helm-ff-icon-mode: t
shell-dirtrack-mode: t
helm-popup-tip-mode: t
async-bytecomp-package-mode: t
dired-async-mode: t
minibuffer-depth-indicate-mode: t
override-global-mode: t
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
show-paren-mode: t
mouse-wheel-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
column-number-mode: t
line-number-mode: t
transient-mark-mode: t
Load-path shadows:
None found.
Features:
(epa-mail face-remap char-fold image-file image-converter helm-x-files
helm-for-files addressbook-bookmark mu4e-config org-mu4e mu4e-contrib
mu4e-patch mu4e mu4e-org mu4e-view gnus-art mm-uu mml2015 mm-view
mml-smime smime dig gnus-sum gnus-group gnus-undo gnus-start gnus-dbus
gnus-cloud nnimap nnmail mail-source utf7 netrc nnoo gnus-spec gnus-int
gnus-range gnus-win mu4e-main mu4e-headers mu4e-lists mu4e-compose
mu4e-draft mu4e-actions smtpmail mu4e-search mu4e-bookmarks mu4e-mark
mu4e-message shr kinsoku svg flow-fill hl-line mu4e-contacts mu4e-update
mu4e-folders mu4e-server mu4e-context mu4e-vars mu4e-helpers ido
mu4e-meta shadow sort mail-extr emacsbug sendmail tramp-archive
tramp-gvfs tramp-cache zeroconf dbus helm-command flymake-proc flymake
project make-mode vc-filewise vc-rcs conf-mode ledger-config ledger-mode
ledger-check ledger-texi ledger-test ledger-sort ledger-report
ledger-reconcile ledger-occur ledger-fonts ledger-fontify ledger-state
ledger-complete ledger-schedule ledger-init ledger-xact ledger-post
ledger-exec ledger-navigate eshell esh-cmd esh-ext esh-opt esh-proc
esh-io esh-arg esh-module esh-groups esh-util ledger-context
ledger-commodities ledger-regex markdown-mode bug-reference jka-compr
sh-script smie executable naquadah-theme solar cal-dst holidays
hol-loaddefs tv-utils osm dom yaml-mode undo-tree diff queue
rainbow-mode color psession frameset log-view pcvs-util pcmpl-git
cl-indent ffap thingatpt autocrypt-message message rmc puny rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader autocrypt-gnus gnus nnheader gnus-util rmail
rmail-loaddefs rfc2047 rfc2045 mail-utils mm-util mail-prsvr
autocrypt-mu4e autocrypt ietf-drums config-w3m git-gutter mule-util appt
diary-lib diary-loaddefs gud pcomplete-extension pcmpl-unix pcmpl-gnu
iterator pcase wdired dired-extension org-config ob-gnuplot org-crypt
net-utils time winner autotest-mode autoconf-mode woman man ediff
ediff-merg ediff-mult ediff-wind ediff-diff ediff-help ediff-init
ediff-util init-helm helm-ls-git vc-git diff-mode vc vc-dispatcher
helm-fd epa derived epg rfc6068 epg-config helm-epa helm-imenu imenu
helm-elisp-package helm-find helm-org org ob ob-tangle ob-ref ob-lob
ob-table ob-exp org-macro org-footnote org-src ob-comint org-pcomplete
org-list org-faces org-entities noutline outline org-version
ob-emacs-lisp ob-core ob-eval org-table oc-basic bibtex ol org-keys oc
org-compat advice org-macs org-loaddefs cal-menu calendar cal-loaddefs
helm-external isearch-light helm-descbinds helm-wikipedia all-the-icons
all-the-icons-faces data-material data-weathericons data-octicons
data-fileicons data-faicons data-alltheicons cus-edit wid-edit
helm-ipython helm-elisp helm-eval edebug backtrace find-func python
tramp-sh helm-bookmark helm-net xml helm-info bookmark pp helm-adaptive
helm-mode helm-misc helm-files image-dired image-mode exif filenotify
tramp tramp-loaddefs trampver tramp-integration files-x tramp-compat
shell pcomplete parse-time iso8601 time-date ls-lisp helm-buffers
helm-occur helm-tags helm-locate helm-grep wgrep-helm wgrep grep compile
text-property-search comint ansi-color ring helm-regexp format-spec
helm-utils helm-help helm-types helm-extensions-autoloads helm-config
helm-autoloads helm helm-core async-bytecomp helm-global-bindings
helm-easymenu helm-source helm-multi-match helm-lib dired-async
dired-aux dired dired-loaddefs async popup diminish mb-depth server comp
comp-cstr warnings rx cl-extra help-mode edmacro kmacro avoid cus-load
use-package use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key easy-mmode use-package-core finder-inf
package browse-url url url-proxy url-privacy url-expand url-methods
url-history url-cookie url-domsuf url-util mailcap url-handlers
url-parse auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json subr-x map url-vars seq byte-opt gv bytecomp
byte-compile cconv cl-loaddefs cl-lib info w3m-load iso-transl tooltip
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)
Memory information:
((conses 16 893084 166497)
(symbols 48 43805 13)
(strings 32 244568 28635)
(string-bytes 1 6976950)
(vectors 16 86016)
(vector-slots 8 2303151 205471)
(floats 8 2821 2894)
(intervals 56 12355 7408)
(buffers 992 156))
<#secure method=pgpmime mode=sign>
--
Thierry
[-- Attachment #2: Capture d’écran_2022-04-07_21-21-51.png --]
[-- Type: image/png, Size: 156007 bytes --]
[-- Attachment #3: Capture d’écran_2022-04-07_21-35-10.png --]
[-- Type: image/png, Size: 148605 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
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
1 sibling, 1 reply; 10+ messages in thread
From: Thierry Volpiatto @ 2022-04-07 20:10 UTC (permalink / raw)
To: 54774
Also in ansi-color-underline, ansi-color-italic, ansi-color-bold there
is unneeded quotes, e.g. '((t :inherit 'bold))
--
Thierry
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
2022-04-07 20:10 ` Thierry Volpiatto
@ 2022-04-07 20:24 ` Thierry Volpiatto
0 siblings, 0 replies; 10+ messages in thread
From: Thierry Volpiatto @ 2022-04-07 20:24 UTC (permalink / raw)
To: 54774
Sorry one of the screenshot is the wrong one (the one with squares) it
has been taken with the commented code, it should be the same than the
first one but without colors.
--
Thierry
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
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-08 13:23 ` Lars Ingebrigtsen
2022-04-08 17:48 ` Thierry Volpiatto
2022-04-08 18:23 ` Jim Porter
1 sibling, 2 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-08 13:23 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: 54774
Thierry Volpiatto <thievol@posteo.net> writes:
> it seems using ansi-color-apply in Emacs-28 is not working properly,
> there is no colors. In Emacs-29 it is working properly (very nice)
> without needing a workaround used previously in emacs-27 (code commented).
> See code below to reproduce and Screenshots attached.
I'm not sure I understand this bug report. Are you asking for the code
in ansi-color in Emacs 29 to be backported to Emacs 28.2?
We're only doing that for regressions and serious bugs, so that's not
going to happen for the ansi-color stuff. (And besides, if I remember
correctly, the changes needed in ansi-color in Emacs 29 were rather
extensive, so it'd be impractical anyway.)
But perhaps I misunderstand what you mean here.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
2022-04-08 13:23 ` Lars Ingebrigtsen
@ 2022-04-08 17:48 ` Thierry Volpiatto
2022-04-08 18:23 ` Jim Porter
1 sibling, 0 replies; 10+ messages in thread
From: Thierry Volpiatto @ 2022-04-08 17:48 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 54774
[-- Attachment #1: Type: text/plain, Size: 684 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> it seems using ansi-color-apply in Emacs-28 is not working properly,
>> there is no colors. In Emacs-29 it is working properly (very nice)
>> without needing a workaround used previously in emacs-27 (code commented).
>> See code below to reproduce and Screenshots attached.
>
> I'm not sure I understand this bug report. Are you asking for the code
> in ansi-color in Emacs 29 to be backported to Emacs 28.2?
I am not asking for anything, it is up to you to decide what to be done.
I am just reporting that ansi-color on Emacs-28 is partially broken.
--
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
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
1 sibling, 1 reply; 10+ messages in thread
From: Jim Porter @ 2022-04-08 18:23 UTC (permalink / raw)
To: Lars Ingebrigtsen, Thierry Volpiatto; +Cc: 54774
On 4/8/2022 6:23 AM, Lars Ingebrigtsen wrote:
> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> it seems using ansi-color-apply in Emacs-28 is not working properly,
>> there is no colors. In Emacs-29 it is working properly (very nice)
>> without needing a workaround used previously in emacs-27 (code commented).
>> See code below to reproduce and Screenshots attached.
>
> I'm not sure I understand this bug report. Are you asking for the code
> in ansi-color in Emacs 29 to be backported to Emacs 28.2?
I think the issue is that there were some changes in Emacs 28.1 (by me,
see commit ceb9da3b7125fbdf0da04a3b158ac1e792c87f4f) to add support for
ANSI "bright" colors. In 29, Miha added support for 256-color and 24-bit
ANSI colors as well (see 0fa2279b90bf5a638d8377032b71135e1374e8fb).
I've verified that Emacs 28.1 properly handles normal and bright ANSI
colors in shell output. Bold/italic/etc works correctly as well, even
though I added an unnecessary quote to the face definitions - that's
been fixed in Emacs 29, and could be backported to 28, though I don't
think it causes any serious problems.
That said, it looks like Thierry had written some code for Emacs 27 that
scans the output of a command that uses ANSI 256-color sequences and
then translates those sequences into ANSI 8-color sequences that
ansi-color.el will understand. However, that code no longer works in
Emacs 28, possibly due to my changes to support ANSI bright colors. I'm
not sure this is actually a bug in Emacs; it may just mean that
Thierry's workaround needs to be updated to account for the
ansi-color.el changes I made.
I'm a little unclear about what actually broke though, and haven't had a
chance to dig deeper. Some basic testing of `ansi-color-apply' shows
that it does what I expect. From "emacs -Q":
(require 'ansi-color)
(ansi-color-apply "\033[44mfoo\033[0m")
-> #("foo" 0 3 (font-lock-face (:background "blue2")))
(ansi-color-apply "\033[44;33mfoo\033[0m")
-> #("foo" 0 3 (font-lock-face ((:foreground "yellow3")
(:background "blue2"))))
That's the same behavior as Emacs 27.2 with some trivial differences
(Emacs 27.2 uses `foreground-color' instead of `:foreground').
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
2022-04-08 18:23 ` Jim Porter
@ 2022-04-09 7:25 ` Thierry Volpiatto
2022-04-09 17:31 ` Jim Porter
0 siblings, 1 reply; 10+ messages in thread
From: Thierry Volpiatto @ 2022-04-09 7:25 UTC (permalink / raw)
To: Jim Porter; +Cc: Lars Ingebrigtsen, 54774
[-- Attachment #1: Type: text/plain, Size: 3927 bytes --]
Hello Jim and thanks for clarifications.
Jim Porter <jporterbugs@gmail.com> writes:
> On 4/8/2022 6:23 AM, Lars Ingebrigtsen wrote:
>> Thierry Volpiatto <thievol@posteo.net> writes:
>>
>>> it seems using ansi-color-apply in Emacs-28 is not working properly,
>>> there is no colors. In Emacs-29 it is working properly (very nice)
>>> without needing a workaround used previously in emacs-27 (code commented).
>>> See code below to reproduce and Screenshots attached.
>> I'm not sure I understand this bug report. Are you asking for the
>> code
>> in ansi-color in Emacs 29 to be backported to Emacs 28.2?
>
> I think the issue is that there were some changes in Emacs 28.1 (by
> me, see commit ceb9da3b7125fbdf0da04a3b158ac1e792c87f4f) to add
> support for ANSI "bright" colors.
Yes this is this commit that cause problems, commenting the first cond
clause of `ansi-color-get-face-1` allows having the same behavior as
with Emacs-27 with replacement of 256 colors sequences:
#+begin_src diff
diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index b379e710940..e9a251545ba 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -861,8 +861,8 @@ BRIGHT, if non-nil, requests \"bright\" ANSI colors, even if ANSI-CODE
is a normal-intensity color."
(when (and bright (<= 30 ansi-code 49))
(setq ansi-code (+ ansi-code 60)))
- (cond ((<= 0 ansi-code 7)
- (aref ansi-color-basic-faces-vector ansi-code))
+ (cond ;; ((<= 0 ansi-code 7)
+ ;; (aref ansi-color-basic-faces-vector ansi-code))
((<= 30 ansi-code 38)
(list :foreground
(face-foreground
#+end_src
I made a bug report on github to clarify what's wrong,
see https://github.com/thierryvolpiatto/emacs-config/issues/1.
> In 29, Miha added support for 256-color and 24-bit ANSI colors as well
> (see 0fa2279b90bf5a638d8377032b71135e1374e8fb).
Working fine without the need of replacing 256 sequences.
> I've verified that Emacs 28.1 properly handles normal and bright ANSI
> colors in shell output. Bold/italic/etc works correctly as well, even
> though I added an unnecessary quote to the face definitions - that's
> been fixed in Emacs 29, and could be backported to 28, though I don't
> think it causes any serious problems.
>
> That said, it looks like Thierry had written some code for Emacs 27
> that scans the output of a command that uses ANSI 256-color sequences
> and then translates those sequences into ANSI 8-color sequences that
> ansi-color.el will understand. However, that code no longer works in
> Emacs 28, possibly due to my changes to support ANSI bright
> colors. I'm not sure this is actually a bug in Emacs; it may just mean
> that Thierry's workaround needs to be updated to account for the
> ansi-color.el changes I made.
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'm a little unclear about what actually broke though, and haven't had
> a chance to dig deeper. Some basic testing of `ansi-color-apply' shows
> that it does what I expect. From "emacs -Q":
>
> (require 'ansi-color)
> (ansi-color-apply "\033[44mfoo\033[0m")
> -> #("foo" 0 3 (font-lock-face (:background "blue2")))
> (ansi-color-apply "\033[44;33mfoo\033[0m")
> -> #("foo" 0 3 (font-lock-face ((:foreground "yellow3")
> (:background "blue2"))))
>
> That's the same behavior as Emacs 27.2 with some trivial differences
> (Emacs 27.2 uses `foreground-color' instead of `:foreground').
You can have a try at my code which is here:
https://github.com/thierryvolpiatto/emacs-config/blob/main/tv-utils.el#L1097
with and without advicing `ansi-color-get-face-1`:
https://github.com/thierryvolpiatto/emacs-config/blob/main/init.el#L24
Thanks.
--
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]
^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
2022-04-09 7:25 ` Thierry Volpiatto
@ 2022-04-09 17:31 ` Jim Porter
2022-04-09 18:18 ` Thierry Volpiatto
0 siblings, 1 reply; 10+ messages in thread
From: Jim Porter @ 2022-04-09 17:31 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: Lars Ingebrigtsen, 54774
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. 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?).
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
2022-04-09 17:31 ` Jim Porter
@ 2022-04-09 18:18 ` Thierry Volpiatto
2022-04-10 12:01 ` Lars Ingebrigtsen
0 siblings, 1 reply; 10+ messages in thread
From: Thierry Volpiatto @ 2022-04-09 18:18 UTC (permalink / raw)
To: Jim Porter; +Cc: Lars Ingebrigtsen, 54774
[-- 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 --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#54774: 28.1; ansi-color with no colors in Emacs-28
2022-04-09 18:18 ` Thierry Volpiatto
@ 2022-04-10 12:01 ` Lars Ingebrigtsen
0 siblings, 0 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-10 12:01 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: Jim Porter, 54774
Thierry Volpiatto <thievol@posteo.net> writes:
> Indeed following your advice it work fine with both Emacs-28 and
> Emacs-27:
Then I guess there's nothing more to do here in this bug report, and I'm
therefore closing it.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-04-10 12:01 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2022-04-10 12:01 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.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).