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, FontFallbacks, FontFeatures,
 10    FontStyle, FontWeight, Hsla, Length, Pixels, Point, PointRefinement, Rgba, SharedString, Size,
 11    SizeRefinement, Styled, 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 fallback fonts to use
184    pub font_fallbacks: Option<FontFallbacks>,
185
186    /// The font size to use, in pixels or rems.
187    pub font_size: AbsoluteLength,
188
189    /// The line height to use, in pixels or fractions
190    pub line_height: DefiniteLength,
191
192    /// The font weight, e.g. bold
193    pub font_weight: FontWeight,
194
195    /// The font style, e.g. italic
196    pub font_style: FontStyle,
197
198    /// The background color of the text
199    pub background_color: Option<Hsla>,
200
201    /// The underline style of the text
202    pub underline: Option<UnderlineStyle>,
203
204    /// The strikethrough style of the text
205    pub strikethrough: Option<StrikethroughStyle>,
206
207    /// How to handle whitespace in the text
208    pub white_space: WhiteSpace,
209}
210
211impl Default for TextStyle {
212    fn default() -> Self {
213        TextStyle {
214            color: black(),
215            // todo(linux) make this configurable or choose better default
216            font_family: if cfg!(target_os = "linux") {
217                "FreeMono".into()
218            } else if cfg!(target_os = "windows") {
219                "Segoe UI".into()
220            } else {
221                "Helvetica".into()
222            },
223            font_features: FontFeatures::default(),
224            font_fallbacks: None,
225            font_size: rems(1.).into(),
226            line_height: phi(),
227            font_weight: FontWeight::default(),
228            font_style: FontStyle::default(),
229            background_color: None,
230            underline: None,
231            strikethrough: None,
232            white_space: WhiteSpace::Normal,
233        }
234    }
235}
236
237impl TextStyle {
238    /// Create a new text style with the given highlighting applied.
239    pub fn highlight(mut self, style: impl Into<HighlightStyle>) -> Self {
240        let style = style.into();
241        if let Some(weight) = style.font_weight {
242            self.font_weight = weight;
243        }
244        if let Some(style) = style.font_style {
245            self.font_style = style;
246        }
247
248        if let Some(color) = style.color {
249            self.color = self.color.blend(color);
250        }
251
252        if let Some(factor) = style.fade_out {
253            self.color.fade_out(factor);
254        }
255
256        if let Some(background_color) = style.background_color {
257            self.background_color = Some(background_color);
258        }
259
260        if let Some(underline) = style.underline {
261            self.underline = Some(underline);
262        }
263
264        if let Some(strikethrough) = style.strikethrough {
265            self.strikethrough = Some(strikethrough);
266        }
267
268        self
269    }
270
271    /// Get the font configured for this text style.
272    pub fn font(&self) -> Font {
273        Font {
274            family: self.font_family.clone(),
275            features: self.font_features.clone(),
276            fallbacks: self.font_fallbacks.clone(),
277            weight: self.font_weight,
278            style: self.font_style,
279        }
280    }
281
282    /// Returns the rounded line height in pixels.
283    pub fn line_height_in_pixels(&self, rem_size: Pixels) -> Pixels {
284        self.line_height.to_pixels(self.font_size, rem_size).round()
285    }
286
287    /// Convert this text style into a [`TextRun`], for the given length of the text.
288    pub fn to_run(&self, len: usize) -> TextRun {
289        TextRun {
290            len,
291            font: Font {
292                family: self.font_family.clone(),
293                features: Default::default(),
294                fallbacks: self.font_fallbacks.clone(),
295                weight: self.font_weight,
296                style: self.font_style,
297            },
298            color: self.color,
299            background_color: self.background_color,
300            underline: self.underline,
301            strikethrough: self.strikethrough,
302        }
303    }
304}
305
306/// A highlight style to apply, similar to a `TextStyle` except
307/// for a single font, uniformly sized and spaced text.
308#[derive(Copy, Clone, Debug, Default, PartialEq)]
309pub struct HighlightStyle {
310    /// The color of the text
311    pub color: Option<Hsla>,
312
313    /// The font weight, e.g. bold
314    pub font_weight: Option<FontWeight>,
315
316    /// The font style, e.g. italic
317    pub font_style: Option<FontStyle>,
318
319    /// The background color of the text
320    pub background_color: Option<Hsla>,
321
322    /// The underline style of the text
323    pub underline: Option<UnderlineStyle>,
324
325    /// The underline style of the text
326    pub strikethrough: Option<StrikethroughStyle>,
327
328    /// Similar to the CSS `opacity` property, this will cause the text to be less vibrant.
329    pub fade_out: Option<f32>,
330}
331
332impl Eq for HighlightStyle {}
333
334impl Hash for HighlightStyle {
335    fn hash<H: Hasher>(&self, state: &mut H) {
336        self.color.hash(state);
337        self.font_weight.hash(state);
338        self.font_style.hash(state);
339        self.background_color.hash(state);
340        self.underline.hash(state);
341        self.strikethrough.hash(state);
342        state.write_u32(u32::from_be_bytes(
343            self.fade_out.map(|f| f.to_be_bytes()).unwrap_or_default(),
344        ));
345    }
346}
347
348impl Style {
349    /// Returns true if the style is visible and the background is opaque.
350    pub fn has_opaque_background(&self) -> bool {
351        self.background
352            .as_ref()
353            .is_some_and(|fill| fill.color().is_some_and(|color| !color.is_transparent()))
354    }
355
356    /// Get the text style in this element style.
357    pub fn text_style(&self) -> Option<&TextStyleRefinement> {
358        if self.text.is_some() {
359            Some(&self.text)
360        } else {
361            None
362        }
363    }
364
365    /// Get the content mask for this element style, based on the given bounds.
366    /// If the element does not hide its overflow, this will return `None`.
367    pub fn overflow_mask(
368        &self,
369        bounds: Bounds<Pixels>,
370        rem_size: Pixels,
371    ) -> Option<ContentMask<Pixels>> {
372        match self.overflow {
373            Point {
374                x: Overflow::Visible,
375                y: Overflow::Visible,
376            } => None,
377            _ => {
378                let mut min = bounds.origin;
379                let mut max = bounds.lower_right();
380
381                if self
382                    .border_color
383                    .map_or(false, |color| !color.is_transparent())
384                {
385                    min.x += self.border_widths.left.to_pixels(rem_size);
386                    max.x -= self.border_widths.right.to_pixels(rem_size);
387                    min.y += self.border_widths.top.to_pixels(rem_size);
388                    max.y -= self.border_widths.bottom.to_pixels(rem_size);
389                }
390
391                let bounds = match (
392                    self.overflow.x == Overflow::Visible,
393                    self.overflow.y == Overflow::Visible,
394                ) {
395                    // x and y both visible
396                    (true, true) => return None,
397                    // x visible, y hidden
398                    (true, false) => Bounds::from_corners(
399                        point(min.x, bounds.origin.y),
400                        point(max.x, bounds.lower_right().y),
401                    ),
402                    // x hidden, y visible
403                    (false, true) => Bounds::from_corners(
404                        point(bounds.origin.x, min.y),
405                        point(bounds.lower_right().x, max.y),
406                    ),
407                    // both hidden
408                    (false, false) => Bounds::from_corners(min, max),
409                };
410
411                Some(ContentMask { bounds })
412            }
413        }
414    }
415
416    /// Paints the background of an element styled with this style.
417    pub fn paint(
418        &self,
419        bounds: Bounds<Pixels>,
420        cx: &mut WindowContext,
421        continuation: impl FnOnce(&mut WindowContext),
422    ) {
423        #[cfg(debug_assertions)]
424        if self.debug_below {
425            cx.set_global(DebugBelow)
426        }
427
428        #[cfg(debug_assertions)]
429        if self.debug || cx.has_global::<DebugBelow>() {
430            cx.paint_quad(crate::outline(bounds, crate::red()));
431        }
432
433        let rem_size = cx.rem_size();
434
435        cx.paint_shadows(
436            bounds,
437            self.corner_radii.to_pixels(bounds.size, rem_size),
438            &self.box_shadow,
439        );
440
441        let background_color = self.background.as_ref().and_then(Fill::color);
442        if background_color.map_or(false, |color| !color.is_transparent()) {
443            let mut border_color = background_color.unwrap_or_default();
444            border_color.a = 0.;
445            cx.paint_quad(quad(
446                bounds,
447                self.corner_radii.to_pixels(bounds.size, rem_size),
448                background_color.unwrap_or_default(),
449                Edges::default(),
450                border_color,
451            ));
452        }
453
454        continuation(cx);
455
456        if self.is_border_visible() {
457            let corner_radii = self.corner_radii.to_pixels(bounds.size, rem_size);
458            let border_widths = self.border_widths.to_pixels(rem_size);
459            let max_border_width = border_widths.max();
460            let max_corner_radius = corner_radii.max();
461
462            let top_bounds = Bounds::from_corners(
463                bounds.origin,
464                bounds.upper_right() + point(Pixels::ZERO, max_border_width.max(max_corner_radius)),
465            );
466            let bottom_bounds = Bounds::from_corners(
467                bounds.lower_left() - point(Pixels::ZERO, max_border_width.max(max_corner_radius)),
468                bounds.lower_right(),
469            );
470            let left_bounds = Bounds::from_corners(
471                top_bounds.lower_left(),
472                bottom_bounds.origin + point(max_border_width, Pixels::ZERO),
473            );
474            let right_bounds = Bounds::from_corners(
475                top_bounds.lower_right() - point(max_border_width, Pixels::ZERO),
476                bottom_bounds.upper_right(),
477            );
478
479            let mut background = self.border_color.unwrap_or_default();
480            background.a = 0.;
481            let quad = quad(
482                bounds,
483                corner_radii,
484                background,
485                border_widths,
486                self.border_color.unwrap_or_default(),
487            );
488
489            cx.with_content_mask(Some(ContentMask { bounds: top_bounds }), |cx| {
490                cx.paint_quad(quad.clone());
491            });
492            cx.with_content_mask(
493                Some(ContentMask {
494                    bounds: right_bounds,
495                }),
496                |cx| {
497                    cx.paint_quad(quad.clone());
498                },
499            );
500            cx.with_content_mask(
501                Some(ContentMask {
502                    bounds: bottom_bounds,
503                }),
504                |cx| {
505                    cx.paint_quad(quad.clone());
506                },
507            );
508            cx.with_content_mask(
509                Some(ContentMask {
510                    bounds: left_bounds,
511                }),
512                |cx| {
513                    cx.paint_quad(quad);
514                },
515            );
516        }
517
518        #[cfg(debug_assertions)]
519        if self.debug_below {
520            cx.remove_global::<DebugBelow>();
521        }
522    }
523
524    fn is_border_visible(&self) -> bool {
525        self.border_color
526            .map_or(false, |color| !color.is_transparent())
527            && self.border_widths.any(|length| !length.is_zero())
528    }
529}
530
531impl Default for Style {
532    fn default() -> Self {
533        Style {
534            display: Display::Block,
535            visibility: Visibility::Visible,
536            overflow: Point {
537                x: Overflow::Visible,
538                y: Overflow::Visible,
539            },
540            scrollbar_width: 0.0,
541            position: Position::Relative,
542            inset: Edges::auto(),
543            margin: Edges::<Length>::zero(),
544            padding: Edges::<DefiniteLength>::zero(),
545            border_widths: Edges::<AbsoluteLength>::zero(),
546            size: Size::auto(),
547            min_size: Size::auto(),
548            max_size: Size::auto(),
549            aspect_ratio: None,
550            gap: Size::default(),
551            // Alignment
552            align_items: None,
553            align_self: None,
554            align_content: None,
555            justify_content: None,
556            // Flexbox
557            flex_direction: FlexDirection::Row,
558            flex_wrap: FlexWrap::NoWrap,
559            flex_grow: 0.0,
560            flex_shrink: 1.0,
561            flex_basis: Length::Auto,
562            background: None,
563            border_color: None,
564            corner_radii: Corners::default(),
565            box_shadow: Default::default(),
566            text: TextStyleRefinement::default(),
567            mouse_cursor: None,
568
569            #[cfg(debug_assertions)]
570            debug: false,
571            #[cfg(debug_assertions)]
572            debug_below: false,
573        }
574    }
575}
576
577/// The properties that can be applied to an underline.
578#[derive(Refineable, Copy, Clone, Default, Debug, PartialEq, Eq, Hash)]
579#[refineable(Debug)]
580pub struct UnderlineStyle {
581    /// The thickness of the underline.
582    pub thickness: Pixels,
583
584    /// The color of the underline.
585    pub color: Option<Hsla>,
586
587    /// Whether the underline should be wavy, like in a spell checker.
588    pub wavy: bool,
589}
590
591/// The properties that can be applied to a strikethrough.
592#[derive(Refineable, Copy, Clone, Default, Debug, PartialEq, Eq, Hash)]
593#[refineable(Debug)]
594pub struct StrikethroughStyle {
595    /// The thickness of the strikethrough.
596    pub thickness: Pixels,
597
598    /// The color of the strikethrough.
599    pub color: Option<Hsla>,
600}
601
602/// The kinds of fill that can be applied to a shape.
603#[derive(Clone, Debug)]
604pub enum Fill {
605    /// A solid color fill.
606    Color(Hsla),
607}
608
609impl Fill {
610    /// Unwrap this fill into a solid color, if it is one.
611    pub fn color(&self) -> Option<Hsla> {
612        match self {
613            Fill::Color(color) => Some(*color),
614        }
615    }
616}
617
618impl Default for Fill {
619    fn default() -> Self {
620        Self::Color(Hsla::default())
621    }
622}
623
624impl From<Hsla> for Fill {
625    fn from(color: Hsla) -> Self {
626        Self::Color(color)
627    }
628}
629
630impl From<Rgba> for Fill {
631    fn from(color: Rgba) -> Self {
632        Self::Color(color.into())
633    }
634}
635
636impl From<TextStyle> for HighlightStyle {
637    fn from(other: TextStyle) -> Self {
638        Self::from(&other)
639    }
640}
641
642impl From<&TextStyle> for HighlightStyle {
643    fn from(other: &TextStyle) -> Self {
644        Self {
645            color: Some(other.color),
646            font_weight: Some(other.font_weight),
647            font_style: Some(other.font_style),
648            background_color: other.background_color,
649            underline: other.underline,
650            strikethrough: other.strikethrough,
651            fade_out: None,
652        }
653    }
654}
655
656impl HighlightStyle {
657    /// Create a highlight style with just a color
658    pub fn color(color: Hsla) -> Self {
659        Self {
660            color: Some(color),
661            ..Default::default()
662        }
663    }
664    /// Blend this highlight style with another.
665    /// Non-continuous properties, like font_weight and font_style, are overwritten.
666    pub fn highlight(&mut self, other: HighlightStyle) {
667        match (self.color, other.color) {
668            (Some(self_color), Some(other_color)) => {
669                self.color = Some(Hsla::blend(other_color, self_color));
670            }
671            (None, Some(other_color)) => {
672                self.color = Some(other_color);
673            }
674            _ => {}
675        }
676
677        if other.font_weight.is_some() {
678            self.font_weight = other.font_weight;
679        }
680
681        if other.font_style.is_some() {
682            self.font_style = other.font_style;
683        }
684
685        if other.background_color.is_some() {
686            self.background_color = other.background_color;
687        }
688
689        if other.underline.is_some() {
690            self.underline = other.underline;
691        }
692
693        if other.strikethrough.is_some() {
694            self.strikethrough = other.strikethrough;
695        }
696
697        match (other.fade_out, self.fade_out) {
698            (Some(source_fade), None) => self.fade_out = Some(source_fade),
699            (Some(source_fade), Some(dest_fade)) => {
700                self.fade_out = Some((dest_fade * (1. + source_fade)).clamp(0., 1.));
701            }
702            _ => {}
703        }
704    }
705}
706
707impl From<Hsla> for HighlightStyle {
708    fn from(color: Hsla) -> Self {
709        Self {
710            color: Some(color),
711            ..Default::default()
712        }
713    }
714}
715
716impl From<FontWeight> for HighlightStyle {
717    fn from(font_weight: FontWeight) -> Self {
718        Self {
719            font_weight: Some(font_weight),
720            ..Default::default()
721        }
722    }
723}
724
725impl From<FontStyle> for HighlightStyle {
726    fn from(font_style: FontStyle) -> Self {
727        Self {
728            font_style: Some(font_style),
729            ..Default::default()
730        }
731    }
732}
733
734impl From<Rgba> for HighlightStyle {
735    fn from(color: Rgba) -> Self {
736        Self {
737            color: Some(color.into()),
738            ..Default::default()
739        }
740    }
741}
742
743/// Combine and merge the highlights and ranges in the two iterators.
744pub fn combine_highlights(
745    a: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
746    b: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
747) -> impl Iterator<Item = (Range<usize>, HighlightStyle)> {
748    let mut endpoints = Vec::new();
749    let mut highlights = Vec::new();
750    for (range, highlight) in a.into_iter().chain(b) {
751        if !range.is_empty() {
752            let highlight_id = highlights.len();
753            endpoints.push((range.start, highlight_id, true));
754            endpoints.push((range.end, highlight_id, false));
755            highlights.push(highlight);
756        }
757    }
758    endpoints.sort_unstable_by_key(|(position, _, _)| *position);
759    let mut endpoints = endpoints.into_iter().peekable();
760
761    let mut active_styles = HashSet::default();
762    let mut ix = 0;
763    iter::from_fn(move || {
764        while let Some((endpoint_ix, highlight_id, is_start)) = endpoints.peek() {
765            let prev_index = mem::replace(&mut ix, *endpoint_ix);
766            if ix > prev_index && !active_styles.is_empty() {
767                let mut current_style = HighlightStyle::default();
768                for highlight_id in &active_styles {
769                    current_style.highlight(highlights[*highlight_id]);
770                }
771                return Some((prev_index..ix, current_style));
772            }
773
774            if *is_start {
775                active_styles.insert(*highlight_id);
776            } else {
777                active_styles.remove(highlight_id);
778            }
779            endpoints.next();
780        }
781        None
782    })
783}
784
785#[cfg(test)]
786mod tests {
787    use crate::{blue, green, red, yellow};
788
789    use super::*;
790
791    #[test]
792    fn test_combine_highlights() {
793        assert_eq!(
794            combine_highlights(
795                [
796                    (0..5, green().into()),
797                    (4..10, FontWeight::BOLD.into()),
798                    (15..20, yellow().into()),
799                ],
800                [
801                    (2..6, FontStyle::Italic.into()),
802                    (1..3, blue().into()),
803                    (21..23, red().into()),
804                ]
805            )
806            .collect::<Vec<_>>(),
807            [
808                (
809                    0..1,
810                    HighlightStyle {
811                        color: Some(green()),
812                        ..Default::default()
813                    }
814                ),
815                (
816                    1..2,
817                    HighlightStyle {
818                        color: Some(green()),
819                        ..Default::default()
820                    }
821                ),
822                (
823                    2..3,
824                    HighlightStyle {
825                        color: Some(green()),
826                        font_style: Some(FontStyle::Italic),
827                        ..Default::default()
828                    }
829                ),
830                (
831                    3..4,
832                    HighlightStyle {
833                        color: Some(green()),
834                        font_style: Some(FontStyle::Italic),
835                        ..Default::default()
836                    }
837                ),
838                (
839                    4..5,
840                    HighlightStyle {
841                        color: Some(green()),
842                        font_weight: Some(FontWeight::BOLD),
843                        font_style: Some(FontStyle::Italic),
844                        ..Default::default()
845                    }
846                ),
847                (
848                    5..6,
849                    HighlightStyle {
850                        font_weight: Some(FontWeight::BOLD),
851                        font_style: Some(FontStyle::Italic),
852                        ..Default::default()
853                    }
854                ),
855                (
856                    6..10,
857                    HighlightStyle {
858                        font_weight: Some(FontWeight::BOLD),
859                        ..Default::default()
860                    }
861                ),
862                (
863                    15..20,
864                    HighlightStyle {
865                        color: Some(yellow()),
866                        ..Default::default()
867                    }
868                ),
869                (
870                    21..23,
871                    HighlightStyle {
872                        color: Some(red()),
873                        ..Default::default()
874                    }
875                )
876            ]
877        );
878    }
879}