style.rs

  1use std::{
  2    hash::{Hash, Hasher},
  3    iter, mem,
  4    ops::Range,
  5};
  6
  7use crate::{
  8    black, phi, point, quad, rems, AbsoluteLength, Bounds, ContentMask, Corners, CornersRefinement,
  9    CursorStyle, DefiniteLength, Edges, EdgesRefinement, Font, FontFeatures, FontStyle, FontWeight,
 10    Hsla, Length, Pixels, Point, PointRefinement, Rgba, SharedString, Size, SizeRefinement, Styled,
 11    TextRun, WindowContext,
 12};
 13use collections::HashSet;
 14use refineable::Refineable;
 15use smallvec::SmallVec;
 16pub use taffy::style::{
 17    AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, JustifyContent,
 18    Overflow, Position,
 19};
 20
 21/// Use this struct for interfacing with the 'debug_below' styling from your own elements.
 22/// If a parent element has this style set on it, then this struct will be set as a global in
 23/// GPUI.
 24#[cfg(debug_assertions)]
 25pub struct DebugBelow;
 26
 27#[cfg(debug_assertions)]
 28impl crate::Global for DebugBelow {}
 29
 30/// The CSS styling that can be applied to an element via the `Styled` trait
 31#[derive(Clone, Refineable, Debug)]
 32#[refineable(Debug)]
 33pub struct Style {
 34    /// What layout strategy should be used?
 35    pub display: Display,
 36
 37    /// Should the element be painted on screen?
 38    pub visibility: Visibility,
 39
 40    // Overflow properties
 41    /// How children overflowing their container should affect layout
 42    #[refineable]
 43    pub overflow: Point<Overflow>,
 44    /// How much space (in points) should be reserved for the scrollbars of `Overflow::Scroll` and `Overflow::Auto` nodes.
 45    pub scrollbar_width: f32,
 46
 47    // Position properties
 48    /// What should the `position` value of this struct use as a base offset?
 49    pub position: Position,
 50    /// How should the position of this element be tweaked relative to the layout defined?
 51    #[refineable]
 52    pub inset: Edges<Length>,
 53
 54    // Size properties
 55    /// Sets the initial size of the item
 56    #[refineable]
 57    pub size: Size<Length>,
 58    /// Controls the minimum size of the item
 59    #[refineable]
 60    pub min_size: Size<Length>,
 61    /// Controls the maximum size of the item
 62    #[refineable]
 63    pub max_size: Size<Length>,
 64    /// Sets the preferred aspect ratio for the item. The ratio is calculated as width divided by height.
 65    pub aspect_ratio: Option<f32>,
 66
 67    // Spacing Properties
 68    /// How large should the margin be on each side?
 69    #[refineable]
 70    pub margin: Edges<Length>,
 71    /// How large should the padding be on each side?
 72    #[refineable]
 73    pub padding: Edges<DefiniteLength>,
 74    /// How large should the border be on each side?
 75    #[refineable]
 76    pub border_widths: Edges<AbsoluteLength>,
 77
 78    // Alignment properties
 79    /// How this node's children aligned in the cross/block axis?
 80    pub align_items: Option<AlignItems>,
 81    /// How this node should be aligned in the cross/block axis. Falls back to the parents [`AlignItems`] if not set
 82    pub align_self: Option<AlignSelf>,
 83    /// How should content contained within this item be aligned in the cross/block axis
 84    pub align_content: Option<AlignContent>,
 85    /// How should contained within this item be aligned in the main/inline axis
 86    pub justify_content: Option<JustifyContent>,
 87    /// How large should the gaps between items in a flex container be?
 88    #[refineable]
 89    pub gap: Size<DefiniteLength>,
 90
 91    // Flexbox properties
 92    /// Which direction does the main axis flow in?
 93    pub flex_direction: FlexDirection,
 94    /// Should elements wrap, or stay in a single line?
 95    pub flex_wrap: FlexWrap,
 96    /// Sets the initial main axis size of the item
 97    pub flex_basis: Length,
 98    /// The relative rate at which this item grows when it is expanding to fill space, 0.0 is the default value, and this value must be positive.
 99    pub flex_grow: f32,
100    /// The relative rate at which this item shrinks when it is contracting to fit into space, 1.0 is the default value, and this value must be positive.
101    pub flex_shrink: f32,
102
103    /// The fill color of this element
104    pub background: Option<Fill>,
105
106    /// The border color of this element
107    pub border_color: Option<Hsla>,
108
109    /// The radius of the corners of this element
110    #[refineable]
111    pub corner_radii: Corners<AbsoluteLength>,
112
113    /// Box Shadow of the element
114    pub box_shadow: SmallVec<[BoxShadow; 2]>,
115
116    /// The text style of this element
117    pub text: TextStyleRefinement,
118
119    /// The mouse cursor style shown when the mouse pointer is over an element.
120    pub mouse_cursor: Option<CursorStyle>,
121
122    /// Whether to draw a red debugging outline around this element
123    #[cfg(debug_assertions)]
124    pub debug: bool,
125
126    /// Whether to draw a red debugging outline around this element and all of its conforming children
127    #[cfg(debug_assertions)]
128    pub debug_below: bool,
129}
130
131impl Styled for StyleRefinement {
132    fn style(&mut self) -> &mut StyleRefinement {
133        self
134    }
135}
136
137/// The value of the visibility property, similar to the CSS property `visibility`
138#[derive(Default, Clone, Copy, Debug, Eq, PartialEq)]
139pub enum Visibility {
140    /// The element should be drawn as normal.
141    #[default]
142    Visible,
143    /// The element should not be drawn, but should still take up space in the layout.
144    Hidden,
145}
146
147/// The possible values of the box-shadow property
148#[derive(Clone, Debug)]
149pub struct BoxShadow {
150    /// What color should the shadow have?
151    pub color: Hsla,
152    /// How should it be offset from its element?
153    pub offset: Point<Pixels>,
154    /// How much should the shadow be blurred?
155    pub blur_radius: Pixels,
156    /// How much should the shadow spread?
157    pub spread_radius: Pixels,
158}
159
160/// How to handle whitespace in text
161#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
162pub enum WhiteSpace {
163    /// Normal line wrapping when text overflows the width of the element
164    #[default]
165    Normal,
166    /// No line wrapping, text will overflow the width of the element
167    Nowrap,
168}
169
170/// The properties that can be used to style text in GPUI
171#[derive(Refineable, Clone, Debug, PartialEq)]
172#[refineable(Debug)]
173pub struct TextStyle {
174    /// The color of the text
175    pub color: Hsla,
176
177    /// The font family to use
178    pub font_family: SharedString,
179
180    /// The font features to use
181    pub font_features: FontFeatures,
182
183    /// The font size to use, in pixels or rems.
184    pub font_size: AbsoluteLength,
185
186    /// The line height to use, in pixels or fractions
187    pub line_height: DefiniteLength,
188
189    /// The font weight, e.g. bold
190    pub font_weight: FontWeight,
191
192    /// The font style, e.g. italic
193    pub font_style: FontStyle,
194
195    /// The background color of the text
196    pub background_color: Option<Hsla>,
197
198    /// The underline style of the text
199    pub underline: Option<UnderlineStyle>,
200
201    /// The strikethrough style of the text
202    pub strikethrough: Option<StrikethroughStyle>,
203
204    /// How to handle whitespace in the text
205    pub white_space: WhiteSpace,
206}
207
208impl Default for TextStyle {
209    fn default() -> Self {
210        TextStyle {
211            color: black(),
212            // todo(linux) make this configurable or choose better default
213            font_family: if cfg!(target_os = "linux") {
214                "FreeMono".into()
215            } else if cfg!(target_os = "windows") {
216                "Segoe UI".into()
217            } else {
218                "Helvetica".into()
219            },
220            font_features: FontFeatures::default(),
221            font_size: rems(1.).into(),
222            line_height: phi(),
223            font_weight: FontWeight::default(),
224            font_style: FontStyle::default(),
225            background_color: None,
226            underline: None,
227            strikethrough: None,
228            white_space: WhiteSpace::Normal,
229        }
230    }
231}
232
233impl TextStyle {
234    /// Create a new text style with the given highlighting applied.
235    pub fn highlight(mut self, style: impl Into<HighlightStyle>) -> Self {
236        let style = style.into();
237        if let Some(weight) = style.font_weight {
238            self.font_weight = weight;
239        }
240        if let Some(style) = style.font_style {
241            self.font_style = style;
242        }
243
244        if let Some(color) = style.color {
245            self.color = self.color.blend(color);
246        }
247
248        if let Some(factor) = style.fade_out {
249            self.color.fade_out(factor);
250        }
251
252        if let Some(background_color) = style.background_color {
253            self.background_color = Some(background_color);
254        }
255
256        if let Some(underline) = style.underline {
257            self.underline = Some(underline);
258        }
259
260        if let Some(strikethrough) = style.strikethrough {
261            self.strikethrough = Some(strikethrough);
262        }
263
264        self
265    }
266
267    /// Get the font configured for this text style.
268    pub fn font(&self) -> Font {
269        Font {
270            family: self.font_family.clone(),
271            features: self.font_features.clone(),
272            weight: self.font_weight,
273            style: self.font_style,
274        }
275    }
276
277    /// Returns the rounded line height in pixels.
278    pub fn line_height_in_pixels(&self, rem_size: Pixels) -> Pixels {
279        self.line_height.to_pixels(self.font_size, rem_size).round()
280    }
281
282    /// Convert this text style into a [`TextRun`], for the given length of the text.
283    pub fn to_run(&self, len: usize) -> TextRun {
284        TextRun {
285            len,
286            font: Font {
287                family: self.font_family.clone(),
288                features: Default::default(),
289                weight: self.font_weight,
290                style: self.font_style,
291            },
292            color: self.color,
293            background_color: self.background_color,
294            underline: self.underline,
295            strikethrough: self.strikethrough,
296        }
297    }
298}
299
300/// A highlight style to apply, similar to a `TextStyle` except
301/// for a single font, uniformly sized and spaced text.
302#[derive(Copy, Clone, Debug, Default, PartialEq)]
303pub struct HighlightStyle {
304    /// The color of the text
305    pub color: Option<Hsla>,
306
307    /// The font weight, e.g. bold
308    pub font_weight: Option<FontWeight>,
309
310    /// The font style, e.g. italic
311    pub font_style: Option<FontStyle>,
312
313    /// The background color of the text
314    pub background_color: Option<Hsla>,
315
316    /// The underline style of the text
317    pub underline: Option<UnderlineStyle>,
318
319    /// The underline style of the text
320    pub strikethrough: Option<StrikethroughStyle>,
321
322    /// Similar to the CSS `opacity` property, this will cause the text to be less vibrant.
323    pub fade_out: Option<f32>,
324}
325
326impl Eq for HighlightStyle {}
327
328impl Hash for HighlightStyle {
329    fn hash<H: Hasher>(&self, state: &mut H) {
330        self.color.hash(state);
331        self.font_weight.hash(state);
332        self.font_style.hash(state);
333        self.background_color.hash(state);
334        self.underline.hash(state);
335        self.strikethrough.hash(state);
336        state.write_u32(u32::from_be_bytes(
337            self.fade_out.map(|f| f.to_be_bytes()).unwrap_or_default(),
338        ));
339    }
340}
341
342impl Style {
343    /// Returns true if the style is visible and the background is opaque.
344    pub fn has_opaque_background(&self) -> bool {
345        self.background
346            .as_ref()
347            .is_some_and(|fill| fill.color().is_some_and(|color| !color.is_transparent()))
348    }
349
350    /// Get the text style in this element style.
351    pub fn text_style(&self) -> Option<&TextStyleRefinement> {
352        if self.text.is_some() {
353            Some(&self.text)
354        } else {
355            None
356        }
357    }
358
359    /// Get the content mask for this element style, based on the given bounds.
360    /// If the element does not hide its overflow, this will return `None`.
361    pub fn overflow_mask(
362        &self,
363        bounds: Bounds<Pixels>,
364        rem_size: Pixels,
365    ) -> Option<ContentMask<Pixels>> {
366        match self.overflow {
367            Point {
368                x: Overflow::Visible,
369                y: Overflow::Visible,
370            } => None,
371            _ => {
372                let mut min = bounds.origin;
373                let mut max = bounds.lower_right();
374
375                if self
376                    .border_color
377                    .map_or(false, |color| !color.is_transparent())
378                {
379                    min.x += self.border_widths.left.to_pixels(rem_size);
380                    max.x -= self.border_widths.right.to_pixels(rem_size);
381                    min.y += self.border_widths.top.to_pixels(rem_size);
382                    max.y -= self.border_widths.bottom.to_pixels(rem_size);
383                }
384
385                let bounds = match (
386                    self.overflow.x == Overflow::Visible,
387                    self.overflow.y == Overflow::Visible,
388                ) {
389                    // x and y both visible
390                    (true, true) => return None,
391                    // x visible, y hidden
392                    (true, false) => Bounds::from_corners(
393                        point(min.x, bounds.origin.y),
394                        point(max.x, bounds.lower_right().y),
395                    ),
396                    // x hidden, y visible
397                    (false, true) => Bounds::from_corners(
398                        point(bounds.origin.x, min.y),
399                        point(bounds.lower_right().x, max.y),
400                    ),
401                    // both hidden
402                    (false, false) => Bounds::from_corners(min, max),
403                };
404
405                Some(ContentMask { bounds })
406            }
407        }
408    }
409
410    /// Paints the background of an element styled with this style.
411    pub fn paint(
412        &self,
413        bounds: Bounds<Pixels>,
414        cx: &mut WindowContext,
415        continuation: impl FnOnce(&mut WindowContext),
416    ) {
417        #[cfg(debug_assertions)]
418        if self.debug_below {
419            cx.set_global(DebugBelow)
420        }
421
422        #[cfg(debug_assertions)]
423        if self.debug || cx.has_global::<DebugBelow>() {
424            cx.paint_quad(crate::outline(bounds, crate::red()));
425        }
426
427        let rem_size = cx.rem_size();
428
429        cx.paint_shadows(
430            bounds,
431            self.corner_radii.to_pixels(bounds.size, rem_size),
432            &self.box_shadow,
433        );
434
435        let background_color = self.background.as_ref().and_then(Fill::color);
436        if background_color.map_or(false, |color| !color.is_transparent()) {
437            let mut border_color = background_color.unwrap_or_default();
438            border_color.a = 0.;
439            cx.paint_quad(quad(
440                bounds,
441                self.corner_radii.to_pixels(bounds.size, rem_size),
442                background_color.unwrap_or_default(),
443                Edges::default(),
444                border_color,
445            ));
446        }
447
448        continuation(cx);
449
450        if self.is_border_visible() {
451            let corner_radii = self.corner_radii.to_pixels(bounds.size, rem_size);
452            let border_widths = self.border_widths.to_pixels(rem_size);
453            let max_border_width = border_widths.max();
454            let max_corner_radius = corner_radii.max();
455
456            let top_bounds = Bounds::from_corners(
457                bounds.origin,
458                bounds.upper_right() + point(Pixels::ZERO, max_border_width.max(max_corner_radius)),
459            );
460            let bottom_bounds = Bounds::from_corners(
461                bounds.lower_left() - point(Pixels::ZERO, max_border_width.max(max_corner_radius)),
462                bounds.lower_right(),
463            );
464            let left_bounds = Bounds::from_corners(
465                top_bounds.lower_left(),
466                bottom_bounds.origin + point(max_border_width, Pixels::ZERO),
467            );
468            let right_bounds = Bounds::from_corners(
469                top_bounds.lower_right() - point(max_border_width, Pixels::ZERO),
470                bottom_bounds.upper_right(),
471            );
472
473            let mut background = self.border_color.unwrap_or_default();
474            background.a = 0.;
475            let quad = quad(
476                bounds,
477                corner_radii,
478                background,
479                border_widths,
480                self.border_color.unwrap_or_default(),
481            );
482
483            cx.with_content_mask(Some(ContentMask { bounds: top_bounds }), |cx| {
484                cx.paint_quad(quad.clone());
485            });
486            cx.with_content_mask(
487                Some(ContentMask {
488                    bounds: right_bounds,
489                }),
490                |cx| {
491                    cx.paint_quad(quad.clone());
492                },
493            );
494            cx.with_content_mask(
495                Some(ContentMask {
496                    bounds: bottom_bounds,
497                }),
498                |cx| {
499                    cx.paint_quad(quad.clone());
500                },
501            );
502            cx.with_content_mask(
503                Some(ContentMask {
504                    bounds: left_bounds,
505                }),
506                |cx| {
507                    cx.paint_quad(quad);
508                },
509            );
510        }
511
512        #[cfg(debug_assertions)]
513        if self.debug_below {
514            cx.remove_global::<DebugBelow>();
515        }
516    }
517
518    fn is_border_visible(&self) -> bool {
519        self.border_color
520            .map_or(false, |color| !color.is_transparent())
521            && self.border_widths.any(|length| !length.is_zero())
522    }
523}
524
525impl Default for Style {
526    fn default() -> Self {
527        Style {
528            display: Display::Block,
529            visibility: Visibility::Visible,
530            overflow: Point {
531                x: Overflow::Visible,
532                y: Overflow::Visible,
533            },
534            scrollbar_width: 0.0,
535            position: Position::Relative,
536            inset: Edges::auto(),
537            margin: Edges::<Length>::zero(),
538            padding: Edges::<DefiniteLength>::zero(),
539            border_widths: Edges::<AbsoluteLength>::zero(),
540            size: Size::auto(),
541            min_size: Size::auto(),
542            max_size: Size::auto(),
543            aspect_ratio: None,
544            gap: Size::default(),
545            // Alignment
546            align_items: None,
547            align_self: None,
548            align_content: None,
549            justify_content: None,
550            // Flexbox
551            flex_direction: FlexDirection::Row,
552            flex_wrap: FlexWrap::NoWrap,
553            flex_grow: 0.0,
554            flex_shrink: 1.0,
555            flex_basis: Length::Auto,
556            background: None,
557            border_color: None,
558            corner_radii: Corners::default(),
559            box_shadow: Default::default(),
560            text: TextStyleRefinement::default(),
561            mouse_cursor: None,
562
563            #[cfg(debug_assertions)]
564            debug: false,
565            #[cfg(debug_assertions)]
566            debug_below: false,
567        }
568    }
569}
570
571/// The properties that can be applied to an underline.
572#[derive(Refineable, Copy, Clone, Default, Debug, PartialEq, Eq, Hash)]
573#[refineable(Debug)]
574pub struct UnderlineStyle {
575    /// The thickness of the underline.
576    pub thickness: Pixels,
577
578    /// The color of the underline.
579    pub color: Option<Hsla>,
580
581    /// Whether the underline should be wavy, like in a spell checker.
582    pub wavy: bool,
583}
584
585/// The properties that can be applied to a strikethrough.
586#[derive(Refineable, Copy, Clone, Default, Debug, PartialEq, Eq, Hash)]
587#[refineable(Debug)]
588pub struct StrikethroughStyle {
589    /// The thickness of the strikethrough.
590    pub thickness: Pixels,
591
592    /// The color of the strikethrough.
593    pub color: Option<Hsla>,
594}
595
596/// The kinds of fill that can be applied to a shape.
597#[derive(Clone, Debug)]
598pub enum Fill {
599    /// A solid color fill.
600    Color(Hsla),
601}
602
603impl Fill {
604    /// Unwrap this fill into a solid color, if it is one.
605    pub fn color(&self) -> Option<Hsla> {
606        match self {
607            Fill::Color(color) => Some(*color),
608        }
609    }
610}
611
612impl Default for Fill {
613    fn default() -> Self {
614        Self::Color(Hsla::default())
615    }
616}
617
618impl From<Hsla> for Fill {
619    fn from(color: Hsla) -> Self {
620        Self::Color(color)
621    }
622}
623
624impl From<Rgba> for Fill {
625    fn from(color: Rgba) -> Self {
626        Self::Color(color.into())
627    }
628}
629
630impl From<TextStyle> for HighlightStyle {
631    fn from(other: TextStyle) -> Self {
632        Self::from(&other)
633    }
634}
635
636impl From<&TextStyle> for HighlightStyle {
637    fn from(other: &TextStyle) -> Self {
638        Self {
639            color: Some(other.color),
640            font_weight: Some(other.font_weight),
641            font_style: Some(other.font_style),
642            background_color: other.background_color,
643            underline: other.underline,
644            strikethrough: other.strikethrough,
645            fade_out: None,
646        }
647    }
648}
649
650impl HighlightStyle {
651    /// Create a highlight style with just a color
652    pub fn color(color: Hsla) -> Self {
653        Self {
654            color: Some(color),
655            ..Default::default()
656        }
657    }
658    /// Blend this highlight style with another.
659    /// Non-continuous properties, like font_weight and font_style, are overwritten.
660    pub fn highlight(&mut self, other: HighlightStyle) {
661        match (self.color, other.color) {
662            (Some(self_color), Some(other_color)) => {
663                self.color = Some(Hsla::blend(other_color, self_color));
664            }
665            (None, Some(other_color)) => {
666                self.color = Some(other_color);
667            }
668            _ => {}
669        }
670
671        if other.font_weight.is_some() {
672            self.font_weight = other.font_weight;
673        }
674
675        if other.font_style.is_some() {
676            self.font_style = other.font_style;
677        }
678
679        if other.background_color.is_some() {
680            self.background_color = other.background_color;
681        }
682
683        if other.underline.is_some() {
684            self.underline = other.underline;
685        }
686
687        if other.strikethrough.is_some() {
688            self.strikethrough = other.strikethrough;
689        }
690
691        match (other.fade_out, self.fade_out) {
692            (Some(source_fade), None) => self.fade_out = Some(source_fade),
693            (Some(source_fade), Some(dest_fade)) => {
694                self.fade_out = Some((dest_fade * (1. + source_fade)).clamp(0., 1.));
695            }
696            _ => {}
697        }
698    }
699}
700
701impl From<Hsla> for HighlightStyle {
702    fn from(color: Hsla) -> Self {
703        Self {
704            color: Some(color),
705            ..Default::default()
706        }
707    }
708}
709
710impl From<FontWeight> for HighlightStyle {
711    fn from(font_weight: FontWeight) -> Self {
712        Self {
713            font_weight: Some(font_weight),
714            ..Default::default()
715        }
716    }
717}
718
719impl From<FontStyle> for HighlightStyle {
720    fn from(font_style: FontStyle) -> Self {
721        Self {
722            font_style: Some(font_style),
723            ..Default::default()
724        }
725    }
726}
727
728impl From<Rgba> for HighlightStyle {
729    fn from(color: Rgba) -> Self {
730        Self {
731            color: Some(color.into()),
732            ..Default::default()
733        }
734    }
735}
736
737/// Combine and merge the highlights and ranges in the two iterators.
738pub fn combine_highlights(
739    a: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
740    b: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
741) -> impl Iterator<Item = (Range<usize>, HighlightStyle)> {
742    let mut endpoints = Vec::new();
743    let mut highlights = Vec::new();
744    for (range, highlight) in a.into_iter().chain(b) {
745        if !range.is_empty() {
746            let highlight_id = highlights.len();
747            endpoints.push((range.start, highlight_id, true));
748            endpoints.push((range.end, highlight_id, false));
749            highlights.push(highlight);
750        }
751    }
752    endpoints.sort_unstable_by_key(|(position, _, _)| *position);
753    let mut endpoints = endpoints.into_iter().peekable();
754
755    let mut active_styles = HashSet::default();
756    let mut ix = 0;
757    iter::from_fn(move || {
758        while let Some((endpoint_ix, highlight_id, is_start)) = endpoints.peek() {
759            let prev_index = mem::replace(&mut ix, *endpoint_ix);
760            if ix > prev_index && !active_styles.is_empty() {
761                let mut current_style = HighlightStyle::default();
762                for highlight_id in &active_styles {
763                    current_style.highlight(highlights[*highlight_id]);
764                }
765                return Some((prev_index..ix, current_style));
766            }
767
768            if *is_start {
769                active_styles.insert(*highlight_id);
770            } else {
771                active_styles.remove(highlight_id);
772            }
773            endpoints.next();
774        }
775        None
776    })
777}
778
779#[cfg(test)]
780mod tests {
781    use crate::{blue, green, red, yellow};
782
783    use super::*;
784
785    #[test]
786    fn test_combine_highlights() {
787        assert_eq!(
788            combine_highlights(
789                [
790                    (0..5, green().into()),
791                    (4..10, FontWeight::BOLD.into()),
792                    (15..20, yellow().into()),
793                ],
794                [
795                    (2..6, FontStyle::Italic.into()),
796                    (1..3, blue().into()),
797                    (21..23, red().into()),
798                ]
799            )
800            .collect::<Vec<_>>(),
801            [
802                (
803                    0..1,
804                    HighlightStyle {
805                        color: Some(green()),
806                        ..Default::default()
807                    }
808                ),
809                (
810                    1..2,
811                    HighlightStyle {
812                        color: Some(green()),
813                        ..Default::default()
814                    }
815                ),
816                (
817                    2..3,
818                    HighlightStyle {
819                        color: Some(green()),
820                        font_style: Some(FontStyle::Italic),
821                        ..Default::default()
822                    }
823                ),
824                (
825                    3..4,
826                    HighlightStyle {
827                        color: Some(green()),
828                        font_style: Some(FontStyle::Italic),
829                        ..Default::default()
830                    }
831                ),
832                (
833                    4..5,
834                    HighlightStyle {
835                        color: Some(green()),
836                        font_weight: Some(FontWeight::BOLD),
837                        font_style: Some(FontStyle::Italic),
838                        ..Default::default()
839                    }
840                ),
841                (
842                    5..6,
843                    HighlightStyle {
844                        font_weight: Some(FontWeight::BOLD),
845                        font_style: Some(FontStyle::Italic),
846                        ..Default::default()
847                    }
848                ),
849                (
850                    6..10,
851                    HighlightStyle {
852                        font_weight: Some(FontWeight::BOLD),
853                        ..Default::default()
854                    }
855                ),
856                (
857                    15..20,
858                    HighlightStyle {
859                        color: Some(yellow()),
860                        ..Default::default()
861                    }
862                ),
863                (
864                    21..23,
865                    HighlightStyle {
866                        color: Some(red()),
867                        ..Default::default()
868                    }
869                )
870            ]
871        );
872    }
873}