poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-Escape sequences in print command


From: Henner Zeller
Subject: Re: C-Escape sequences in print command
Date: Sun, 29 Sep 2019 07:24:17 -0700

On Sun, 29 Sep 2019 at 03:46, Henner Zeller <address@hidden> wrote:
>
> Hi,
> (thanks for poke and the OrConf talk, just poking around :) ).
>
> 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);
     }

>
> Yet, pickle complains that "error: invalid \0 sequence in string". Is
> it considered to allow more c-escape idioms in strings ?
>
> Thanks,
>   Henner.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]