From 1889f2fddddcce21790828c46a396e12c416919a Mon Sep 17 00:00:00 2001 From: pml68 Date: Thu, 27 Feb 2025 00:01:38 +0100 Subject: docs: add README --- src/lib.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') 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::( +//! 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 = const LINES_PER_SNAPSHOT: usize = 50; -type ScopeSelectorsResult = core::result::Result< - highlighting::ScopeSelectors, - parsing::ParseScopeError, ->; +type ScopeSelectorsResult = + std::result::Result; /// A syntax highlighter. #[derive(Debug)] -- cgit v1.2.3