style.rs

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