iced_custom_highlighter

Crates.ioiced_custom_highlighter
lib.rsiced_custom_highlighter
version0.1.0
created_at2025-12-09 09:22:17.545937+00
updated_at2025-12-09 09:22:17.545937+00
descriptionA custom highlighter for `iced`'s TextEditor widget that uses your application Theme's colors
homepagehttps://sr.ht/~pml68/iced_custom_highlighter/
repositoryhttps://git.sr.ht/~pml68/iced_custom_highlighter
max_upload_size
id1975155
size51,016
Polesznyák Márk László (pml68)

documentation

README

iced_custom_highlighter

builds.sr.ht status

A custom syntax highlighter for iced.

It uses the colors from your app's Theme, based on a styling method (like default_style)

two-face is used for providing extra syntaxes. More info

Example

use iced::widget::{Column, pick_list, text_editor};
use iced::{Element, Theme};
use iced_custom_highlighter::{Highlight, Highlighter, Settings};

#[derive(Default)]
struct State {
    content: text_editor::Content,
    theme: Theme,
}

#[derive(Debug, Clone)]
enum Message {
    Edit(text_editor::Action),
    ChangeTheme(Theme),
}

fn view(state: &State) -> Element<'_, Message> {
Column::new()
    .push(
        text_editor(&state.content)
            .placeholder("Type something here...")
            .highlight_with::<Highlighter>(
                Settings::new(vec![], Highlight::default_style, "rs"),
                Highlight::to_format,
            )
            .on_action(Message::Edit),
    )
    .push(pick_list(
        Theme::ALL,
        Some(state.theme),
        Message::ChangeTheme,
    ))
    .into()
}

fn update(state: &mut State, message: Message) {
    match message {
        Message::Edit(action) => {
            state.content.perform(action);
        }

        Message::ChangeTheme(theme) => {
            state.theme = theme;
        }
    }
}
Commit count: 0

cargo fmt