chore: Spans -> Line, ratatui 0.21 update
This commit is contained in:
@@ -3,12 +3,12 @@ pub mod log_sanitizer {
|
|||||||
use cansi::{v3::categorise_text, Color as CansiColor, Intensity};
|
use cansi::{v3::categorise_text, Color as CansiColor, Intensity};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
style::{Color, Modifier, Style},
|
style::{Color, Modifier, Style},
|
||||||
text::{Span, Spans},
|
text::{Span, Line},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Attempt to colorize the given string to tui-rs standards
|
/// Attempt to colorize the given string to tui-rs standards
|
||||||
pub fn colorize_logs<'a>(input: &str) -> Vec<Spans<'a>> {
|
pub fn colorize_logs<'a>(input: &str) -> Vec<Line<'a>> {
|
||||||
vec![Spans::from(
|
vec![Line::from(
|
||||||
categorise_text(input)
|
categorise_text(input)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
@@ -40,7 +40,7 @@ pub mod log_sanitizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remove all ansi formatting from a given string and create tui-rs spans
|
/// 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)
|
raw(&categorise_text(input)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|i| i.text)
|
.map(|i| i.text)
|
||||||
@@ -48,8 +48,8 @@ pub mod log_sanitizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// create tui-rs spans that exactly match the given strings
|
/// create tui-rs spans that exactly match the given strings
|
||||||
pub fn raw<'a>(input: &str) -> Vec<Spans<'a>> {
|
pub fn raw<'a>(input: &str) -> Vec<Line<'a>> {
|
||||||
vec![Spans::from(Span::raw(input.to_owned()))]
|
vec![Line::from(Span::raw(input.to_owned()))]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change from ansi to tui colors
|
/// Change from ansi to tui colors
|
||||||
|
|||||||
+23
-23
@@ -4,7 +4,7 @@ use ratatui::{
|
|||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
style::{Color, Modifier, Style},
|
style::{Color, Modifier, Style},
|
||||||
symbols,
|
symbols,
|
||||||
text::{Span, Spans},
|
text::{Span, Line},
|
||||||
widgets::{
|
widgets::{
|
||||||
Axis, Block, BorderType, Borders, Chart, Clear, Dataset, GraphType, List, ListItem,
|
Axis, Block, BorderType, Borders, Chart, Clear, Dataset, GraphType, List, ListItem,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
@@ -96,7 +96,7 @@ pub fn commands<B: Backend>(
|
|||||||
let items = app_data.lock().get_control_items().map_or(vec![], |i| {
|
let items = app_data.lock().get_control_items().map_or(vec![], |i| {
|
||||||
i.iter()
|
i.iter()
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
let lines = Spans::from(vec![Span::styled(
|
let lines = Line::from(vec![Span::styled(
|
||||||
c.to_string(),
|
c.to_string(),
|
||||||
Style::default().fg(c.get_color()),
|
Style::default().fg(c.get_color()),
|
||||||
)]);
|
)]);
|
||||||
@@ -138,7 +138,7 @@ pub fn containers<B: Backend>(
|
|||||||
let state_style = Style::default().fg(i.state.get_color());
|
let state_style = Style::default().fg(i.state.get_color());
|
||||||
let blue = Style::default().fg(Color::Blue);
|
let blue = Style::default().fg(Color::Blue);
|
||||||
|
|
||||||
let lines = Spans::from(vec![
|
let lines = Line::from(vec![
|
||||||
Span::styled(
|
Span::styled(
|
||||||
format!(
|
format!(
|
||||||
"{:<width$}",
|
"{:<width$}",
|
||||||
@@ -489,25 +489,25 @@ pub fn heading_bar<B: Backend>(
|
|||||||
|
|
||||||
/// Help popup box needs these three pieces of information
|
/// Help popup box needs these three pieces of information
|
||||||
struct HelpInfo {
|
struct HelpInfo {
|
||||||
spans: Vec<Spans<'static>>,
|
spans: Vec<Line<'static>>,
|
||||||
width: usize,
|
width: usize,
|
||||||
height: usize,
|
height: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HelpInfo {
|
impl HelpInfo {
|
||||||
/// Find the max width of a Span in &[Spans], although it isn't calculating it correctly
|
/// Find the max width of a Span in &[Line], although it isn't calculating it correctly
|
||||||
fn calc_width(spans: &[Spans]) -> usize {
|
fn calc_width(lines: &[Line]) -> usize {
|
||||||
spans
|
lines
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|x| x.0.iter())
|
.flat_map(|x| x.spans.iter())
|
||||||
.map(ratatui::text::Span::width)
|
.map(ratatui::text::Span::width)
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(1)
|
.unwrap_or(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Just an empty span, i.e. a new line
|
/// Just an empty span, i.e. a new line
|
||||||
fn empty_span<'a>() -> Spans<'a> {
|
fn empty_span<'a>() -> Line<'a> {
|
||||||
Spans::from(String::new())
|
Line::from(String::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// generate a span, of given &str and given color
|
/// generate a span, of given &str and given color
|
||||||
@@ -529,7 +529,7 @@ impl HelpInfo {
|
|||||||
fn gen_name() -> Self {
|
fn gen_name() -> Self {
|
||||||
let mut spans = NAME_TEXT
|
let mut spans = NAME_TEXT
|
||||||
.lines()
|
.lines()
|
||||||
.map(|i| Spans::from(Self::white_span(i)))
|
.map(|i| Line::from(Self::white_span(i)))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
spans.insert(0, Self::empty_span());
|
spans.insert(0, Self::empty_span());
|
||||||
let width = Self::calc_width(&spans);
|
let width = Self::calc_width(&spans);
|
||||||
@@ -545,7 +545,7 @@ impl HelpInfo {
|
|||||||
fn gen_description() -> Self {
|
fn gen_description() -> Self {
|
||||||
let spans = [
|
let spans = [
|
||||||
Self::empty_span(),
|
Self::empty_span(),
|
||||||
Spans::from(Self::white_span(DESCRIPTION)),
|
Line::from(Self::white_span(DESCRIPTION)),
|
||||||
Self::empty_span(),
|
Self::empty_span(),
|
||||||
];
|
];
|
||||||
let width = Self::calc_width(&spans);
|
let width = Self::calc_width(&spans);
|
||||||
@@ -565,14 +565,14 @@ impl HelpInfo {
|
|||||||
let space = || button_desc(" ");
|
let space = || button_desc(" ");
|
||||||
|
|
||||||
let spans = [
|
let spans = [
|
||||||
Spans::from(vec![
|
Line::from(vec![
|
||||||
space(),
|
space(),
|
||||||
button_item("tab"),
|
button_item("tab"),
|
||||||
or(),
|
or(),
|
||||||
button_item("shift+tab"),
|
button_item("shift+tab"),
|
||||||
button_desc("to change panels"),
|
button_desc("to change panels"),
|
||||||
]),
|
]),
|
||||||
Spans::from(vec![
|
Line::from(vec![
|
||||||
space(),
|
space(),
|
||||||
button_item("↑ ↓"),
|
button_item("↑ ↓"),
|
||||||
or(),
|
or(),
|
||||||
@@ -583,30 +583,30 @@ impl HelpInfo {
|
|||||||
button_item("Home End"),
|
button_item("Home End"),
|
||||||
button_desc("to change selected line"),
|
button_desc("to change selected line"),
|
||||||
]),
|
]),
|
||||||
Spans::from(vec![
|
Line::from(vec![
|
||||||
space(),
|
space(),
|
||||||
button_item("enter"),
|
button_item("enter"),
|
||||||
button_desc("to send docker container command"),
|
button_desc("to send docker container command"),
|
||||||
]),
|
]),
|
||||||
Spans::from(vec![
|
Line::from(vec![
|
||||||
space(),
|
space(),
|
||||||
button_item("h"),
|
button_item("h"),
|
||||||
button_desc("to toggle this help information"),
|
button_desc("to toggle this help information"),
|
||||||
]),
|
]),
|
||||||
Spans::from(vec![space(), button_item("0"), button_desc("to stop sort")]),
|
Line::from(vec![space(), button_item("0"), button_desc("to stop sort")]),
|
||||||
Spans::from(vec![
|
Line::from(vec![
|
||||||
space(),
|
space(),
|
||||||
button_item("1 - 9"),
|
button_item("1 - 9"),
|
||||||
button_desc("sort by header - or click header"),
|
button_desc("sort by header - or click header"),
|
||||||
]),
|
]),
|
||||||
Spans::from(vec![
|
Line::from(vec![
|
||||||
space(),
|
space(),
|
||||||
button_item("m"),
|
button_item("m"),
|
||||||
button_desc(
|
button_desc(
|
||||||
"to toggle mouse capture - if disabled, text on screen can be selected & copied",
|
"to toggle mouse capture - if disabled, text on screen can be selected & copied",
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
Spans::from(vec![
|
Line::from(vec![
|
||||||
space(),
|
space(),
|
||||||
button_item("q"),
|
button_item("q"),
|
||||||
button_desc("to quit at any time"),
|
button_desc("to quit at any time"),
|
||||||
@@ -626,10 +626,10 @@ impl HelpInfo {
|
|||||||
fn gen_final() -> Self {
|
fn gen_final() -> Self {
|
||||||
let spans = [
|
let spans = [
|
||||||
Self::empty_span(),
|
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",
|
"currently an early work in progress, all and any input appreciated",
|
||||||
)]),
|
)]),
|
||||||
Spans::from(vec![Span::styled(
|
Line::from(vec![Span::styled(
|
||||||
REPO.to_owned(),
|
REPO.to_owned(),
|
||||||
Style::default()
|
Style::default()
|
||||||
.fg(Color::White)
|
.fg(Color::White)
|
||||||
@@ -738,7 +738,7 @@ pub fn delete_confirm<B: Backend>(
|
|||||||
.title_alignment(Alignment::Center)
|
.title_alignment(Alignment::Center)
|
||||||
.borders(Borders::ALL);
|
.borders(Borders::ALL);
|
||||||
|
|
||||||
let confirm = Spans::from(vec![
|
let confirm = Line::from(vec![
|
||||||
Span::from("Are you sure you want to delete container: "),
|
Span::from("Are you sure you want to delete container: "),
|
||||||
Span::styled(
|
Span::styled(
|
||||||
name,
|
name,
|
||||||
|
|||||||
+1
-3
@@ -278,9 +278,7 @@ fn draw_frame<B: Backend>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if let Some(id) = delete_confirm {
|
if let Some(id) = delete_confirm {
|
||||||
let name = app_data.lock().get_container_name_by_id(&id);
|
app_data.lock().get_container_name_by_id(&id).map_or_else(|| {
|
||||||
name.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
|
// 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
|
// so if in that unique situation, just clear the delete_container id
|
||||||
gui_state.lock().set_delete_container(None);
|
gui_state.lock().set_delete_container(None);
|
||||||
|
|||||||
Reference in New Issue
Block a user