[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C-Escape sequences in print command
From: |
Jose E. Marchesi |
Subject: |
Re: C-Escape sequences in print command |
Date: |
Mon, 30 Sep 2019 11:34:39 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
> I am trying to use escape sequences in print commands. In my case, I
> want to wrap the header of the 'dump' output in "\033[4m" ...
> "\033[0m" so that it visually indicates that this is the header (in
> pk-dump.pk).
With the %c patch (see my other mail), here is a crude way to do it
(but I still might implement \0** and \x** c-escapes in strings)
This underlines the header -- (by hardcode assuming that the terminal
understands them, so this probably needs to be done more
cleanly depending on isatty(STDOUT_FILENO) or something. But it lives
happily in my local copy :)
--- a/src/pk-dump.pk
+++ b/src/pk-dump.pk
@@ -47,7 +47,7 @@ defun dump = (off64 from = pk_dump_offset,
{
defvar o = 0#B;
- print "76543210 ";
+ printf("%c[4m76543210 ", 0x1b);
for (s in ["00", "11", "22", "33", "44", "55", "66",
"77", "88", "99", "aa", "bb", "cc", "dd",
"ee", "ff"])
@@ -59,7 +59,7 @@ defun dump = (off64 from = pk_dump_offset,
}
if (ascii)
print " 0123456789ABCDEF";
- print "\n";
+ printf ("%c[0m\n", 0x1b);
}
Nice hack :D
My intention is to use Bruno Haible's new libtextstyle library for
supporting colorizing terminal output, and also other goodies like
terminal hyperlinks (!). At the moment, the library lives in the
gettext's git repo, but he will soon package it separately.
Now, at the Poke level... I feel like it would be better to somehow
abstract the complex world of terminals to Poke programmers. What about
adding convenient escapes to change attributes? Like introducing a
background color, or similar. Like:
print "\#color(green)This is green\#reset(color) This is not green"
(Yeah the syntax sucks, suggestions are welcome :P)
How is that handled by other high-level programming languages? Elisp
uses text properties, but I don't think we should go that far :D