Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add color role #26

Closed
philshafer opened this issue Feb 27, 2015 · 8 comments
Closed

add color role #26

philshafer opened this issue Feb 27, 2015 · 8 comments
Assignees

Comments

@philshafer
Copy link
Contributor

Oleg Ginzburg writes:

I wanted to ask - is there some method to be used in the output xo ANSII
codes? For normal human text sometimes you want to draw a conclusion in color
to make it more human output ;)

Color would be a useful enhancement, but it can't be done by intermixing
escape sequnces with data. It would need to be something more explicit
and meaningful, something like:

xo_emit("The {k:name} {C:green}weighs{C:} {:weight/%d} pounds\n", name, weight);

The new "C" role would accept a name that would appear as escape
sequences for text and "style" attributes for HTML. The list of
color names should be freakishly small, to keep it portable, and
unknown colors would be ignored (with a warning).

Hmm... instead of directly making a color style attribute, I'd probably
opt for a color class, allowing CSS files to adjust it when/if needed.

And no, it won't support blinking ;^)

Thanks,
Phil

@philshafer philshafer self-assigned this Feb 27, 2015
@philshafer
Copy link
Contributor Author

Turns out, the list is not longer the ancient 16 from DOS circa
1982. According to http://en.wikipedia.org/wiki/ANSI_escape_code:

Xterm[14] and recent-enough versions of KDE's Konsole program support ISO-8613-3 24-bit fo
reground and background color setting[15][better source needed] Quoting one of the text-fi
les in its source-tree:[16][better source needed]

ESC[38;2;;;m Select RGB foreground color
ESC[48;2;;;m Select RGB background color

If these are widely supported, the list of colors could be expanded.

On the other hand, 16 colors has been good enough for thirty years....

Thanks,
Phil

@philshafer
Copy link
Contributor Author

I'm thinking this would be a comma-separated list:

"{C:bold,green,bg-red,italics}"

Would be nice to support "/%s" as well, like:

xo_emit("{C:/bold,%s,bg-%s}", fg, bg);

@philshafer
Copy link
Contributor Author

Debugging note (to self):

printf '\033[7m\033[33mtest\033[27m\n'
printf '\033[7m\033[33mtest\033[39m\n'
printf '\033[7m\033[33mtest\033[39m\03327m\n'
printf '\033[7m\033[33mtest\033[39m\033[27m\n'
printf '\033[7m\033[33mtest\033[39m\033[27m\n'
printf '\033[7;1m\033[33mtest\033[39m\033[27m\n'
printf '\033[7m\033[33mtest\033[39m\033[27m\n'
printf '\033[7m\033[33mtest\033[39m\033[0m\n'
printf '\033[7m\033[33mtest\033[39mdone\033[0m\n'
printf '\033[7m\033[33mtest\033[39m\033[27mdone\033[0m\n'
printf '\033[7;33mtest\033[39m\033[27mdone\033[0m\n'
printf '\033[7;33mtest\033[39;27mdone\033[0m\n'
printf '\033[7;33;1mtest\033[39;27mdone\033[0m\n'
printf '\033[7;33mtest\033[39;27mdone\033[0m\n'
printf '\033[7;33;43mtest\033[39;27mdone\033[0m\n'
printf '\033[7;33;45mtest\033[39;27mdone\033[0m\n'
printf '\033[7;33;45mtest\033[39;49;27mdone\033[0m\n'
printf '\033[33;45mtest\033[39;49;27mdone\033[0m\n'
printf '\033[1;33;45mtest\033[39;49;27mdone\033[0m\n'
printf '\033[33;45;1mtest\033[39;49;27mdone\033[0m\n'
printf '\033[33;45;1mtest\033[39;49;27;2mdone\033[0m\n'
printf '\033[33;45;1mtest\033[39;49;27;21mdone\033[0m\n'
printf '\033[33;45;1mtest\033[39;49;27;22mdone\033[0m\n'

@philshafer
Copy link
Contributor Author

(note from Olevole)

On Friday 27 February 2015 19:20:52 you wrote:

On the other hand, 16 colors has been good enough for thirty years....

I totally agree with you - for console output is more than enough. I'm a few
years applies only this set to text shell output in the Linux / BSD:

http://pastebin.com/Qntu4P5q

WBR,

TOX ID: olevole@toxme.se
(B4A584A75560D5A93DBF387FAAC56669DA18797078A46B9A9818726BEE643E52A43A6A2E3DA0)
E-mail: olevole at olevole.ru

@philshafer
Copy link
Contributor Author

Got time to work on this tonight:

    static const char *colors[] =
    { "blue", "green", "red", "yellow", "default", NULL };

    int i;
    for (i = 0; colors[i]; i++) {
        if (i > 0)
            xo_emit("{C:/bg-%s}", colors[i-1]);
        xo_emit("{C:/fg-%s}{T:/%s}", colors[i], colors[i]);
    }
    xo_emit("{C:reset}\n");

    xo_emit("{T:Item/%-10s}{C:bold,underline}{T:Total Sold/%12s}{C:no-bold}"
            "{T:In Stock/%12s}{C:/%s}"  
            "{T:On Order/%12s}{C:normal}{T:SKU/%5s}\n", "inverse");

libxo-demo

Need to document it and add html support, but the plumbing's all there.

@philshafer
Copy link
Contributor Author

Done. Will be in next release.

@olevole
Copy link
Contributor

olevole commented Apr 25, 2015

It's amazing, thank You!

@philshafer
Copy link
Contributor Author

You’re very welcome. Check out “xohtml” to see your content in colorized html also.

Thanks,
Phil

On Apr 25, 2015, at 7:10 PM, Oleg Ginzburg notifications@github.com wrote:

It's amazing, thank You!


Reply to this email directly or view it on GitHub #26 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants