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