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

How to set both background and color? #17

Open
jcubic opened this issue Jun 11, 2021 · 6 comments
Open

How to set both background and color? #17

jcubic opened this issue Jun 11, 2021 · 6 comments

Comments

@jcubic
Copy link
Contributor

jcubic commented Jun 11, 2021

I've noticed that the demo doesn't render properly when you select the text. The charts should be reversed.
To fix the issue the style should be both ervy.bg and ervy.fg. Is it possible to combine the styles?

@chunqiuyiyu
Copy link
Owner

Hi @jcubic, ANSI escape code support combine color and background, for example:

console.log('\x1b[36m\x1b[41mHello World\x1b[0m')

result:
image

I will add new mixin utils function to comine fg and bg styles if it is necessary.

@jcubic
Copy link
Contributor Author

jcubic commented Jun 14, 2021

I know how to do this in raw text using ANSI escapes, the problem is the ervy API. Can I write code that will make both color and background?

@chunqiuyiyu
Copy link
Owner

Of course.

@jcubic
Copy link
Contributor Author

jcubic commented Jun 14, 2021

So can I write it? Can you share the code on how to do this? I would update the demo, because it's looks weird when you select text.

@chunqiuyiyu
Copy link
Owner

You can use raw ANSI escapes to render ervy charts, for example:

const barData = [
    { key: 'A', value: 5, style: '\x1b[36m\x1b[41m#\x1b[0m' },
    { key: 'B', value: 3, style: '+' },
    { key: 'C', value: 11 },

]

console.log(ervy.bar(barData))

Output:
image

@jcubic
Copy link
Contributor Author

jcubic commented Jul 11, 2021

It seems that for ervy.bg in demo the fix would be something like this (using existing API):

function bg(style, size) {
    var fg = ervy.fg(style, '?').replace(/\?.*/, '');
    return fg + ervy.bg(style, size);
}

and it will fix selection in a terminal. If you want to can create a PR. You can see how this works in in demo:
https://codepen.io/jcubic/pen/gObPBdP?editors=1010

An alternative is to come up with a better API like ervy.color that will change both colors. And update documentation

Note that the error is not only in the web terminal the same happens in a real terminal emulator.
ervy

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

No branches or pull requests

2 participants