Skip to content

Commit

Permalink
refactor: optional use minimal widths function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kek5chen committed Jun 10, 2024
1 parent e5329ae commit 8f94bb5
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions vickyctl/src/tui/lock_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,32 @@ where
.map_or(0, |len| u16::try_from(len).unwrap_or(u16::MAX))
}

// This will not make the table equally spaced, but instead use minimal space.
#[allow(dead_code)]
fn minimal_widths(locks: &[PoisonedLock]) -> [Constraint; 4] {

[
Constraint::Max(get_longest_len(locks.iter().map(|l| l.name()))),
Constraint::Max(5),
Constraint::Max(get_longest_len(
locks
.iter()
.map(|l| l.get_poisoned_by().display_name.as_str()),
).max("Failed Task Name".len() as u16)),
Constraint::Min(get_longest_len(
locks
.iter()
.map(|l| l.get_poisoned_by().flake_ref.flake.as_str()),
).max("Task Flake URI".len() as u16)),
]
}

fn draw_task_picker(f: &mut Frame, locks: &[PoisonedLock], state: &mut TableState) {
let rows: Vec<Row> = locks.iter().map(|l| l.into()).collect();

// let _widths: [Constraint; 4] = [
// Constraint::Max(get_longest_len(locks.iter().map(|l| l.name()))),
// Constraint::Max(5),
// Constraint::Max(get_longest_len(
// locks
// .iter()
// .map(|l| l.get_poisoned_by().display_name.as_str()),
// ).max("Failed Task Name".len() as u16)),
// Constraint::Min(get_longest_len(
// locks
// .iter()
// .map(|l| l.get_poisoned_by().flake_ref.flake.as_str()),
// ).max("Task Flake URI".len() as u16)),
// ]; // This will not make the table equally spaced, but instead use minimal space. Just keeping this since I don't wanna rewrite it.
let table = Table::new(rows, &[])
// let widths = minimal_widths(locks);
let widths = &[];
let table = Table::new(rows, widths)
.block(
Block::default()
.title("Manually Resolve Locks")
Expand Down

0 comments on commit 8f94bb5

Please sign in to comment.