diff options
Diffstat (limited to 'highlighter')
| -rw-r--r-- | highlighter/Cargo.toml | 3 | ||||
| -rw-r--r-- | highlighter/src/lib.rs | 31 | 
2 files changed, 33 insertions, 1 deletions
| diff --git a/highlighter/Cargo.toml b/highlighter/Cargo.toml index 2d108d6f..7962b89d 100644 --- a/highlighter/Cargo.toml +++ b/highlighter/Cargo.toml @@ -10,6 +10,9 @@ homepage.workspace = true  categories.workspace = true  keywords.workspace = true +[lints] +workspace = true +  [dependencies]  iced_core.workspace = true diff --git a/highlighter/src/lib.rs b/highlighter/src/lib.rs index 63f21fc0..7636a712 100644 --- a/highlighter/src/lib.rs +++ b/highlighter/src/lib.rs @@ -1,3 +1,4 @@ +//! A syntax highlighter for iced.  use iced_core as core;  use crate::core::text::highlighter::{self, Format}; @@ -16,6 +17,8 @@ static THEMES: Lazy<highlighting::ThemeSet> =  const LINES_PER_SNAPSHOT: usize = 50; +/// A syntax highlighter. +#[derive(Debug)]  pub struct Highlighter {      syntax: &'static parsing::SyntaxReference,      highlighter: highlighting::Highlighter<'static>, @@ -131,25 +134,47 @@ impl highlighter::Highlighter for Highlighter {      }  } +/// The settings of a [`Highlighter`].  #[derive(Debug, Clone, PartialEq)]  pub struct Settings { +    /// The [`Theme`] of the [`Highlighter`]. +    /// +    /// It dictates the color scheme that will be used for highlighting.      pub theme: Theme, +    /// The extension of the file to highlight. +    /// +    /// The [`Highlighter`] will use the extension to automatically determine +    /// the grammar to use for highlighting.      pub extension: String,  } +/// A highlight produced by a [`Highlighter`]. +#[derive(Debug)]  pub struct Highlight(highlighting::StyleModifier);  impl Highlight { +    /// Returns the color of this [`Highlight`]. +    /// +    /// If `None`, the original text color should be unchanged.      pub fn color(&self) -> Option<Color> {          self.0.foreground.map(|color| {              Color::from_rgba8(color.r, color.g, color.b, color.a as f32 / 255.0)          })      } +    /// Returns the font of this [`Highlight`]. +    /// +    /// If `None`, the original font should be unchanged.      pub fn font(&self) -> Option<Font> {          None      } +    /// Returns the [`Format`] of the [`Highlight`]. +    /// +    /// It contains both the [`color`] and the [`font`]. +    /// +    /// [`color`]: Self::color +    /// [`font`]: Self::font      pub fn to_format(&self) -> Format<Font> {          Format {              color: self.color(), @@ -158,6 +183,8 @@ impl Highlight {      }  } +/// A highlighting theme. +#[allow(missing_docs)]  #[derive(Debug, Clone, Copy, PartialEq, Eq)]  pub enum Theme {      SolarizedDark, @@ -168,6 +195,7 @@ pub enum Theme {  }  impl Theme { +    /// A static slice containing all the available themes.      pub const ALL: &'static [Self] = &[          Self::SolarizedDark,          Self::Base16Mocha, @@ -176,6 +204,7 @@ impl Theme {          Self::InspiredGitHub,      ]; +    /// Returns `true` if the [`Theme`] is dark, and false otherwise.      pub fn is_dark(self) -> bool {          match self {              Self::SolarizedDark @@ -209,7 +238,7 @@ impl std::fmt::Display for Theme {      }  } -pub struct ScopeRangeIterator { +struct ScopeRangeIterator {      ops: Vec<(usize, parsing::ScopeStackOp)>,      line_length: usize,      index: usize, | 
