Skip to content

Commit

Permalink
chore(spans): remove deprecated Spans type
Browse files Browse the repository at this point in the history
- `Line` replaces `Spans`
- `Buffer::set_line` replaces `Buffer::set_spans`
  • Loading branch information
joshka committed Sep 12, 2023
1 parent 94af2a2 commit e96e5a1
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 327 deletions.
26 changes: 1 addition & 25 deletions src/buffer.rs
Expand Up @@ -6,11 +6,10 @@ use std::{
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;

#[allow(deprecated)]
use crate::{
layout::Rect,
style::{Color, Modifier, Style},
text::{Line, Span, Spans},
text::{Line, Span},
};

/// A buffer cell
Expand Down Expand Up @@ -334,29 +333,6 @@ impl Buffer {
(x_offset as u16, y)
}

#[allow(deprecated)]
#[deprecated(note = "Use `Buffer::set_line` instead")]
pub fn set_spans(&mut self, x: u16, y: u16, spans: &Spans<'_>, width: u16) -> (u16, u16) {
let mut remaining_width = width;
let mut x = x;
for span in &spans.0 {
if remaining_width == 0 {
break;
}
let pos = self.set_stringn(
x,
y,
span.content.as_ref(),
remaining_width as usize,
span.style,
);
let w = pos.0.saturating_sub(x);
x = pos.0;
remaining_width = remaining_width.saturating_sub(w);
}
(x, y)
}

pub fn set_line(&mut self, x: u16, y: u16, line: &Line<'_>, width: u16) -> (u16, u16) {
let mut remaining_width = width;
let mut x = x;
Expand Down
20 changes: 2 additions & 18 deletions src/text/line.rs
@@ -1,7 +1,6 @@
#![allow(deprecated)]
use std::borrow::Cow;

use super::{Span, Spans, Style, StyledGrapheme};
use super::{Span, Style, StyledGrapheme};
use crate::layout::Alignment;

#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -180,18 +179,12 @@ impl<'a> From<Line<'a>> for String {
}
}

impl<'a> From<Spans<'a>> for Line<'a> {
fn from(value: Spans<'a>) -> Self {
Self::from(value.0)
}
}

#[cfg(test)]
mod tests {
use crate::{
layout::Alignment,
style::{Color, Modifier, Style},
text::{Line, Span, Spans, StyledGrapheme},
text::{Line, Span, StyledGrapheme},
};

#[test]
Expand Down Expand Up @@ -266,15 +259,6 @@ mod tests {
assert_eq!(vec![span], line.spans);
}

#[test]
fn test_from_spans() {
let spans = vec![
Span::styled("Hello,", Style::default().fg(Color::Red)),
Span::styled(" world!", Style::default().fg(Color::Green)),
];
assert_eq!(Line::from(Spans::from(spans.clone())), Line::from(spans));
}

#[test]
fn test_into_string() {
let line = Line::from(vec![
Expand Down
5 changes: 0 additions & 5 deletions src/text/mod.rs
Expand Up @@ -60,11 +60,6 @@ pub use masked::Masked;
mod span;
pub use span::Span;

/// We keep this for backward compatibility.
mod spans;
#[allow(deprecated)]
pub use spans::Spans;

#[allow(clippy::module_inception)]
mod text;
pub use text::Text;
223 changes: 0 additions & 223 deletions src/text/spans.rs

This file was deleted.

0 comments on commit e96e5a1

Please sign in to comment.