Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 504138 - sys-apps/gentoo-functions: escape sequences for colors won't work
Summary: sys-apps/gentoo-functions: escape sequences for colors won't work
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: William Hubbs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-10 20:53 UTC by Kirill Elagin
Modified: 2014-03-11 22:03 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Proper colors (functions.patch,836 bytes, patch)
2014-03-10 20:53 UTC, Kirill Elagin
Details | Diff
gentoo-functions.patch (gentoo-functions.patch,677 bytes, patch)
2014-03-11 15:05 UTC, William Hubbs
Details | Diff
Fallback to printf (functions.patch,932 bytes, patch)
2014-03-11 17:08 UTC, Kirill Elagin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kirill Elagin 2014-03-10 20:53:13 UTC
Created attachment 372324 [details, diff]
Proper colors

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

kirrun@kirNote ~ [1101]% gcc-config -l
 [1] x86_64-pc-linux-gnu-4.7.3 \033[32;01m*\033[0m

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some tools (e.g. `gcc-config`) source functions.sh and then use variables defined there with `echo`. This doesn't work now, because they call echo without `-e`, so escape sequences are not interpreted.

In the example above the offending lines are:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<...>
x="${x} ${GOOD}*${NORMAL}"
<...>
echo " [${i}] ${x}"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I suggest using termcap for this, falling back to hardcoded escape sequences. That's what OpenRC does, as far as I can tell.
Comment 1 Alex Xu (Hello71) 2014-03-10 20:59:42 UTC
Perhaps we can fix the consumers to avoid adding deps.
Comment 2 Alex Xu (Hello71) 2014-03-10 21:07:48 UTC
This is, strictly speaking, bash's fault for not being POSIX-compliant.

Solutions:

- Fix the consumers to use echo -e or /bin/echo
- Use the bashism $''
- Use tput

Possibly more, but I think that's it.
Comment 3 Kirill Elagin 2014-03-10 21:12:46 UTC
(In reply to Alex Xu (Hello71) from comment #2)
> This is, strictly speaking, bash's fault for not being POSIX-compliant.

How is this related to POSIX compilance?

POSIX:
> If the first operand is -n, or if any of the operands contain a backslash ( '\' ) character, the results are implementation-defined.

In my patch `tput` is not a strict dependency. But, well, you are right, _both_ using `tput` and fixing consumers might be a good idea.
Comment 4 Alex Xu (Hello71) 2014-03-10 21:16:39 UTC
(In reply to Kirill Elagin from comment #3)
> (In reply to Alex Xu (Hello71) from comment #2)
> > This is, strictly speaking, bash's fault for not being POSIX-compliant.
> 
> How is this related to POSIX compilance?
> 
> POSIX:
> > If the first operand is -n, or if any of the operands contain a backslash ( '\' ) character, the results are implementation-defined.
> 

I think this section has been amended.

Another solution: use printf.
Comment 5 William Hubbs gentoo-dev 2014-03-11 15:05:31 UTC
Created attachment 372384 [details, diff]
gentoo-functions.patch

Can you check this variation of the patch?
I think we can do it this way and avoid a level of nesting.

Thanks,

William
Comment 6 Alex Xu (Hello71) 2014-03-11 15:10:47 UTC
(In reply to William Hubbs from comment #5)
> Created attachment 372384 [details, diff] [details, diff]
> gentoo-functions.patch
> 
> Can you check this variation of the patch?
> I think we can do it this way and avoid a level of nesting.
> 
> Thanks,
> 
> William

Perhaps in the else use $(printf ...) to ensure that colors work on ANSI-compatible terminals.

(although I'm not sure why you would really want colors if you're using dash and don't have ncurses)
Comment 7 Kirill Elagin 2014-03-11 16:08:29 UTC
(In reply to William Hubbs from comment #5)
> Can you check this variation of the patch?

Looks $GOOD ;).
Comment 8 Kirill Elagin 2014-03-11 17:08:25 UTC
Created attachment 372398 [details, diff]
Fallback to printf

As Alex suggested, falling back to `printf`.
Comment 9 Kirill Elagin 2014-03-11 17:12:26 UTC
FYI: this does work in dash.
Comment 10 William Hubbs gentoo-dev 2014-03-11 22:03:43 UTC
This is fixed in 0.1. Thanks much to everyone involved.