Re: [Possible bug?] column command not ignoring escape sequences.

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

 



On 25 November 2015 at 22:11, Michael Heyns <mike.bean.heyns@xxxxxxxxx> wrote:
> Greetings,
>
> I have a working script checking mimetypes i.e. `text/x-diff`;
> `image/svg+xml` etc.
>
> =================================
>   1   #!/bin/bash
>   2
>   3   _Bold="\e[1m"
>   4   _unBold="\e[22m"
>   5   _Blue="\e[34m"
>   6   _uC="\e[39m"
>   7
>   8   mimetype="$1"
>   9   output="${_Bold}Testing MimeType${_unBold}:\t${mimetype}\n\t-------------"
>  10
>  11   get_default()
>  12   {
>  13       xdg-mime query default "$1"
>  14   }
>  15
>  16   alias_of=`grep "^$mimetype " /usr/share/mime/aliases | cut -d' ' -f2`
>  17   if [ -n "$alias_of" ]; then
>  18       default=`get_default $alias_of`
>  19       output="$output\nWhich is an alias of:\t$alias_of\t->
> ${default:-"none"}"
>  20   else
>  21       output="$output\nWhich is not an alias."
>  22       alias_of=$mimetype
>  23   fi
>  24
>  25   while : ; do
>  26       subclass_of=`grep "^$alias_of " /usr/share/mime/subclasses |
> cut -d' ' -f2`
>  27       if [ -n "$subclass_of" ]; then
>  28         default=`get_default $subclass_of`
>  29         output="$output\nWhich is a subclass of:\t$subclass_of\t->
> ${default:-"none"}"
>  30
>  31         alias_of=$subclass_of
>  32       else
>  33         output="$output\nWhich is not a subclass"
>  34         break
>  35       fi
>  36   done
>  37
>  38   echo -e $output | column -t -s $'\t'
> =================================
>
> Output without bold (line 8) is as expected but with bold, the column
> is widened/broken.
>
> I have removed the rest of the formatting in my example, but with
> colors added it gets much worse.
>
> I think I have narrowed it down to the `column` somehow including the
> escape sequences in its spacing calculation? The same thing happens in
> xterm, gnome-terminal and urxvt.
>
> Is this expected behaviour? I'm learning a lot but sometimes I get a
> headscratcher like this one.

Hi Michael,

I think you are onto something. The issue feels like the same what is
skewing more output, and that I fixed in my upcoming pull request.

https://github.com/kerolasa/lelux-utiliteetit/commit/eeaa3eede07830c80540ab3b4e31ff348bbc1c65

But since the issue is with two utilities the fix really should be
wrote once. Trouble is that what I did with more is no where near
being an universal stream filter that is clearly needed.

-- 
Sami Kerola
http://www.iki.fi/kerolasa/
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux