unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Examining the output of a shell command?
Date: Mon, 29 Jun 2015 14:08:02 +0200	[thread overview]
Message-ID: <87mvziogyl.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: cvcobeF8753U1@mid.individual.net

Raffaele Ricciardi <rfflrccrd@gmail.com> writes:

> On 28/06/15 15:57, Pascal J. Bourguignon wrote:
>> (shell-command-to-string "echo $RED hello $NORMAL")
>> --> "[31m hello [0m> "
>
> Hence, how could I capture a colorized output in Emacs as in a Bash
> session?

This is an entirely different question, isn't it.

In *shell* and other comint based modes, you can activate interpretion
of ANSI escape codes for colorizing with 
M-x ansi-color-for-comint-mode-on RET

You can process the string with ansi-color-apply:

(ansi-color-apply
 (shell-command-to-string "echo $RED hello $YELLOW world $NORMAL"))
--> #(" hello  world 
" 0 7 (font-lock-face (foreground-color . "red")) 7 14 (font-lock-face (foreground-color . "yellow")))

(insert (ansi-color-apply
          (shell-command-to-string "echo $RED hello $YELLOW world $NORMAL")))
 hello  world 
  ^red    ^yellow
--> nil


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


  reply	other threads:[~2015-06-29 12:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-28 12:47 Examining the output of a shell command? Raffaele Ricciardi
2015-06-28 13:57 ` Pascal J. Bourguignon
     [not found] ` <mailman.5831.1435499861.904.help-gnu-emacs@gnu.org>
2015-06-28 14:03   ` Dan Espen
2015-06-28 14:20     ` Michael Heerdegen
     [not found]     ` <mailman.5833.1435501234.904.help-gnu-emacs@gnu.org>
2015-06-28 17:17       ` Dan Espen
2015-06-28 18:28         ` Michael Heerdegen
2015-06-29  1:39         ` Barry Margolin
2015-06-28 14:31   ` Raffaele Ricciardi
2015-06-28 14:55     ` Eli Zaretskii
     [not found]     ` <mailman.5839.1435503359.904.help-gnu-emacs@gnu.org>
2015-06-28 15:03       ` Raffaele Ricciardi
2015-06-28 15:43         ` Eli Zaretskii
     [not found]         ` <mailman.5843.1435506194.904.help-gnu-emacs@gnu.org>
2015-06-28 15:51           ` Raffaele Ricciardi
2015-06-28 15:52     ` Pascal J. Bourguignon
2015-06-29  1:53       ` Emanuel Berg
     [not found]       ` <mailman.5887.1435542902.904.help-gnu-emacs@gnu.org>
2015-06-29  8:13         ` Pascal J. Bourguignon
2015-06-29 11:26   ` Raffaele Ricciardi
2015-06-29 12:08     ` Pascal J. Bourguignon [this message]
2015-06-29 14:51     ` Eli Zaretskii
     [not found]     ` <mailman.5928.1435589507.904.help-gnu-emacs@gnu.org>
2015-06-29 15:56       ` Raffaele Ricciardi

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://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87mvziogyl.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@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.
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).