Skip to content

Commit

Permalink
chore: Spans -> Line, ratatui 0.21 update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed Jun 3, 2023
1 parent 0caa92f commit 4679ddc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/ui/color_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ pub mod log_sanitizer {
use cansi::{v3::categorise_text, Color as CansiColor, Intensity};
use ratatui::{
style::{Color, Modifier, Style},
text::{Span, Spans},
text::{Span, Line},
};

/// Attempt to colorize the given string to tui-rs standards
pub fn colorize_logs<'a>(input: &str) -> Vec<Spans<'a>> {
vec![Spans::from(
pub fn colorize_logs<'a>(input: &str) -> Vec<Line<'a>> {
vec![Line::from(
categorise_text(input)
.iter()
.map(|i| {
Expand Down Expand Up @@ -40,16 +40,16 @@ pub mod log_sanitizer {
}

/// Remove all ansi formatting from a given string and create tui-rs spans
pub fn remove_ansi<'a>(input: &str) -> Vec<Spans<'a>> {
pub fn remove_ansi<'a>(input: &str) -> Vec<Line<'a>> {
raw(&categorise_text(input)
.into_iter()
.map(|i| i.text)
.collect::<String>())
}

/// create tui-rs spans that exactly match the given strings
pub fn raw<'a>(input: &str) -> Vec<Spans<'a>> {
vec![Spans::from(Span::raw(input.to_owned()))]
pub fn raw<'a>(input: &str) -> Vec<Line<'a>> {
vec![Line::from(Span::raw(input.to_owned()))]
}

/// Change from ansi to tui colors
Expand Down
46 changes: 23 additions & 23 deletions src/ui/draw_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
symbols,
text::{Span, Spans},
text::{Span, Line},
widgets::{
Axis, Block, BorderType, Borders, Chart, Clear, Dataset, GraphType, List, ListItem,
Paragraph,
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn commands<B: Backend>(
let items = app_data.lock().get_control_items().map_or(vec![], |i| {
i.iter()
.map(|c| {
let lines = Spans::from(vec![Span::styled(
let lines = Line::from(vec![Span::styled(
c.to_string(),
Style::default().fg(c.get_color()),
)]);
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn containers<B: Backend>(
let state_style = Style::default().fg(i.state.get_color());
let blue = Style::default().fg(Color::Blue);

let lines = Spans::from(vec![
let lines = Line::from(vec![
Span::styled(
format!(
"{:<width$}",
Expand Down Expand Up @@ -489,25 +489,25 @@ pub fn heading_bar<B: Backend>(

/// Help popup box needs these three pieces of information
struct HelpInfo {
spans: Vec<Spans<'static>>,
spans: Vec<Line<'static>>,
width: usize,
height: usize,
}

impl HelpInfo {
/// Find the max width of a Span in &[Spans], although it isn't calculating it correctly
fn calc_width(spans: &[Spans]) -> usize {
spans
/// Find the max width of a Span in &[Line], although it isn't calculating it correctly
fn calc_width(lines: &[Line]) -> usize {
lines
.iter()
.flat_map(|x| x.0.iter())
.flat_map(|x| x.spans.iter())
.map(ratatui::text::Span::width)
.max()
.unwrap_or(1)
}

/// Just an empty span, i.e. a new line
fn empty_span<'a>() -> Spans<'a> {
Spans::from(String::new())
fn empty_span<'a>() -> Line<'a> {
Line::from(String::new())
}

/// generate a span, of given &str and given color
Expand All @@ -529,7 +529,7 @@ impl HelpInfo {
fn gen_name() -> Self {
let mut spans = NAME_TEXT
.lines()
.map(|i| Spans::from(Self::white_span(i)))
.map(|i| Line::from(Self::white_span(i)))
.collect::<Vec<_>>();
spans.insert(0, Self::empty_span());
let width = Self::calc_width(&spans);
Expand All @@ -545,7 +545,7 @@ impl HelpInfo {
fn gen_description() -> Self {
let spans = [
Self::empty_span(),
Spans::from(Self::white_span(DESCRIPTION)),
Line::from(Self::white_span(DESCRIPTION)),
Self::empty_span(),
];
let width = Self::calc_width(&spans);
Expand All @@ -565,14 +565,14 @@ impl HelpInfo {
let space = || button_desc(" ");

let spans = [
Spans::from(vec![
Line::from(vec![
space(),
button_item("tab"),
or(),
button_item("shift+tab"),
button_desc("to change panels"),
]),
Spans::from(vec![
Line::from(vec![
space(),
button_item("↑ ↓"),
or(),
Expand All @@ -583,30 +583,30 @@ impl HelpInfo {
button_item("Home End"),
button_desc("to change selected line"),
]),
Spans::from(vec![
Line::from(vec![
space(),
button_item("enter"),
button_desc("to send docker container command"),
]),
Spans::from(vec![
Line::from(vec![
space(),
button_item("h"),
button_desc("to toggle this help information"),
]),
Spans::from(vec![space(), button_item("0"), button_desc("to stop sort")]),
Spans::from(vec![
Line::from(vec![space(), button_item("0"), button_desc("to stop sort")]),
Line::from(vec![
space(),
button_item("1 - 9"),
button_desc("sort by header - or click header"),
]),
Spans::from(vec![
Line::from(vec![
space(),
button_item("m"),
button_desc(
"to toggle mouse capture - if disabled, text on screen can be selected & copied",
),
]),
Spans::from(vec![
Line::from(vec![
space(),
button_item("q"),
button_desc("to quit at any time"),
Expand All @@ -626,10 +626,10 @@ impl HelpInfo {
fn gen_final() -> Self {
let spans = [
Self::empty_span(),
Spans::from(vec![Self::black_span(
Line::from(vec![Self::black_span(
"currently an early work in progress, all and any input appreciated",
)]),
Spans::from(vec![Span::styled(
Line::from(vec![Span::styled(
REPO.to_owned(),
Style::default()
.fg(Color::White)
Expand Down Expand Up @@ -738,7 +738,7 @@ pub fn delete_confirm<B: Backend>(
.title_alignment(Alignment::Center)
.borders(Borders::ALL);

let confirm = Spans::from(vec![
let confirm = Line::from(vec![
Span::from("Are you sure you want to delete container: "),
Span::styled(
name,
Expand Down
4 changes: 1 addition & 3 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ fn draw_frame<B: Backend>(
);

if let Some(id) = delete_confirm {
let name = app_data.lock().get_container_name_by_id(&id);
name.map_or_else(
|| {
app_data.lock().get_container_name_by_id(&id).map_or_else(|| {
// If a container is deleted outside of oxker but whilst the Delete Confirm dialog is open, it can get caught in kind of a dead lock situation
// so if in that unique situation, just clear the delete_container id
gui_state.lock().set_delete_container(None);
Expand Down

0 comments on commit 4679ddc

Please # to comment.