aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-02-27 00:01:38 +0100
committerpml68 <contact@pml68.dev>2025-02-27 00:01:38 +0100
commit1889f2fddddcce21790828c46a396e12c416919a (patch)
tree9b1438127127a54896f9496fb4f2cd6f731507c3 /src/lib.rs
parentfeat: switch to personal `iced` fork (should be temporary) (diff)
downloadiced_custom_highlighter-1889f2fddddcce21790828c46a396e12c416919a.tar.gz
docs: add README
Diffstat (limited to '')
-rw-r--r--src/lib.rs62
1 files changed, 57 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index eb486e7..0753766 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,60 @@
//! A custom syntax highlighter for iced.
//!
-//! It uses the colors from your app's Theme, based on the current [`Scope`]
+//! It uses the colors from your app's Theme, based on a styling method (like [`default_style`])
+//!
+//! # Example
+//!
+//! ```no_run
+//! 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...")
+//! .rehighlight_on_redraw(true)
+//! .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;
+//! }
+//! }
+//! }
+//! ```
+//!
+//! [`default_style`]: crate::Highlight::default_style
use iced_core::font::Font;
use iced_core::text::highlighter::{self, Format};
use iced_core::Theme;
@@ -16,10 +70,8 @@ static SYNTAXES: LazyLock<parsing::SyntaxSet> =
const LINES_PER_SNAPSHOT: usize = 50;
-type ScopeSelectorsResult = core::result::Result<
- highlighting::ScopeSelectors,
- parsing::ParseScopeError,
->;
+type ScopeSelectorsResult =
+ std::result::Result<highlighting::ScopeSelectors, parsing::ParseScopeError>;
/// A syntax highlighter.
#[derive(Debug)]