gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.26k stars 243 forks source link

[FEATURE] Use default system color theme (or themeless widgets) #706

Closed eminfedar closed 1 year ago

eminfedar commented 1 year ago

Is your feature request related to a problem? Please describe. If I use native ncurses or tui-rs, it is themeless by default, which means whatever my default terminal color is, I see it.

If I use light colors on my terminal, I see light colors. If I see dark green theme on my terminal, I see dark green theme. I couldn't find a Palette or Theme default methods or traits for this.

Describe the solution you'd like I need something like theme::no_theme() or theme::system_defaults(). I don't want to define custom permanent colors. I want my tui program is obeying the terminal colors of the user. Like htop for example. Additionally has custom colors but they are above the system colors.

Additional context htop screenshot examples which respects to system default theme Screenshot from 2023-01-05 14-06-47

Screenshot from 2023-01-05 14-07-05

gyscos commented 1 year ago

Hi, and thanks for the report!

The terminal "theme" defines a couple of colors that can be used by applications:

So if you only want to use the text and background colors, you can use a theme where every color of the palette is set to TerminalDefault.

gyscos commented 1 year ago

Note that using TerminalDefault for everything currently had one major drawback: it was messing up text highlighting.

Should be fixed with the latest commit. It also adds Theme::terminal_default() as a convenience method to return a theme that only uses this color.

(Technical details: The reason is that highlighting so far was done by directly specifying the fore and back colors, but if we specify Terminal Default, it will actually look indistinguishable from regular text. The fix was to swap the colors for the highlight style, and rely on the "reverse" effect instead.)