Skip to content

Commit

Permalink
chores: ratatui span -> lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed Jun 3, 2023
1 parent 4da1fb5 commit 0d37ac5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/ui/color_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod log_sanitizer {
text::{Span, Line},
};

/// Attempt to colorize the given string to tui-rs standards
/// Attempt to colorize the given string to ratatui standards
pub fn colorize_logs<'a>(input: &str) -> Vec<Line<'a>> {
vec![Line::from(
categorise_text(input)
Expand Down Expand Up @@ -39,15 +39,15 @@ 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 ratatui Lines
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
/// create ratatui Lines that exactly match the given strings
pub fn raw<'a>(input: &str) -> Vec<Line<'a>> {
vec![Line::from(Span::raw(input.to_owned()))]
}
Expand Down
44 changes: 22 additions & 22 deletions src/ui/draw_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub fn heading_bar<B: Backend>(

/// Help popup box needs these three pieces of information
struct HelpInfo {
spans: Vec<Line<'static>>,
lines: Vec<Line<'static>>,
width: usize,
height: usize,
}
Expand Down Expand Up @@ -527,31 +527,31 @@ impl HelpInfo {

/// Generate the `oxker` name span + metadata
fn gen_name() -> Self {
let mut spans = NAME_TEXT
let mut lines = NAME_TEXT
.lines()
.map(|i| Line::from(Self::white_span(i)))
.collect::<Vec<_>>();
spans.insert(0, Self::empty_span());
let width = Self::calc_width(&spans);
let height = spans.len();
lines.insert(0, Self::empty_span());
let width = Self::calc_width(&lines);
let height = lines.len();
Self {
spans,
lines,
width,
height,
}
}

/// Generate the description span + metadata
fn gen_description() -> Self {
let spans = [
let lines = [
Self::empty_span(),
Line::from(Self::white_span(DESCRIPTION)),
Self::empty_span(),
];
let width = Self::calc_width(&spans);
let height = spans.len();
let width = Self::calc_width(&lines);
let height = lines.len();
Self {
spans: spans.to_vec(),
lines: lines.to_vec(),
width,
height,
}
Expand All @@ -564,7 +564,7 @@ impl HelpInfo {
let or = || button_desc("or");
let space = || button_desc(" ");

let spans = [
let lines = [
Line::from(vec![
space(),
button_item("tab"),
Expand Down Expand Up @@ -613,18 +613,18 @@ impl HelpInfo {
]),
];

let height = spans.len();
let width = Self::calc_width(&spans);
let height = lines.len();
let width = Self::calc_width(&lines);
Self {
spans: spans.to_vec(),
lines: lines.to_vec(),
width,
height,
}
}

/// Generate the final lines, GitHub link etc, + metadata
fn gen_final() -> Self {
let spans = [
let lines = [
Self::empty_span(),
Line::from(vec![Self::black_span(
"currently an early work in progress, all and any input appreciated",
Expand All @@ -636,10 +636,10 @@ impl HelpInfo {
.add_modifier(Modifier::UNDERLINED),
)]),
];
let height = spans.len();
let width = Self::calc_width(&spans);
let height = lines.len();
let width = Self::calc_width(&lines);
Self {
spans: spans.to_vec(),
lines: lines.to_vec(),
width,
height,
}
Expand Down Expand Up @@ -689,22 +689,22 @@ pub fn help_box<B: Backend>(f: &mut Frame<'_, B>) {
)
.split(area);

let name_paragraph = Paragraph::new(name_info.spans)
let name_paragraph = Paragraph::new(name_info.lines)
.style(Style::default().bg(Color::Magenta).fg(Color::White))
.block(Block::default())
.alignment(Alignment::Center);

let description_paragraph = Paragraph::new(description_info.spans)
let description_paragraph = Paragraph::new(description_info.lines)
.style(Style::default().bg(Color::Magenta).fg(Color::Black))
.block(Block::default())
.alignment(Alignment::Center);

let help_paragraph = Paragraph::new(button_info.spans)
let help_paragraph = Paragraph::new(button_info.lines)
.style(Style::default().bg(Color::Magenta).fg(Color::Black))
.block(Block::default())
.alignment(Alignment::Left);

let final_paragraph = Paragraph::new(final_info.spans)
let final_paragraph = Paragraph::new(final_info.lines)
.style(Style::default().bg(Color::Magenta).fg(Color::Black))
.block(Block::default())
.alignment(Alignment::Center);
Expand Down

0 comments on commit 0d37ac5

Please sign in to comment.