Skip to content

feat: Color themes#136

Merged
orhun merged 10 commits intoratatui:mainfrom
bladecoder:color-themes
Jan 28, 2026
Merged

feat: Color themes#136
orhun merged 10 commits intoratatui:mainfrom
bladecoder:color-themes

Conversation

@bladecoder
Copy link
Copy Markdown
Contributor

@bladecoder bladecoder commented Dec 1, 2025

Hello!

This pull request introduces a new color theme system to the Mousefood embedded terminal library, allowing users to customize how Ratatui colors are mapped to display pixels. The changes include a new ColorTheme struct with built-in themes, updates to the backend to support color themes, and refactoring of color conversion logic.

Colors can be remapped using color_theme on EmbeddedBackendConfig.
By default the ANSI palette is used.

use mousefood::{ColorTheme, EmbeddedBackend, EmbeddedBackendConfig};
use mousefood::embedded_graphics::pixelcolor::Rgb888;

let theme = ColorTheme {
    background: Rgb888::new(5, 5, 5),
    foreground: Rgb888::new(240, 240, 240),
    yellow: Rgb888::new(255, 200, 0),
    ..ColorTheme::ansi()
};

let config = EmbeddedBackendConfig {
    color_theme: theme,
    ..Default::default()
};
let backend = EmbeddedBackend::new(&mut display, config);

Besides, the Tokio Night color theme has been included as a built-in theme.

use mousefood::{ColorTheme, EmbeddedBackendConfig};

let config = EmbeddedBackendConfig {
    color_theme: ColorTheme::tokionight(),
    ..Default::default()
};

Below an example of the ansi and Tokio Night themes working with the emulator example:

Captura desde 2025-12-01 23-35-54

@bladecoder bladecoder changed the title Color themes feature feat: Color themes Dec 2, 2025
Copy link
Copy Markdown
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good!

@bladecoder
Copy link
Copy Markdown
Contributor Author

Hey @orhun, thanks for the review! By the way, I loved your talk about embedded ratatouille at the Tokyo Rust meetup!

Copy link
Copy Markdown
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@orhun
Copy link
Copy Markdown
Member

orhun commented Jan 27, 2026

Oops, there seems to be some clippy issues, can you address them? (If not I can get to this soon)

error: this function has too many arguments (8/7)
   --> mousefood/src/backend.rs:126:5
    |
126 | /     fn init(
127 | |         display: &'display mut D,
128 | |         flush_callback: impl FnMut(&mut D) + 'static,
129 | |         font_regular: MonoFont<'static>,
...   |
134 | |         color_theme: ColorTheme,
135 | |     ) -> EmbeddedBackend<'display, D, C> {
    | |________________________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#too_many_arguments
    = note: `-D clippy::too-many-arguments` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]`

error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value
   --> mousefood/src/colors.rs:147:18
    |
147 |     fn to_rgb888(&self) -> Rgb888 {
    |                  ^^^^^
    |
    = help: consider choosing a less ambiguous name
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#wrong_self_convention
    = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]`

error: could not compile `mousefood` (lib) due to 2 previous errors

We could create a separate struct for mitigating too_many_arguments I believe.

@bladecoder
Copy link
Copy Markdown
Contributor Author

Fixed the clippy problems. Sorry for not checking before 😓

Copy link
Copy Markdown
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks again!

@orhun orhun merged commit 6cfce4a into ratatui:main Jan 28, 2026
42 of 52 checks passed
@github-actions github-actions bot mentioned this pull request Jan 25, 2026
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

Successfully merging this pull request may close these issues.

3 participants