Merge branch 'aljazerzen-left-align' into dev

This commit is contained in:
Jack Wills
2024-07-25 16:06:59 +00:00
2 changed files with 60 additions and 85 deletions
+5 -5
View File
@@ -669,14 +669,14 @@ impl Columns {
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
name: (Header::Name, 4), name: (Header::Name, 4),
state: (Header::State, 11), state: (Header::State, 5),
status: (Header::Status, 16), status: (Header::Status, 6),
cpu: (Header::Cpu, 7), cpu: (Header::Cpu, 3),
mem: (Header::Memory, 7, 7), mem: (Header::Memory, 7, 7),
id: (Header::Id, 8), id: (Header::Id, 8),
image: (Header::Image, 5), image: (Header::Image, 5),
net_rx: (Header::Rx, 7), net_rx: (Header::Rx, 4),
net_tx: (Header::Tx, 7), net_tx: (Header::Tx, 4),
} }
} }
} }
+55 -80
View File
@@ -146,7 +146,7 @@ fn format_containers<'a>(i: &ContainerItem, widths: &Columns) -> Line<'a> {
Line::from(vec![ Line::from(vec![
Span::styled( Span::styled(
format!( format!(
"{:>width$}", "{:<width$}{MARGIN}",
i.name.to_string(), i.name.to_string(),
width = widths.name.1.into() width = widths.name.1.into()
), ),
@@ -154,7 +154,7 @@ fn format_containers<'a>(i: &ContainerItem, widths: &Columns) -> Line<'a> {
), ),
Span::styled( Span::styled(
format!( format!(
"{MARGIN}{:<width$}", "{:<width$}{MARGIN}",
i.state.to_string(), i.state.to_string(),
width = widths.state.1.into() width = widths.state.1.into()
), ),
@@ -162,7 +162,7 @@ fn format_containers<'a>(i: &ContainerItem, widths: &Columns) -> Line<'a> {
), ),
Span::styled( Span::styled(
format!( format!(
"{MARGIN}{:>width$}", "{:<width$}{MARGIN}",
i.status, i.status,
width = &widths.status.1.into() width = &widths.status.1.into()
), ),
@@ -170,8 +170,7 @@ fn format_containers<'a>(i: &ContainerItem, widths: &Columns) -> Line<'a> {
), ),
Span::styled( Span::styled(
format!( format!(
"{}{:>width$}", "{:>width$}{MARGIN}",
MARGIN,
i.cpu_stats.back().unwrap_or(&CpuStats::default()), i.cpu_stats.back().unwrap_or(&CpuStats::default()),
width = &widths.cpu.1.into() width = &widths.cpu.1.into()
), ),
@@ -179,7 +178,7 @@ fn format_containers<'a>(i: &ContainerItem, widths: &Columns) -> Line<'a> {
), ),
Span::styled( Span::styled(
format!( format!(
"{MARGIN}{:>width_current$} / {:>width_limit$}", "{:>width_current$} / {:>width_limit$}{MARGIN}",
i.mem_stats.back().unwrap_or(&ByteStats::default()), i.mem_stats.back().unwrap_or(&ByteStats::default()),
i.mem_limit, i.mem_limit,
width_current = &widths.mem.1.into(), width_current = &widths.mem.1.into(),
@@ -189,8 +188,7 @@ fn format_containers<'a>(i: &ContainerItem, widths: &Columns) -> Line<'a> {
), ),
Span::styled( Span::styled(
format!( format!(
"{}{:>width$}", "{:>width$}{MARGIN}",
MARGIN,
i.id.get_short(), i.id.get_short(),
width = &widths.id.1.into() width = &widths.id.1.into()
), ),
@@ -198,18 +196,18 @@ fn format_containers<'a>(i: &ContainerItem, widths: &Columns) -> Line<'a> {
), ),
Span::styled( Span::styled(
format!( format!(
"{MARGIN}{:>width$}", "{:<width$}{MARGIN}",
i.image.to_string(), i.image.to_string(),
width = widths.image.1.into() width = widths.image.1.into()
), ),
blue, blue,
), ),
Span::styled( Span::styled(
format!("{MARGIN}{:>width$}", i.rx, width = widths.net_rx.1.into()), format!("{:>width$}{MARGIN}", i.rx, width = widths.net_rx.1.into()),
Style::default().fg(Color::Rgb(255, 233, 193)), Style::default().fg(Color::Rgb(255, 233, 193)),
), ),
Span::styled( Span::styled(
format!("{MARGIN}{:>width$}", i.tx, width = widths.net_tx.1.into()), format!("{:>width$}{MARGIN}", i.tx, width = widths.net_tx.1.into()),
Style::default().fg(Color::Rgb(205, 140, 140)), Style::default().fg(Color::Rgb(205, 140, 140)),
), ),
]) ])
@@ -506,54 +504,31 @@ pub fn heading_bar(
// Generate a block for the header, if the header is currently being used to sort a column, then highlight it white // Generate a block for the header, if the header is currently being used to sort a column, then highlight it white
let header_block = |x: &Header| { let header_block = |x: &Header| {
let mut color = Color::Black; let mut color = Color::Black;
let mut prefix = ""; let mut suffix = "";
let mut prefix_margin = 0;
if let Some((a, b)) = &data.sorted_by { if let Some((a, b)) = &data.sorted_by {
if x == a { if x == a {
match b { match b {
SortedOrder::Asc => prefix = " ", SortedOrder::Asc => suffix = " ",
SortedOrder::Desc => prefix = " ", SortedOrder::Desc => suffix = " ",
} }
prefix_margin = 2; color = Color::Gray;
color = Color::White;
}; };
}; };
(
Block::default().style(Style::default().bg(Color::Magenta).fg(color)), (Block::default().style(Style::default().fg(color)), suffix)
prefix,
prefix_margin,
)
}; };
// Generate block for the headers, state and status has a specific layout, others all equal // Generate block for the headers, state and status has a specific layout, others all equal
// width is dependant on it that column is selected to sort - or not // width is dependant on it that column is selected to sort - or not
let gen_header = |header: &Header, width: usize| { let gen_header = |header: &Header, width: usize| {
let block = header_block(header); let block = header_block(header);
// Yes this is a mess, needs documenting correctly // Yes this is a mess, needs documenting correctly
let text = match header {
Header::State => format!( let text = format!(
" {x:>width$}", "{x:<width$}{MARGIN}",
x = format!("{ic}{header}", ic = block.1), x = format!("{header}{ic}", ic = block.1),
width = width );
),
Header::Name => format!(
" {x:>width$}",
x = format!("{ic}{header}", ic = block.1),
width = width
),
Header::Status => format!(
"{} {x:>width$}",
MARGIN,
x = format!("{ic}{header}", ic = block.1),
width = width
),
_ => format!(
"{}{x:>width$}",
MARGIN,
x = format!("{ic}{header}", ic = block.1),
width = width
),
};
let count = u16::try_from(text.chars().count()).unwrap_or_default(); 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)
@@ -584,7 +559,7 @@ pub fn heading_bar(
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 data.has_containers { let splits = if data.has_containers {
vec![ vec![
Constraint::Max(2), Constraint::Max(4),
Constraint::Min(column_width.try_into().unwrap_or_default()), Constraint::Min(column_width.try_into().unwrap_or_default()),
Constraint::Max(info_width.try_into().unwrap_or_default()), Constraint::Max(info_width.try_into().unwrap_or_default()),
] ]
@@ -1485,9 +1460,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 ✓ running Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 ✓ running Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1554,9 +1529,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 ✓ running Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 ✓ running Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1613,9 +1588,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ a_long_container_name_for_the… ॥ paused Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 a_long_image_name_for_the_pur… 0.00 kB 0.00 kB │", "│⚪ a_long_container_name_for_the… ॥ paused Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 a_long_image_name_for_the_pur… 0.00 kB 0.00 kB │",
"container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1645,9 +1620,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 ॥ paused Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 ॥ paused Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1672,9 +1647,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 ✖ dead Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 ✖ dead Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1698,9 +1673,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 ✖ exited Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 ✖ exited Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1724,9 +1699,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 removing Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 removing Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1751,9 +1726,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 ↻ restarting Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 ↻ restarting Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -1812,9 +1787,9 @@ mod tests {
let expected = [ let expected = [
"╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│⚪ container_1 ? unknown Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│⚪ container_1 ? unknown Up 1 hour 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │",
"│ │", "│ │",
"╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
]; ];
@@ -3292,9 +3267,9 @@ mod tests {
let expected = [ let expected = [
" name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", " name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ",
"╭ Containers 1/3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭──────────────╮", "╭ Containers 1/3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭──────────────╮",
"│⚪ container_1 ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 image_1 0.00 kB 0.00 kB ││▶ pause │", "│⚪ container_1 ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 image_1 0.00 kB 0.00 kB ││▶ pause │",
"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │",
"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB ││ stop │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB ││ stop │",
"│ ││ delete │", "│ ││ delete │",
"│ ││ │", "│ ││ │",
"│ ││ │", "│ ││ │",
@@ -3478,9 +3453,9 @@ mod tests {
let expected = [ let expected = [
" name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", " name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ",
"╭ Containers 1/3 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭─────────────────╮", "╭ Containers 1/3 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭─────────────────╮",
"│⚪ a_long_container_name_for_the… ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 a_long_image_name_for_the_pur… 0.00 kB 0.00 kB ││▶ pause │", "│⚪ a_long_container_name_for_the… ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 a_long_image_name_for_the_pur… 0.00 kB 0.00 kB ││▶ pause │",
"container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │", "container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │",
"container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB ││ stop │", "container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB ││ stop │",
"│ ││ delete │", "│ ││ delete │",
"│ ││ │", "│ ││ │",
"│ ││ │", "│ ││ │",