Skip to content

Commit

Permalink
chore(spans): remove deprecated Spans type
Browse files Browse the repository at this point in the history
`Spans` was replaced with `Line` in 0.21.0. This commit removes the
deprecated type and all associated code. `Buffer::set_spans` was
replaced with `Buffer::set_line`.
  • Loading branch information
joshka committed Aug 24, 2023
1 parent 80fd77e commit d65a49f
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 299 deletions.
26 changes: 1 addition & 25 deletions src/buffer.rs
Original file line number Diff line number Diff line change
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 @@ -335,29 +334,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
Original file line number Diff line number Diff line change
@@ -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 @@ -187,18 +186,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 @@ -273,15 +266,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
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,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;
225 changes: 0 additions & 225 deletions src/text/spans.rs

This file was deleted.

21 changes: 1 addition & 20 deletions src/text/text.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;

#[allow(deprecated)]
use super::{Line, Span, Spans};
use super::{Line, Span};
use crate::style::Style;

/// A string split over multiple lines where each line is composed of several clusters, each with
Expand Down Expand Up @@ -175,30 +174,12 @@ impl<'a> From<Span<'a>> for Text<'a> {
}
}

#[allow(deprecated)]
impl<'a> From<Spans<'a>> for Text<'a> {
fn from(spans: Spans<'a>) -> Text<'a> {
Text {
lines: vec![spans.into()],
}
}
}

impl<'a> From<Line<'a>> for Text<'a> {
fn from(line: Line<'a>) -> Text<'a> {
Text { lines: vec![line] }
}
}

#[allow(deprecated)]
impl<'a> From<Vec<Spans<'a>>> for Text<'a> {
fn from(lines: Vec<Spans<'a>>) -> Text<'a> {
Text {
lines: lines.into_iter().map(|l| l.0.into()).collect(),
}
}
}

impl<'a> From<Vec<Line<'a>>> for Text<'a> {
fn from(lines: Vec<Line<'a>>) -> Text<'a> {
Text { lines }
Expand Down
2 changes: 0 additions & 2 deletions tests/widgets_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(deprecated)]

use ratatui::{
backend::TestBackend,
buffer::Buffer,
Expand Down
2 changes: 0 additions & 2 deletions tests/widgets_paragraph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(deprecated)]

use ratatui::{
backend::TestBackend,
buffer::Buffer,
Expand Down
2 changes: 0 additions & 2 deletions tests/widgets_tabs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(deprecated)]

use ratatui::{
backend::TestBackend, buffer::Buffer, layout::Rect, symbols, text::Line, widgets::Tabs,
Terminal,
Expand Down

0 comments on commit d65a49f

Please sign in to comment.