johnnovak / illwill

A curses inspired simple cross-platform console library for Nim
Do What The F*ck You Want To Public License
398 stars 27 forks source link

Support wide characters and true color #16

Closed iffy closed 2 years ago

iffy commented 3 years ago
  1. I'm happy to divide this into two issues (one for wide chars, one for true color) if that's preferable.
  2. I'm offering to submit PRs, but want to know if you'd rather depend on the library I've made for these features, or fold them into illwill itself.

Wide Characters

On macOS Terminal (and I assume other terminals), the current version of illwill assumes that all characters occupy one space. Emoji and some other characters actually occupy 2 spaces. For aligning tables and boxes, it's important to know how wide strings are. For example, see that the smiley below covers 23 and the last two characters each cover 2 spaces:

Screen Shot 2020-10-27 at 4 07 12 PM

True Colors

Some terminals support 16 colors, some 256 and some 24-bit "true color." It would be nice if illwill did, too. Then you can do things like this:

Windows CMD prompt:

Screen Shot 2020-10-27 at 4 02 56 PM

Windows Terminus (lacks 256 color support):

Screen Shot 2020-10-27 at 4 03 16 PM

macOS Terminal:

Screen Shot 2020-10-27 at 4 03 42 PM

I've looked at how other libraries work around this and have come up with: https://github.com/iffy/termtools It contains methods for detecting wide char string lengths and color escape sequence generation.

I think my preference is to depend on this new library as others might want the widechar and color support it provides without making a curses-like UI that illwill provides. But I'm interested in your thoughts before I proceed.

jeangit commented 3 years ago

Yes, true color support would be fabulous.

It is supported in terminal.vim , which is used by illwill.

Is there a reason for not using true colors in illwill ?

johnnovak commented 3 years ago

@iffy

I think the length detection can be useful sometimes, but in actual reality you almost always know when you are going to output a double-width char, so you just follow it with a space then. This should exist in another library, I don't want to merge this code into illwill.

About true-colour support, that can be handy and it would be cool to extend illwill with support for it, I agree. I'd just add the bare minimum for it in illwill, though, and ditch all the various other helper methods you have. I'd like to keep illwill dependency free.

Just a tip for your width-detection routine: you might want to make sure that it works correctly with NerdFonts. See this issue for further details. You might also want to check out the mintty sources for identifying the "wide" codepoint ranges.

@jeangit

Is there a reason for not using true colors in illwill ?

When I started illwill, terminal.nim didn't support it and I don't really have a need for it. But as I said above, it would be cool to add support. Are you up for creating a PR? 😄

iffy commented 3 years ago

@johnnovak, That sounds reasonable to me. Feel free to leave this issue open when it supports true colors or close it for another one if you'd like. I won't have time soon to submit a PR, but in the future when I get back to my TUI I will.

johnnovak commented 2 years ago

Closing due to inactivity/lack of interest.