mirror of
https://git.meli.delivery/meli/meli
synced 2024-11-15 06:12:47 +00:00
ui: remove unnecessary unreachable panics in set_and_join_box
This commit is contained in:
parent
bc98a0ef48
commit
af4c5792b3
@ -107,22 +107,6 @@ pub trait Component: Display + Debug + Send {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
pub(crate) fn is_box_char(ch: char) -> bool {
|
|
||||||
match ch {
|
|
||||||
HORZ_BOUNDARY | VERT_BOUNDARY => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
* pub(crate) fn is_box_char(ch: char) -> bool {
|
|
||||||
* match ch {
|
|
||||||
* '└' | '─' | '┘' | '┴' | '┌' | '│' | '├' | '┐' | '┬' | '┤' | '┼' | '╷' | '╵' | '╴' | '╶' => true,
|
|
||||||
* _ => false,
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
fn bin_to_ch(b: u32) -> char {
|
fn bin_to_ch(b: u32) -> char {
|
||||||
match b {
|
match b {
|
||||||
0b0001 => '╶',
|
0b0001 => '╶',
|
||||||
@ -140,7 +124,7 @@ fn bin_to_ch(b: u32) -> char {
|
|||||||
0b1101 => '┬',
|
0b1101 => '┬',
|
||||||
0b1110 => '┤',
|
0b1110 => '┤',
|
||||||
0b1111 => '┼',
|
0b1111 => '┼',
|
||||||
x => unreachable!(format!("unreachable bin_to_ch(x), x = {:b}", x)),
|
_ => unsafe { std::hint::unreachable_unchecked() },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +347,12 @@ fn set_and_join_horz(grid: &mut CellBuffer, idx: Pos) -> u32 {
|
|||||||
bin_set
|
bin_set
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: char) {
|
pub enum BoxBoundary {
|
||||||
|
Horizontal,
|
||||||
|
Vertical,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: BoxBoundary) {
|
||||||
/* Connected sides:
|
/* Connected sides:
|
||||||
*
|
*
|
||||||
* 1
|
* 1
|
||||||
@ -376,9 +365,8 @@ pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: char) {
|
|||||||
|
|
||||||
if grid.ascii_drawing {
|
if grid.ascii_drawing {
|
||||||
grid[idx].set_ch(match ch {
|
grid[idx].set_ch(match ch {
|
||||||
'│' => '|',
|
BoxBoundary::Vertical => '|',
|
||||||
'─' => '-',
|
BoxBoundary::Horizontal => '-',
|
||||||
_ => unreachable!(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
grid[idx].set_fg(Color::Byte(240));
|
grid[idx].set_fg(Color::Byte(240));
|
||||||
@ -386,9 +374,8 @@ pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: char) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let bin_set = match ch {
|
let bin_set = match ch {
|
||||||
'│' => set_and_join_vert(grid, idx),
|
BoxBoundary::Vertical => set_and_join_vert(grid, idx),
|
||||||
'─' => set_and_join_horz(grid, idx),
|
BoxBoundary::Horizontal => set_and_join_horz(grid, idx),
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
grid[idx].set_ch(bin_to_ch(bin_set));
|
grid[idx].set_ch(bin_to_ch(bin_set));
|
||||||
@ -414,9 +401,17 @@ pub fn create_box(grid: &mut CellBuffer, area: Area) {
|
|||||||
grid[(get_x(bottom_right), y)].set_ch(VERT_BOUNDARY);
|
grid[(get_x(bottom_right), y)].set_ch(VERT_BOUNDARY);
|
||||||
grid[(get_x(bottom_right), y)].set_fg(Color::Byte(240));
|
grid[(get_x(bottom_right), y)].set_fg(Color::Byte(240));
|
||||||
}
|
}
|
||||||
set_and_join_box(grid, upper_left, HORZ_BOUNDARY);
|
set_and_join_box(grid, upper_left, BoxBoundary::Horizontal);
|
||||||
set_and_join_box(grid, set_x(upper_left, get_x(bottom_right)), HORZ_BOUNDARY);
|
set_and_join_box(
|
||||||
set_and_join_box(grid, set_y(upper_left, get_y(bottom_right)), VERT_BOUNDARY);
|
grid,
|
||||||
set_and_join_box(grid, bottom_right, VERT_BOUNDARY);
|
set_x(upper_left, get_x(bottom_right)),
|
||||||
|
BoxBoundary::Horizontal,
|
||||||
|
);
|
||||||
|
set_and_join_box(
|
||||||
|
grid,
|
||||||
|
set_y(upper_left, get_y(bottom_right)),
|
||||||
|
BoxBoundary::Vertical,
|
||||||
|
);
|
||||||
|
set_and_join_box(grid, bottom_right, BoxBoundary::Vertical);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ impl Component for Indexer {
|
|||||||
let index_entity_width = (30 * total_cols) / 100;
|
let index_entity_width = (30 * total_cols) / 100;
|
||||||
let mid = get_x(bottom_right) - index_entity_width;
|
let mid = get_x(bottom_right) - index_entity_width;
|
||||||
for i in get_y(upper_left)..=get_y(bottom_right) {
|
for i in get_y(upper_left)..=get_y(bottom_right) {
|
||||||
set_and_join_box(grid, (mid, i), VERT_BOUNDARY);
|
set_and_join_box(grid, (mid, i), BoxBoundary::Vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
let left_menu_area = (upper_left, (set_x(bottom_right, mid - 1)));
|
let left_menu_area = (upper_left, (set_x(bottom_right, mid - 1)));
|
||||||
|
@ -252,7 +252,7 @@ impl StatusPanel {
|
|||||||
|
|
||||||
for (i, a) in context.accounts.iter().enumerate() {
|
for (i, a) in context.accounts.iter().enumerate() {
|
||||||
for x in 2..(120 - 1) {
|
for x in 2..(120 - 1) {
|
||||||
set_and_join_box(&mut self.content, (x, 12 + i * 10), HORZ_BOUNDARY);
|
set_and_join_box(&mut self.content, (x, 12 + i * 10), BoxBoundary::Horizontal);
|
||||||
}
|
}
|
||||||
//create_box(&mut self.content, ((2, 5 + i * 10), (120 - 1, 15 + i * 10)));
|
//create_box(&mut self.content, ((2, 5 + i * 10), (120 - 1, 15 + i * 10)));
|
||||||
let (x, y) = write_string_to_grid(
|
let (x, y) = write_string_to_grid(
|
||||||
|
@ -245,11 +245,11 @@ impl ThreadView {
|
|||||||
set_and_join_box(
|
set_and_join_box(
|
||||||
&mut content,
|
&mut content,
|
||||||
(e.index.0 * 4 + ctr, 2 * y - 1),
|
(e.index.0 * 4 + ctr, 2 * y - 1),
|
||||||
HORZ_BOUNDARY,
|
BoxBoundary::Horizontal,
|
||||||
);
|
);
|
||||||
ctr += 1;
|
ctr += 1;
|
||||||
}
|
}
|
||||||
set_and_join_box(&mut content, index, HORZ_BOUNDARY);
|
set_and_join_box(&mut content, index, BoxBoundary::Horizontal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
@ -288,13 +288,17 @@ impl ThreadView {
|
|||||||
let bg_color = Color::Default;
|
let bg_color = Color::Default;
|
||||||
change_colors(&mut content, area, fg_color, bg_color);
|
change_colors(&mut content, area, fg_color, bg_color);
|
||||||
}
|
}
|
||||||
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), VERT_BOUNDARY);
|
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical);
|
||||||
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y + 1), VERT_BOUNDARY);
|
set_and_join_box(
|
||||||
|
&mut content,
|
||||||
|
(e.index.0 * 4, 2 * y + 1),
|
||||||
|
BoxBoundary::Vertical,
|
||||||
|
);
|
||||||
for i in ((e.index.0 * 4) + 1)..width - 1 {
|
for i in ((e.index.0 * 4) + 1)..width - 1 {
|
||||||
set_and_join_box(&mut content, (i, 2 * y + 1), HORZ_BOUNDARY);
|
set_and_join_box(&mut content, (i, 2 * y + 1), BoxBoundary::Horizontal);
|
||||||
}
|
}
|
||||||
set_and_join_box(&mut content, (width - 1, 2 * y), VERT_BOUNDARY);
|
set_and_join_box(&mut content, (width - 1, 2 * y), BoxBoundary::Vertical);
|
||||||
set_and_join_box(&mut content, (width - 1, 2 * y + 1), VERT_BOUNDARY);
|
set_and_join_box(&mut content, (width - 1, 2 * y + 1), BoxBoundary::Vertical);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (y, e) in self.entries.iter().enumerate() {
|
for (y, e) in self.entries.iter().enumerate() {
|
||||||
@ -323,11 +327,11 @@ impl ThreadView {
|
|||||||
set_and_join_box(
|
set_and_join_box(
|
||||||
&mut content,
|
&mut content,
|
||||||
(e.index.0 * 4 + ctr, 2 * y - 1),
|
(e.index.0 * 4 + ctr, 2 * y - 1),
|
||||||
HORZ_BOUNDARY,
|
BoxBoundary::Horizontal,
|
||||||
);
|
);
|
||||||
ctr += 1;
|
ctr += 1;
|
||||||
}
|
}
|
||||||
set_and_join_box(&mut content, index, HORZ_BOUNDARY);
|
set_and_join_box(&mut content, index, BoxBoundary::Horizontal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
@ -366,17 +370,21 @@ impl ThreadView {
|
|||||||
let bg_color = Color::Default;
|
let bg_color = Color::Default;
|
||||||
change_colors(&mut content, area, fg_color, bg_color);
|
change_colors(&mut content, area, fg_color, bg_color);
|
||||||
}
|
}
|
||||||
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), VERT_BOUNDARY);
|
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical);
|
||||||
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y + 1), VERT_BOUNDARY);
|
set_and_join_box(
|
||||||
|
&mut content,
|
||||||
|
(e.index.0 * 4, 2 * y + 1),
|
||||||
|
BoxBoundary::Vertical,
|
||||||
|
);
|
||||||
for i in ((e.index.0 * 4) + 1)..width - 1 {
|
for i in ((e.index.0 * 4) + 1)..width - 1 {
|
||||||
set_and_join_box(&mut content, (i, 2 * y + 1), HORZ_BOUNDARY);
|
set_and_join_box(&mut content, (i, 2 * y + 1), BoxBoundary::Horizontal);
|
||||||
}
|
}
|
||||||
set_and_join_box(&mut content, (width - 1, 2 * y), VERT_BOUNDARY);
|
set_and_join_box(&mut content, (width - 1, 2 * y), BoxBoundary::Vertical);
|
||||||
set_and_join_box(&mut content, (width - 1, 2 * y + 1), VERT_BOUNDARY);
|
set_and_join_box(&mut content, (width - 1, 2 * y + 1), BoxBoundary::Vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
for y in 0..height - 1 {
|
for y in 0..height - 1 {
|
||||||
set_and_join_box(&mut content, (width - 1, y), VERT_BOUNDARY);
|
set_and_join_box(&mut content, (width - 1, y), BoxBoundary::Vertical);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.content = content;
|
self.content = content;
|
||||||
@ -682,7 +690,7 @@ impl ThreadView {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for x in get_x(upper_left)..=get_x(bottom_right) {
|
for x in get_x(upper_left)..=get_x(bottom_right) {
|
||||||
set_and_join_box(grid, (x, y - 1), HORZ_BOUNDARY);
|
set_and_join_box(grid, (x, y - 1), BoxBoundary::Horizontal);
|
||||||
grid[(x, y - 1)].set_fg(Color::Byte(33));
|
grid[(x, y - 1)].set_fg(Color::Byte(33));
|
||||||
grid[(x, y - 1)].set_bg(Color::Default);
|
grid[(x, y - 1)].set_bg(Color::Default);
|
||||||
}
|
}
|
||||||
@ -768,7 +776,7 @@ impl ThreadView {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for x in get_x(upper_left)..=get_x(bottom_right) {
|
for x in get_x(upper_left)..=get_x(bottom_right) {
|
||||||
set_and_join_box(grid, (x, y - 1), HORZ_BOUNDARY);
|
set_and_join_box(grid, (x, y - 1), BoxBoundary::Horizontal);
|
||||||
grid[(x, y - 1)].set_fg(Color::Default);
|
grid[(x, y - 1)].set_fg(Color::Default);
|
||||||
grid[(x, y - 1)].set_bg(Color::Default);
|
grid[(x, y - 1)].set_bg(Color::Default);
|
||||||
}
|
}
|
||||||
@ -832,7 +840,7 @@ impl ThreadView {
|
|||||||
let area = (set_y(upper_left, mid), set_y(bottom_right, mid));
|
let area = (set_y(upper_left, mid), set_y(bottom_right, mid));
|
||||||
context.dirty_areas.push_back(area);
|
context.dirty_areas.push_back(area);
|
||||||
for x in get_x(upper_left)..=get_x(bottom_right) {
|
for x in get_x(upper_left)..=get_x(bottom_right) {
|
||||||
set_and_join_box(grid, (x, mid), HORZ_BOUNDARY);
|
set_and_join_box(grid, (x, mid), BoxBoundary::Horizontal);
|
||||||
grid[(x, mid)].set_fg(Color::Default);
|
grid[(x, mid)].set_fg(Color::Default);
|
||||||
grid[(x, mid)].set_bg(Color::Default);
|
grid[(x, mid)].set_bg(Color::Default);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user