From 1a0ad99dfd17dbc93ce039be86fa19a42d3bf2e9 Mon Sep 17 00:00:00 2001 From: Szabin Hamrik Date: Thu, 22 Jun 2023 10:34:17 +0200 Subject: [PATCH] `Spans::push` now takes `Span` --- helix-term/src/ui/statusline.rs | 24 +++++++++++----------- helix-tui/src/text.rs | 35 +++++++++++++++------------------ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 93a13b94a159e..f4d126cf31b00 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -217,16 +217,16 @@ fn render_diagnostics<'a>(context: &RenderContext) -> Spans<'a> { let mut spans = Spans::default(); if warnings > 0 { - spans.push("●", context.editor.theme.get("warning")); - spans.push( + spans.push(Span::styled("●", context.editor.theme.get("warning"))); + spans.push(Span::styled( format!(" {}{}", warnings, if errors > 0 { " " } else { "" }), context.base_style, - ); + )); } if errors > 0 { - spans.push("●", context.editor.theme.get("error")); - spans.push(format!(" {}", errors), context.base_style); + spans.push(Span::styled("●", context.editor.theme.get("error"))); + spans.push(Span::styled(format!(" {}", errors), context.base_style)); } spans @@ -247,19 +247,19 @@ fn render_workspace_diagnostics<'a>(context: &RenderContext) -> Spans<'a> { let mut spans = Spans::default(); if warnings > 0 || errors > 0 { - spans.push("W", context.base_style); + spans.push(Span::styled("W", context.base_style)); } if warnings > 0 { - spans.push(" ", context.base_style); - spans.push("●", context.editor.theme.get("warning")); - spans.push(format!(" {}", warnings), context.base_style); + spans.push(Span::styled(" ", context.base_style)); + spans.push(Span::styled("●", context.editor.theme.get("warning"))); + spans.push(Span::styled(format!(" {}", warnings), context.base_style)); } if errors > 0 { - spans.push(" ", context.base_style); - spans.push("●", context.editor.theme.get("error")); - spans.push(format!(" {}", errors), context.base_style); + spans.push(Span::styled(" ", context.base_style)); + spans.push(Span::styled("●", context.editor.theme.get("error"))); + spans.push(Span::styled(format!(" {}", errors), context.base_style)); } spans diff --git a/helix-tui/src/text.rs b/helix-tui/src/text.rs index 5de0b3c42ab74..3f579deab4bb7 100644 --- a/helix-tui/src/text.rs +++ b/helix-tui/src/text.rs @@ -238,15 +238,12 @@ impl<'a> Spans<'a> { /// ```rust /// # use helix_tui::text::{Span, Spans}; /// # use helix_view::graphics::{Color, Style}; - /// let mut spans = Spans::new(); - /// spans.push("Hello!", Style::default()); + /// let mut spans = Spans::default(); + /// spans.push(Span::styled("Hello!", Style::default())); /// assert_eq!("Hello!", spans.0[0].content); /// ``` - pub fn push(&mut self, string: T, style: Style) - where - T: Into>, - { - self.0.push(Span::styled(string, style)); + pub fn push(&mut self, span: Span<'a>) { + self.0.push(span); } /// Intersperses `sep` between items of the given iterator then returns the concatenated Spans. @@ -258,26 +255,26 @@ impl<'a> Spans<'a> { /// # use helix_view::graphics::Style; /// let spans = Spans::join( /// vec![ - /// Spans::single("Hello", Style::default()), - /// Spans::single("World!", Style::default()), + /// Span::styled("Hello", Style::default()).into(), + /// Span::styled("World!", Style::default()).into(), /// ].into_iter(), - /// &Spans::single(" ", Style::default()), + /// &Span::raw(" ").into(), /// ); /// assert_eq!("Hello World!", String::from(spans)); /// ``` - pub fn join(mut spanses: S, sep: &Spans<'a>) -> Spans<'a> + pub fn join(mut spans_iter: S, sep: &Spans<'a>) -> Spans<'a> where S: Iterator>, { - let mut spans: Vec = Vec::new(); - if let Some(head) = spanses.next() { - spans.extend(head.0); + let mut new_spans: Vec = Vec::new(); + if let Some(head) = spans_iter.next() { + new_spans.extend(head.0); } - spanses.for_each(|s| { - spans.extend(sep.0.clone()); - spans.extend(s.0); - }); - Spans(spans) + for s in spans_iter { + new_spans.extend(sep.0.clone()); + new_spans.extend(s.0); + } + Spans(new_spans) } }