fix: u16::try_from for text widths
This commit is contained in:
@@ -4,6 +4,7 @@ use clap::Parser;
|
|||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
#[derive(Parser, Debug, Clone, Copy)]
|
#[derive(Parser, Debug, Clone, Copy)]
|
||||||
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
// #[command(help_template = FULL_TEMPLATE)]
|
// #[command(help_template = FULL_TEMPLATE)]
|
||||||
#[command(version, about)]
|
#[command(version, about)]
|
||||||
pub struct CliArgs {
|
pub struct CliArgs {
|
||||||
|
|||||||
+22
-21
@@ -168,7 +168,7 @@ pub fn containers<B: Backend>(
|
|||||||
format!(
|
format!(
|
||||||
"{}{:>width$}",
|
"{}{:>width$}",
|
||||||
MARGIN,
|
MARGIN,
|
||||||
i.id.chars().take(8).collect::<String>(),
|
i.id.get().chars().take(8).collect::<String>(),
|
||||||
width = &widths.id.1
|
width = &widths.id.1
|
||||||
),
|
),
|
||||||
blue,
|
blue,
|
||||||
@@ -343,6 +343,7 @@ fn make_chart<'a, T: Stats + Display>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Draw heading bar at top of program, always visible
|
/// Draw heading bar at top of program, always visible
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn heading_bar<B: Backend>(
|
pub fn heading_bar<B: Backend>(
|
||||||
area: Rect,
|
area: Rect,
|
||||||
columns: &Columns,
|
columns: &Columns,
|
||||||
@@ -407,7 +408,7 @@ pub fn heading_bar<B: Backend>(
|
|||||||
width = width - block.2
|
width = width - block.2
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
let count = text.chars().count() as u16;
|
let count = u16::try_from(text.chars().count()).unwrap_or_default();
|
||||||
let status = Paragraph::new(text)
|
let status = Paragraph::new(text)
|
||||||
.block(block.0)
|
.block(block.0)
|
||||||
.alignment(Alignment::Left);
|
.alignment(Alignment::Left);
|
||||||
@@ -437,12 +438,12 @@ pub fn heading_bar<B: Backend>(
|
|||||||
|
|
||||||
let suffix = if info_visible { "exit" } else { "show" };
|
let suffix = if info_visible { "exit" } else { "show" };
|
||||||
let info_text = format!("( h ) {} help {}", suffix, MARGIN);
|
let info_text = format!("( h ) {} help {}", suffix, MARGIN);
|
||||||
let info_width = info_text.chars().count() as u16;
|
let info_width = info_text.chars().count();
|
||||||
|
|
||||||
let column_width = area.width - info_width;
|
let column_width = usize::from(area.width) - info_width;
|
||||||
let column_width = if column_width > 0 { column_width } else { 1 };
|
let column_width = if column_width > 0 { column_width } else { 1 };
|
||||||
let splits = if has_containers {
|
let splits = if has_containers {
|
||||||
vec![Constraint::Min(column_width), Constraint::Min(info_width)]
|
vec![Constraint::Min(column_width.try_into().unwrap_or_default()), Constraint::Min(info_width.try_into().unwrap_or_default())]
|
||||||
} else {
|
} else {
|
||||||
vec![Constraint::Percentage(100)]
|
vec![Constraint::Percentage(100)]
|
||||||
};
|
};
|
||||||
@@ -541,8 +542,8 @@ pub fn help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
|||||||
.border_style(Style::default().fg(Color::Black));
|
.border_style(Style::default().fg(Color::Black));
|
||||||
|
|
||||||
let area = popup(
|
let area = popup(
|
||||||
lines as u16,
|
lines,
|
||||||
max_line_width as u16,
|
max_line_width,
|
||||||
f.size(),
|
f.size(),
|
||||||
BoxLocation::MiddleCentre,
|
BoxLocation::MiddleCentre,
|
||||||
);
|
);
|
||||||
@@ -551,9 +552,9 @@ pub fn help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
|||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(
|
.constraints(
|
||||||
[
|
[
|
||||||
Constraint::Max(NAME_TEXT.lines().count() as u16),
|
Constraint::Max(NAME_TEXT.lines().count().try_into().unwrap_or_default()),
|
||||||
Constraint::Max(description_text.lines().count() as u16),
|
Constraint::Max(description_text.lines().count().try_into().unwrap_or_default()),
|
||||||
Constraint::Max(help_text.lines().count() as u16),
|
Constraint::Max(help_text.lines().count().try_into().unwrap_or_default()),
|
||||||
]
|
]
|
||||||
.as_ref(),
|
.as_ref(),
|
||||||
)
|
)
|
||||||
@@ -605,8 +606,8 @@ pub fn error<B: Backend>(f: &mut Frame<'_, B>, error: AppError, seconds: Option<
|
|||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center);
|
||||||
|
|
||||||
let area = popup(
|
let area = popup(
|
||||||
lines as u16,
|
lines,
|
||||||
max_line_width as u16,
|
max_line_width,
|
||||||
f.size(),
|
f.size(),
|
||||||
BoxLocation::MiddleCentre,
|
BoxLocation::MiddleCentre,
|
||||||
);
|
);
|
||||||
@@ -634,8 +635,8 @@ pub fn info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
|
|||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center);
|
||||||
|
|
||||||
let area = popup(
|
let area = popup(
|
||||||
lines as u16,
|
lines,
|
||||||
max_line_width as u16,
|
max_line_width,
|
||||||
f.size(),
|
f.size(),
|
||||||
BoxLocation::BottomRight,
|
BoxLocation::BottomRight,
|
||||||
);
|
);
|
||||||
@@ -644,21 +645,21 @@ pub fn 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
|
/// draw a box in the one of the BoxLocations, based on max line width + number of lines
|
||||||
fn popup(text_lines: u16, text_width: u16, r: Rect, box_location: BoxLocation) -> Rect {
|
fn popup(text_lines: usize, text_width: usize, r: Rect, box_location: BoxLocation) -> Rect {
|
||||||
// Make sure blank_space can't be an negative, as will crash
|
// Make sure blank_space can't be an negative, as will crash
|
||||||
let blank_vertical = if r.height > text_lines {
|
let blank_vertical = if usize::from(r.height) > text_lines {
|
||||||
(r.height - text_lines) / 2
|
(usize::from(r.height) - text_lines) / 2
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
let blank_horizontal = if r.width > text_width {
|
let blank_horizontal = if usize::from(r.width) > text_width {
|
||||||
(r.width - text_width) / 2
|
(usize::from(r.width) - text_width) / 2
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
let v_constraints = box_location.get_vertical_constraints(blank_vertical, text_lines);
|
let v_constraints = box_location.get_vertical_constraints(blank_vertical.try_into().unwrap_or_default(), text_lines.try_into().unwrap_or_default());
|
||||||
let h_constraints = box_location.get_horizontal_constraints(blank_horizontal, text_width);
|
let h_constraints = box_location.get_horizontal_constraints(blank_horizontal.try_into().unwrap_or_default(), text_width.try_into().unwrap_or_default());
|
||||||
|
|
||||||
let indexes = box_location.get_indexes();
|
let indexes = box_location.get_indexes();
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -148,7 +148,7 @@ fn ui<B: Backend>(
|
|||||||
) {
|
) {
|
||||||
// set max height for container section, needs +4 to deal with docker commands list and borders
|
// set max height for container section, needs +4 to deal with docker commands list and borders
|
||||||
let height = app_data.lock().get_container_len();
|
let height = app_data.lock().get_container_len();
|
||||||
let height = if height < 12 { (height + 4) as u16 } else { 12 };
|
let height = if height < 12 { height + 4 } else { 12 };
|
||||||
|
|
||||||
let column_widths = app_data.lock().get_width();
|
let column_widths = app_data.lock().get_width();
|
||||||
let has_containers = !app_data.lock().containers.items.is_empty();
|
let has_containers = !app_data.lock().containers.items.is_empty();
|
||||||
@@ -168,7 +168,7 @@ fn ui<B: Backend>(
|
|||||||
// Split into 3, containers+controls, logs, then graphs
|
// Split into 3, containers+controls, logs, then graphs
|
||||||
let upper_main = Layout::default()
|
let upper_main = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([Constraint::Max(height as u16), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Max(height.try_into().unwrap_or_default()), Constraint::Percentage(50)].as_ref())
|
||||||
.split(whole_layout[1]);
|
.split(whole_layout[1]);
|
||||||
|
|
||||||
let top_split = if has_containers {
|
let top_split = if has_containers {
|
||||||
|
|||||||
Reference in New Issue
Block a user