1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# iced_custom_highlighter
[](https://builds.sr.ht/~pml68/iced_custom_highlighter)
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`](https://github.com/CosmicHorrorDev/two-face) is used for providing extra syntaxes. [More info](https://github.com/CosmicHorrorDev/two-face?tab=readme-ov-file#syntaxes)
# Example
```rust
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;
}
}
}
```
|