From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: What happens with text properties in batch mode? Date: Sat, 08 Dec 2018 21:08:53 +0100 Message-ID: <87h8fnrdbe.fsf@mbork.pl> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1544299764 9085 195.159.176.226 (8 Dec 2018 20:09:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 8 Dec 2018 20:09:24 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 27.0.50 Cc: help-gnu-emacs@gnu.org To: "andlind\@gmail.com" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 08 21:09:20 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gViud-0002G3-MA for geh-help-gnu-emacs@m.gmane.org; Sat, 08 Dec 2018 21:09:19 +0100 Original-Received: from localhost ([::1]:51963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gViwk-0001Jm-1V for geh-help-gnu-emacs@m.gmane.org; Sat, 08 Dec 2018 15:11:30 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gViwB-0001Je-2y for help-gnu-emacs@gnu.org; Sat, 08 Dec 2018 15:10:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gViw7-0008GV-UI for help-gnu-emacs@gnu.org; Sat, 08 Dec 2018 15:10:55 -0500 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:48730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gViw7-0008F1-MK for help-gnu-emacs@gnu.org; Sat, 08 Dec 2018 15:10:51 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 348DEE651C; Sat, 8 Dec 2018 21:10:50 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SsJNpsfpHUQo; Sat, 8 Dec 2018 21:10:45 +0100 (CET) Original-Received: from localhost (static-dwadziewiec-jedenpiec7.echostar.pl [109.232.29.157]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 577A7E6448; Sat, 8 Dec 2018 21:10:45 +0100 (CET) In-reply-to: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.110.48.8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118923 Archived-At: On 2018-12-08, at 19:31, andlind@gmail.com wrote: > On Friday, 7 December 2018 08:58:38 UTC+1, Marcin Borkowski wrote: > >> it seems that when I `princ' something with text properties (e.g., >> colored faces) in batch mode, the colors disappear. Is it documented >> anywhere? Can I disable this behavior? > > Can you tell me what you are trying to accomplish? Simply printing a highlighted text stdout and expecting it to be shown with colors doesn't work. I was just curious what happens to the properties after princ. >> I found this: https://github.com/Lindydancer/e2ansi, and its existence >> suggests that outputting colored stuff (using ANSI codes) is >> non-trivial. Am I right? > > It is non-trivial, I can assure you, I spent many months writing it. > > One problem is that even though strings have face properties in batch mode, the faces themselves often fail to specify anything useful in batch mode. e2ansi contains a system for playing the "what if" game by allowing you to query things like "what would face X look like when in a gui with 16 millions colors, or in a black-and-white tty". (This part is placed in a stand alone library "face-explorer", along with tons of useful tools.) > > The second problem is to translate the face information to ANSI. Note that Emacs internal system for rendering things in terminal mode is not available to elisp, so I had to implement everything from scratch. > > Fortunately, you can use e2ansi as a library in your own packages. For example `e2ansi-string-to-ansi' converts a string with face information to ANSI. See `face-explorer-number-of-colors' and friends to control which features of ANSI will be used. (They have sane defaults, though.) Thanks a lot for the details (and for e2ansi)! I'll try to look into it some day. Best, -- Marcin Borkowski http://mbork.pl