chore: linting pedantic
This commit is contained in:
@@ -7,9 +7,9 @@ pub mod log_sanitizer {
|
||||
};
|
||||
|
||||
/// Attempt to colorize the given string to tui-rs standars
|
||||
pub fn colorize_logs(input: String) -> Vec<Spans<'static>> {
|
||||
pub fn colorize_logs(input: &str) -> Vec<Spans<'static>> {
|
||||
vec![Spans::from(
|
||||
categorise_text(&input)
|
||||
categorise_text(input)
|
||||
.into_iter()
|
||||
.map(|i| {
|
||||
let fg_color = color_ansi_to_tui(i.fg.unwrap_or(CansiColor::White));
|
||||
@@ -40,10 +40,10 @@ pub mod log_sanitizer {
|
||||
}
|
||||
|
||||
/// Remove all ansi formatting from a given string and create tui-rs spans
|
||||
pub fn remove_ansi(input: String) -> Vec<Spans<'static>> {
|
||||
pub fn remove_ansi(input: &str) -> Vec<Spans<'static>> {
|
||||
let mut output = String::from("");
|
||||
for i in categorise_text(&input) {
|
||||
output.push_str(i.text)
|
||||
for i in categorise_text(input) {
|
||||
output.push_str(i.text);
|
||||
}
|
||||
raw(output)
|
||||
}
|
||||
@@ -56,22 +56,20 @@ pub mod log_sanitizer {
|
||||
/// Change from ansi to tui colors
|
||||
fn color_ansi_to_tui(color: CansiColor) -> Color {
|
||||
match color {
|
||||
CansiColor::Black => Color::Black,
|
||||
CansiColor::Black | CansiColor::BrightBlack => Color::Black,
|
||||
CansiColor::Red => Color::Red,
|
||||
CansiColor::Green => Color::Green,
|
||||
CansiColor::Yellow => Color::Yellow,
|
||||
CansiColor::Blue => Color::Blue,
|
||||
CansiColor::Magenta => Color::Magenta,
|
||||
CansiColor::Cyan => Color::Cyan,
|
||||
CansiColor::White => Color::White,
|
||||
CansiColor::BrightBlack => Color::Black,
|
||||
CansiColor::White | CansiColor::BrightWhite => Color::White,
|
||||
CansiColor::BrightRed => Color::LightRed,
|
||||
CansiColor::BrightGreen => Color::LightGreen,
|
||||
CansiColor::BrightYellow => Color::LightYellow,
|
||||
CansiColor::BrightBlue => Color::LightBlue,
|
||||
CansiColor::BrightMagenta => Color::LightMagenta,
|
||||
CansiColor::BrightCyan => Color::LightCyan,
|
||||
CansiColor::BrightWhite => Color::White,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
-38
@@ -64,7 +64,7 @@ fn generate_block<'a>(
|
||||
SelectablePanel::Logs => {
|
||||
format!(" {} {} ", panel.title(), app_data.lock().get_log_title())
|
||||
}
|
||||
_ => String::from(""),
|
||||
SelectablePanel::Commands => String::from(""),
|
||||
};
|
||||
block = block.title(title);
|
||||
if current_selected_panel == panel {
|
||||
@@ -74,7 +74,7 @@ fn generate_block<'a>(
|
||||
}
|
||||
|
||||
/// Draw the command panel
|
||||
pub fn draw_commands<B: Backend>(
|
||||
pub fn commands<B: Backend>(
|
||||
app_data: &Arc<Mutex<AppData>>,
|
||||
area: Rect,
|
||||
f: &mut Frame<'_, B>,
|
||||
@@ -111,12 +111,12 @@ pub fn draw_commands<B: Backend>(
|
||||
let paragraph = Paragraph::new(debug_text)
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area)
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the containers panel
|
||||
pub fn draw_containers<B: Backend>(
|
||||
pub fn containers<B: Backend>(
|
||||
app_data: &Arc<Mutex<AppData>>,
|
||||
area: Rect,
|
||||
f: &mut Frame<'_, B>,
|
||||
@@ -196,7 +196,7 @@ pub fn draw_containers<B: Backend>(
|
||||
let paragraph = Paragraph::new(debug_text)
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area)
|
||||
f.render_widget(paragraph, area);
|
||||
} else {
|
||||
let items = List::new(items)
|
||||
.block(block)
|
||||
@@ -208,13 +208,13 @@ pub fn draw_containers<B: Backend>(
|
||||
}
|
||||
|
||||
/// Draw the logs panel
|
||||
pub fn draw_logs<B: Backend>(
|
||||
pub fn logs<B: Backend>(
|
||||
app_data: &Arc<Mutex<AppData>>,
|
||||
area: Rect,
|
||||
f: &mut Frame<'_, B>,
|
||||
gui_state: &Arc<Mutex<GuiState>>,
|
||||
index: Option<usize>,
|
||||
loading_icon: String,
|
||||
loading_icon: &str,
|
||||
) {
|
||||
let block = generate_block(app_data, area, gui_state, SelectablePanel::Logs);
|
||||
|
||||
@@ -225,14 +225,14 @@ pub fn draw_logs<B: Backend>(
|
||||
.style(Style::default())
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area)
|
||||
f.render_widget(paragraph, area);
|
||||
} else if let Some(index) = index {
|
||||
let items = app_data.lock().containers.items[index]
|
||||
.logs
|
||||
.items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|i| i.1.to_owned())
|
||||
.map(|i| i.1.clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let items = List::new(items)
|
||||
@@ -249,12 +249,12 @@ pub fn draw_logs<B: Backend>(
|
||||
let paragraph = Paragraph::new(debug_text)
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area)
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the cpu + mem charts
|
||||
pub fn draw_chart<B: Backend>(
|
||||
pub fn chart<B: Backend>(
|
||||
f: &mut Frame<'_, B>,
|
||||
area: Rect,
|
||||
app_data: &Arc<Mutex<AppData>>,
|
||||
@@ -279,19 +279,21 @@ pub fn draw_chart<B: Backend>(
|
||||
.style(Style::default().fg(Color::Cyan))
|
||||
.graph_type(GraphType::Line)
|
||||
.data(&mem.0)];
|
||||
let cpu_stats = CpuStats::new(cpu.0.last().unwrap_or(&(0.00, 0.00)).1);
|
||||
let mem_stats = ByteStats::new(mem.0.last().unwrap_or(&(0.0, 0.0)).1 as u64);
|
||||
let cpu_chart = make_chart(
|
||||
cpu.2,
|
||||
String::from("cpu"),
|
||||
&cpu.2,
|
||||
"cpu",
|
||||
cpu_dataset,
|
||||
CpuStats::new(cpu.0.last().unwrap_or(&(0.00, 0.00)).1),
|
||||
cpu.1,
|
||||
&cpu_stats,
|
||||
&cpu.1,
|
||||
);
|
||||
let mem_chart = make_chart(
|
||||
mem.2,
|
||||
String::from("memory"),
|
||||
&mem.2,
|
||||
"memory",
|
||||
mem_dataset,
|
||||
ByteStats::new(mem.0.last().unwrap_or(&(0.0, 0.0)).1 as u64),
|
||||
mem.1,
|
||||
&mem_stats,
|
||||
&mem.1,
|
||||
);
|
||||
|
||||
f.render_widget(cpu_chart, area[0]);
|
||||
@@ -301,13 +303,13 @@ pub fn draw_chart<B: Backend>(
|
||||
}
|
||||
|
||||
/// Create charts
|
||||
fn make_chart<T: Stats + Display>(
|
||||
state: State,
|
||||
name: String,
|
||||
dataset: Vec<Dataset>,
|
||||
current: T,
|
||||
max: T,
|
||||
) -> Chart {
|
||||
fn make_chart<'a, T: Stats + Display>(
|
||||
state: &State,
|
||||
name: &'a str,
|
||||
dataset: Vec<Dataset<'a>>,
|
||||
current: &'a T,
|
||||
max: &'a T,
|
||||
) -> Chart<'a> {
|
||||
let title_color = match state {
|
||||
State::Running => Color::Green,
|
||||
_ => state.get_color(),
|
||||
@@ -351,13 +353,13 @@ fn make_chart<T: Stats + Display>(
|
||||
}
|
||||
|
||||
/// Draw heading bar at top of program, always visible
|
||||
pub fn draw_heading_bar<B: Backend>(
|
||||
pub fn heading_bar<B: Backend>(
|
||||
area: Rect,
|
||||
columns: &Columns,
|
||||
f: &mut Frame<'_, B>,
|
||||
has_containers: bool,
|
||||
loading_icon: String,
|
||||
sorted_by: Option<(Header, SortedOrder)>,
|
||||
loading_icon: &str,
|
||||
sorted_by: &Option<(Header, SortedOrder)>,
|
||||
gui_state: &Arc<Mutex<GuiState>>,
|
||||
) {
|
||||
let block = || Block::default().style(Style::default().bg(Color::Magenta).fg(Color::Black));
|
||||
@@ -377,7 +379,7 @@ pub fn draw_heading_bar<B: Backend>(
|
||||
SortedOrder::Desc => suffix = " ⌄",
|
||||
}
|
||||
suffix_margin = 2;
|
||||
color = Color::White
|
||||
color = Color::White;
|
||||
};
|
||||
};
|
||||
(
|
||||
@@ -441,7 +443,7 @@ pub fn draw_heading_bar<B: Backend>(
|
||||
let header_block = gen_header(&i.0, i.1);
|
||||
(
|
||||
header_block.0,
|
||||
i.0.to_owned(),
|
||||
i.0.clone(),
|
||||
Constraint::Max(header_block.1),
|
||||
)
|
||||
})
|
||||
@@ -500,7 +502,7 @@ fn max_line_width(text: &str) -> usize {
|
||||
}
|
||||
|
||||
/// Draw the help box in the centre of the screen
|
||||
pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
||||
pub fn help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
||||
let title = format!(" {} ", VERSION);
|
||||
|
||||
let description_text = format!("\n{}", DESCRIPTION);
|
||||
@@ -550,7 +552,7 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(Color::Black));
|
||||
|
||||
let area = draw_popup(
|
||||
let area = popup(
|
||||
lines as u16,
|
||||
max_line_width as u16,
|
||||
f.size(),
|
||||
@@ -578,7 +580,7 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
||||
}
|
||||
|
||||
/// Draw an error popup over whole screen
|
||||
pub fn draw_error<B: Backend>(f: &mut Frame<'_, B>, error: AppError, seconds: Option<u8>) {
|
||||
pub fn error<B: Backend>(f: &mut Frame<'_, B>, error: &AppError, seconds: Option<u8>) {
|
||||
let block = Block::default()
|
||||
.title(" Error ")
|
||||
.border_type(BorderType::Rounded)
|
||||
@@ -614,7 +616,7 @@ pub fn draw_error<B: Backend>(f: &mut Frame<'_, B>, error: AppError, seconds: Op
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
let area = draw_popup(
|
||||
let area = popup(
|
||||
lines as u16,
|
||||
max_line_width as u16,
|
||||
f.size(),
|
||||
@@ -625,7 +627,7 @@ pub fn draw_error<B: Backend>(f: &mut Frame<'_, B>, error: AppError, seconds: Op
|
||||
}
|
||||
|
||||
/// Draw info box in one of the 9 BoxLocations
|
||||
pub fn draw_info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
|
||||
pub fn info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
|
||||
let block = Block::default()
|
||||
.title("")
|
||||
.title_alignment(Alignment::Center)
|
||||
@@ -643,7 +645,7 @@ pub fn draw_info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
let area = draw_popup(
|
||||
let area = popup(
|
||||
lines as u16,
|
||||
max_line_width as u16,
|
||||
f.size(),
|
||||
@@ -654,7 +656,7 @@ pub fn draw_info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
|
||||
}
|
||||
|
||||
/// draw a box in the one of the BoxLocations, based on max line width + number of lines
|
||||
fn draw_popup(text_lines: u16, text_width: u16, r: Rect, box_location: BoxLocation) -> Rect {
|
||||
fn popup(text_lines: u16, text_width: u16, r: Rect, box_location: BoxLocation) -> Rect {
|
||||
// Make sure blank_space can't be an negative, as will crash
|
||||
let blank_vertical = if r.height > text_lines {
|
||||
(r.height - text_lines) / 2
|
||||
|
||||
+5
-5
@@ -30,7 +30,7 @@ pub enum BoxLocation {
|
||||
}
|
||||
|
||||
impl BoxLocation {
|
||||
pub fn get_indexes(&self) -> (usize, usize) {
|
||||
pub fn get_indexes(self) -> (usize, usize) {
|
||||
match self {
|
||||
Self::TopLeft => (0, 0),
|
||||
Self::TopCentre => (0, 1),
|
||||
@@ -46,7 +46,7 @@ impl BoxLocation {
|
||||
|
||||
// Should combine and just return a tuple?
|
||||
pub fn get_horizontal_constraints(
|
||||
&self,
|
||||
self,
|
||||
blank_vertical: u16,
|
||||
text_width: u16,
|
||||
) -> [Constraint; 3] {
|
||||
@@ -69,7 +69,7 @@ impl BoxLocation {
|
||||
}
|
||||
}
|
||||
pub fn get_vertical_constraints(
|
||||
&self,
|
||||
self,
|
||||
blank_vertical: u16,
|
||||
number_lines: u16,
|
||||
) -> [Constraint; 3] {
|
||||
@@ -147,7 +147,7 @@ impl SelectablePanel {
|
||||
match self {
|
||||
Self::Containers => "Containers",
|
||||
Self::Logs => "Logs",
|
||||
_ => "",
|
||||
Self::Commands => "",
|
||||
}
|
||||
}
|
||||
pub fn next(self) -> Self {
|
||||
@@ -221,7 +221,7 @@ impl GuiState {
|
||||
.filter(|i| i.1.intersects(rect))
|
||||
.collect::<Vec<_>>()
|
||||
.get(0)
|
||||
.map(|data| data.0.to_owned())
|
||||
.map(|data| data.0.clone())
|
||||
}
|
||||
|
||||
/// Insert, or updatem header area panel into heading_map
|
||||
|
||||
+13
-14
@@ -30,7 +30,6 @@ use crate::{
|
||||
app_data::AppData, app_error::AppError, docker_data::DockerMessage,
|
||||
input_handler::InputMessages,
|
||||
};
|
||||
use draw_blocks::*;
|
||||
|
||||
/// Take control of the terminal in order to draw gui
|
||||
pub async fn create_ui(
|
||||
@@ -95,7 +94,7 @@ async fn run_app<B: Backend>(
|
||||
break;
|
||||
}
|
||||
if terminal
|
||||
.draw(|f| draw_error(f, AppError::DockerConnect, Some(seconds)))
|
||||
.draw(|f| draw_blocks::error(f, &AppError::DockerConnect, Some(seconds)))
|
||||
.is_err()
|
||||
{
|
||||
return Err(AppError::Terminal);
|
||||
@@ -152,7 +151,7 @@ fn ui<B: Backend>(
|
||||
if height < 12 {
|
||||
height += 4;
|
||||
} else {
|
||||
height = 12
|
||||
height = 12;
|
||||
}
|
||||
|
||||
let column_widths = app_data.lock().get_width();
|
||||
@@ -199,47 +198,47 @@ fn ui<B: Backend>(
|
||||
.constraints(lower_split.as_ref())
|
||||
.split(upper_main[1]);
|
||||
|
||||
draw_containers(app_data, top_panel[0], f, gui_state, &column_widths);
|
||||
draw_blocks::containers(app_data, top_panel[0], f, gui_state, &column_widths);
|
||||
|
||||
if has_containers {
|
||||
draw_commands(app_data, top_panel[1], f, gui_state, log_index);
|
||||
draw_blocks::commands(app_data, top_panel[1], f, gui_state, log_index);
|
||||
}
|
||||
|
||||
draw_logs(
|
||||
draw_blocks::logs(
|
||||
app_data,
|
||||
lower_main[0],
|
||||
f,
|
||||
gui_state,
|
||||
log_index,
|
||||
loading_icon.to_owned(),
|
||||
&loading_icon,
|
||||
);
|
||||
|
||||
draw_heading_bar(
|
||||
draw_blocks::heading_bar(
|
||||
whole_layout[0],
|
||||
&column_widths,
|
||||
f,
|
||||
has_containers,
|
||||
loading_icon,
|
||||
sorted_by,
|
||||
&loading_icon,
|
||||
&sorted_by,
|
||||
gui_state,
|
||||
);
|
||||
|
||||
// only draw charts if there are containers
|
||||
if has_containers {
|
||||
draw_chart(f, lower_main[1], app_data, log_index);
|
||||
draw_blocks::chart(f, lower_main[1], app_data, log_index);
|
||||
}
|
||||
|
||||
if let Some(info) = info_text {
|
||||
draw_info(f, info);
|
||||
draw_blocks::info(f, info);
|
||||
}
|
||||
|
||||
// Check if error, and show popup if so
|
||||
if show_help {
|
||||
draw_help_box(f);
|
||||
draw_blocks::help_box(f);
|
||||
}
|
||||
|
||||
if let Some(error) = has_error {
|
||||
app_data.lock().show_error = true;
|
||||
draw_error(f, error, None);
|
||||
draw_blocks::error(f, &error, None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user