jam1garner / owo-colors

A zero-allocation no_std-compatible zero-cost way to add color to your Rust terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support thread-local/scoped color overrides

jam1garner opened this issue · comments

Moving this from #33 to its own issue.

One considered API design:

// color=always
scoped_override(true, || {
    // do stuff here?
});

// color=never
scoped_override(false, || {
    // do stuff here?
});

This would need to be behind a feature flag as it requires std for thread-local variables, but outside of that this isn't too bad. For the most part it should be able to reuse a lot of the code from #34, but replace the static with a thread local.

Outstanding Design Questions

  • Should scoped overrides or global overrides take precedence?
commented

Should scoped overrides or global overrides take precedence?

I would personally expect that thread-local overrides, being more local than process-wide overrides, take precedence. (Similarly, task-local overrides should take precedence over thread-local ones I think)