diff --git a/meli/src/contacts/editor.rs b/meli/src/contacts/editor.rs index 40a4f0b8..3c23d1eb 100644 --- a/meli/src/contacts/editor.rs +++ b/meli/src/contacts/editor.rs @@ -152,12 +152,12 @@ impl Component for ContactManager { if self.dirty { let (width, _height) = self.content.size(); - clear_area( - grid, + + grid.clear_area( (upper_left, set_y(bottom_right, get_y(upper_left) + 1)), self.theme_default, ); - copy_area_with_break(grid, &self.content, area, ((0, 0), (width - 1, 0))); + grid.copy_area_with_break(&self.content, area, ((0, 0), (width - 1, 0))); self.dirty = false; } diff --git a/meli/src/contacts/list.rs b/meli/src/contacts/list.rs index 3038781a..95aaa527 100644 --- a/meli/src/contacts/list.rs +++ b/meli/src/contacts/list.rs @@ -228,14 +228,14 @@ impl ContactList { if !grid.use_color { theme.attrs |= Attr::REVERSE; } - change_theme(grid, area, theme); + grid.change_theme(area, theme); } fn draw_menu(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { if !self.is_dirty() { return; } - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); self.dirty = false; @@ -360,9 +360,9 @@ impl ContactList { let bottom_right = bottom_right!(area); if self.length == 0 { - clear_area(grid, area, self.theme_default); - copy_area( - grid, + grid.clear_area(area, self.theme_default); + + grid.copy_area( &self.data_columns.columns[0], area, ((0, 0), pos_dec(self.data_columns.columns[0].size(), (1, 1))), @@ -475,7 +475,7 @@ impl ContactList { width.saturating_sub(self.data_columns.widths[0] + self.data_columns.widths[1] + 4); self.data_columns.widths[2] = remainder / 6; } - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); /* Page_no has changed, so draw new page */ let header_attrs = crate::conf::value(context, "widgets.list.header"); @@ -505,8 +505,8 @@ impl ContactList { ), None, ); - copy_area( - grid, + + grid.copy_area( &self.data_columns.columns[i], ( set_x(upper_left, x), @@ -529,8 +529,7 @@ impl ContactList { } } - change_theme( - grid, + grid.change_theme( ( upper_left!(area), set_y(bottom_right, get_y(upper_left!(area))), @@ -539,8 +538,7 @@ impl ContactList { ); if top_idx + rows > self.length { - clear_area( - grid, + grid.clear_area( ( pos_inc(upper_left, (0, self.length - top_idx + 2)), bottom_right, diff --git a/meli/src/jobs_view.rs b/meli/src/jobs_view.rs index 1ef0a2ba..f1825ee4 100644 --- a/meli/src/jobs_view.rs +++ b/meli/src/jobs_view.rs @@ -247,9 +247,9 @@ impl JobManager { let (upper_left, bottom_right) = area; if self.length == 0 { - clear_area(grid, area, self.theme_default); - copy_area( - grid, + grid.clear_area(area, self.theme_default); + + grid.copy_area( &self.data_columns.columns[0], area, ((0, 0), pos_dec(self.data_columns.columns[0].size(), (1, 1))), @@ -337,7 +337,7 @@ impl JobManager { } else { self.theme_default }; - change_theme(grid, new_area, row_attr); + grid.change_theme(new_area, row_attr); context.dirty_areas.push_back(new_area); } return; @@ -352,22 +352,21 @@ impl JobManager { _ = self .data_columns .recalc_widths((width!(area), height!(area)), top_idx); - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); /* copy table columns */ self.data_columns .draw(grid, top_idx, self.cursor_pos, grid.bounds_iter(area)); /* highlight cursor */ - change_theme( - grid, + + grid.change_theme( nth_row_area(area, self.cursor_pos % rows), self.highlight_theme, ); /* clear gap if available height is more than count of entries */ if top_idx + rows > self.length { - clear_area( - grid, + grid.clear_area( ( pos_inc(upper_left, (0, self.length - top_idx)), bottom_right, @@ -390,7 +389,7 @@ impl Component for JobManager { { // Draw column headers. let area = nth_row_area(area, 0); - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); let mut x_offset = 0; let (upper_left, bottom_right) = area; for (i, (h, w)) in Self::HEADERS.iter().zip(self.min_width).enumerate() { diff --git a/meli/src/mail/compose.rs b/meli/src/mail/compose.rs index 227b7952..43094be4 100644 --- a/meli/src/mail/compose.rs +++ b/meli/src/mail/compose.rs @@ -680,7 +680,7 @@ To: {} fn draw_attachments(&self, grid: &mut CellBuffer, area: Area, context: &Context) { let attachments_no = self.draft.attachments().len(); let theme_default = crate::conf::value(context, "theme_default"); - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); #[cfg(feature = "gpgme")] if self.gpg_state.sign_mail.is_true() { let key_list = self @@ -959,25 +959,25 @@ impl Component for Composer { ), None, ); - clear_area(grid, ((x, y), (set_y(bottom_right, y))), theme_default); - change_theme( - grid, + grid.clear_area(((x, y), (set_y(bottom_right, y))), theme_default); + + grid.change_theme( ( set_x(pos_dec(upper_left!(header_area), (0, 1)), x), set_y(bottom_right!(header_area), y), ), crate::conf::value(context, "highlight"), ); - clear_area( - grid, + + grid.clear_area( ( pos_dec(upper_left, (0, 1)), set_x(bottom_right, get_x(upper_left) + mid), ), theme_default, ); - clear_area( - grid, + + grid.clear_area( ( ( get_x(bottom_right).saturating_sub(mid), @@ -995,9 +995,9 @@ impl Component for Composer { match embed_pty { EmbedStatus::Running(_, _) => { let mut guard = embed_pty.lock().unwrap(); - clear_area(grid, embed_area, theme_default); - copy_area( - grid, + grid.clear_area(embed_area, theme_default); + + grid.copy_area( guard.grid.buffer(), embed_area, ((0, 0), pos_dec(guard.grid.terminal_size, (1, 1))), @@ -1009,13 +1009,13 @@ impl Component for Composer { } EmbedStatus::Stopped(_, _) => { let guard = embed_pty.lock().unwrap(); - copy_area( - grid, + + grid.copy_area( guard.grid.buffer(), embed_area, ((0, 0), pos_dec(guard.grid.terminal_size, (1, 1))), ); - change_colors(grid, embed_area, Color::Byte(8), theme_default.bg); + grid.change_colors(embed_area, Color::Byte(8), theme_default.bg); let our_map: ShortcutMap = account_settings!(context[self.account_hash].shortcuts.composing) .key_values(); @@ -1046,7 +1046,7 @@ impl Component for Composer { ), ), ); - clear_area(grid, inner_area, theme_default); + grid.clear_area(inner_area, theme_default); for (i, l) in [ stopped_message.as_str(), stopped_message_2.as_str(), @@ -1081,14 +1081,13 @@ impl Component for Composer { } // Force clean pager area, because if body height is less than body_area it will // might leave draw artifacts in the remaining area. - clear_area(grid, body_area, theme_default); + grid.clear_area(body_area, theme_default); self.set_dirty(true); self.pager.draw(grid, body_area, context); match self.cursor { Cursor::Headers => { - change_theme( - grid, + grid.change_theme( ( pos_dec(upper_left!(body_area), (1, 0)), pos_dec( @@ -1100,8 +1099,7 @@ impl Component for Composer { ); } Cursor::Body => { - change_theme( - grid, + grid.change_theme( ( pos_dec(upper_left!(body_area), (1, 0)), pos_dec( diff --git a/meli/src/mail/compose/edit_attachments.rs b/meli/src/mail/compose/edit_attachments.rs index 17488743..8b2ce2e2 100644 --- a/meli/src/mail/compose/edit_attachments.rs +++ b/meli/src/mail/compose/edit_attachments.rs @@ -123,7 +123,7 @@ impl Component for EditAttachmentsRefMut<'_, '_> { } else if self.is_dirty() { let attachments_no = self.draft.attachments().len(); let theme_default = crate::conf::value(context, "theme_default"); - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); if attachments_no == 0 { grid.write_string_to_grid( "no attachments", diff --git a/meli/src/mail/listing.rs b/meli/src/mail/listing.rs index 0f385c32..89995620 100644 --- a/meli/src/mail/listing.rs +++ b/meli/src/mail/listing.rs @@ -2462,7 +2462,7 @@ impl Listing { } fn draw_menu(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); let total_height: usize = 3 * (self.accounts.len()) + self .accounts @@ -2509,8 +2509,7 @@ impl Listing { rows * y_offset.wrapping_div(rows).saturating_sub(1) + y_offset.wrapping_rem(rows) }; - copy_area( - grid, + grid.copy_area( &self.menu_content, area, ( diff --git a/meli/src/mail/listing/compact.rs b/meli/src/mail/listing/compact.rs index aa4bf8e2..9122ca45 100644 --- a/meli/src/mail/listing/compact.rs +++ b/meli/src/mail/listing/compact.rs @@ -680,8 +680,7 @@ impl ListingTrait for CompactListing { .set_attrs(row_attr.attrs); } - copy_area( - grid, + grid.copy_area( &self.data_columns.columns[3], (set_x(upper_left, x), bottom_right), ( @@ -709,9 +708,9 @@ impl ListingTrait for CompactListing { let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); if self.length == 0 { - clear_area(grid, area, self.color_cache.theme_default); - copy_area( - grid, + grid.clear_area(area, self.color_cache.theme_default); + + grid.copy_area( &self.data_columns.columns[0], area, ((0, 0), pos_dec(self.data_columns.columns[0].size(), (1, 1))), @@ -779,9 +778,9 @@ impl ListingTrait for CompactListing { .draw(grid, idx, self.cursor_pos.2, grid.bounds_iter(new_area)); if highlight { let row_attr = row_attr!(self.color_cache, idx % 2 == 0, false, true, false); - change_theme(grid, new_area, row_attr); + grid.change_theme(new_area, row_attr); } else if let Some(row_attr) = self.rows.row_attr_cache.get(&idx) { - change_theme(grid, new_area, *row_attr); + grid.change_theme(new_area, *row_attr); } context.dirty_areas.push_back(new_area); } @@ -800,14 +799,14 @@ impl ListingTrait for CompactListing { _ = self .data_columns .recalc_widths((width!(area), height!(area)), top_idx); - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); /* copy table columns */ self.data_columns .draw(grid, top_idx, self.cursor_pos.2, grid.bounds_iter(area)); /* apply each row colors separately */ for i in top_idx..(top_idx + height!(area)) { if let Some(row_attr) = self.rows.row_attr_cache.get(&i) { - change_theme(grid, nth_row_area(area, i % rows), *row_attr); + grid.change_theme(nth_row_area(area, i % rows), *row_attr); } } @@ -819,12 +818,11 @@ impl ListingTrait for CompactListing { true, false ); - change_theme(grid, nth_row_area(area, self.cursor_pos.2 % rows), row_attr); + grid.change_theme(nth_row_area(area, self.cursor_pos.2 % rows), row_attr); /* clear gap if available height is more than count of entries */ if top_idx + rows > self.length { - clear_area( - grid, + grid.clear_area( (pos_inc(upper_left, (0, rows - 1)), bottom_right), self.color_cache.theme_default, ); @@ -1759,7 +1757,7 @@ impl Component for CompactListing { } } else { if self.length == 0 && self.dirty { - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); context.dirty_areas.push_back(area); return; } diff --git a/meli/src/mail/listing/conversations.rs b/meli/src/mail/listing/conversations.rs index c25c39ed..449db37a 100644 --- a/meli/src/mail/listing/conversations.rs +++ b/meli/src/mail/listing/conversations.rs @@ -463,7 +463,7 @@ impl ListingTrait for ConversationsListing { let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); if let Err(message) = self.error.as_ref() { - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); grid.write_string_to_grid( message, @@ -546,7 +546,7 @@ impl ListingTrait for ConversationsListing { self.cursor_pos.2 = self.new_cursor_pos.2; } - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); /* Page_no has changed, so draw new page */ self.draw_rows(grid, area, context, top_idx); @@ -887,7 +887,7 @@ impl ConversationsListing { fn draw_rows(&self, grid: &mut CellBuffer, area: Area, context: &Context, top_idx: usize) { let account = &context.accounts[&self.cursor_pos.0]; let threads = account.collection.get_threads(self.cursor_pos.1); - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); let (mut upper_left, bottom_right) = area; for (idx, ((thread_hash, root_env_hash), strings)) in self.rows.entries.iter().enumerate().skip(top_idx) @@ -1057,8 +1057,8 @@ impl Component for ConversationsListing { for c in grid.row_iter(x..(get_x(bottom_right) + 1), y) { grid[c] = Cell::default(); } - clear_area( - grid, + + grid.clear_area( ((x, y), set_y(bottom_right, y)), self.color_cache.theme_default, ); @@ -1272,7 +1272,7 @@ impl Component for ConversationsListing { } if matches!(self.focus, Focus::Entry) { if self.length == 0 && self.dirty { - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); context.dirty_areas.push_back(area); return; } @@ -1285,7 +1285,7 @@ impl Component for ConversationsListing { pos_dec(upper_left!(entry_area), (1, 0)), bottom_right!(entry_area), ); - clear_area(grid, gap_area, self.color_cache.theme_default); + grid.clear_area(gap_area, self.color_cache.theme_default); context.dirty_areas.push_back(gap_area); self.view_area = entry_area.into(); } diff --git a/meli/src/mail/listing/offline.rs b/meli/src/mail/listing/offline.rs index 214e59f9..40b35cff 100644 --- a/meli/src/mail/listing/offline.rs +++ b/meli/src/mail/listing/offline.rs @@ -139,7 +139,7 @@ impl Component for OfflineListing { let theme_default = conf::value(context, "theme_default"); let text_unfocused = conf::value(context, "text.unfocused"); let error_message = conf::value(context, "error_message"); - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); if let Err(err) = context.is_online(self.cursor_pos.0) { let (x, _) = grid.write_string_to_grid( "offline: ", diff --git a/meli/src/mail/listing/plain.rs b/meli/src/mail/listing/plain.rs index 7f99f727..244be644 100644 --- a/meli/src/mail/listing/plain.rs +++ b/meli/src/mail/listing/plain.rs @@ -406,8 +406,8 @@ impl ListingTrait for PlainListing { .set_bg(row_attr.bg) .set_attrs(row_attr.attrs); } - copy_area( - grid, + + grid.copy_area( &self.data_columns.columns[3], (set_x(upper_left, x), bottom_right), ( @@ -429,9 +429,9 @@ impl ListingTrait for PlainListing { let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); if self.length == 0 { - clear_area(grid, area, self.color_cache.theme_default); - copy_area( - grid, + grid.clear_area(area, self.color_cache.theme_default); + + grid.copy_area( &self.data_columns.columns[0], area, ((0, 0), pos_dec(self.data_columns.columns[0].size(), (1, 1))), @@ -497,9 +497,9 @@ impl ListingTrait for PlainListing { .draw(grid, idx, self.cursor_pos.2, grid.bounds_iter(new_area)); if highlight { let row_attr = row_attr!(self.color_cache, idx % 2 == 0, false, true, false); - change_theme(grid, new_area, row_attr); + grid.change_theme(new_area, row_attr); } else if let Some(row_attr) = self.rows.row_attr_cache.get(&idx) { - change_theme(grid, new_area, *row_attr); + grid.change_theme(new_area, *row_attr); } context.dirty_areas.push_back(new_area); } @@ -518,14 +518,14 @@ impl ListingTrait for PlainListing { _ = self .data_columns .recalc_widths((width!(area), height!(area)), top_idx); - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); /* copy table columns */ self.data_columns .draw(grid, top_idx, self.cursor_pos.2, grid.bounds_iter(area)); /* apply each row colors separately */ for i in top_idx..(top_idx + height!(area)) { if let Some(row_attr) = self.rows.row_attr_cache.get(&i) { - change_theme(grid, nth_row_area(area, i % rows), *row_attr); + grid.change_theme(nth_row_area(area, i % rows), *row_attr); } } @@ -537,12 +537,11 @@ impl ListingTrait for PlainListing { true, false ); - change_theme(grid, nth_row_area(area, self.cursor_pos.2 % rows), row_attr); + grid.change_theme(nth_row_area(area, self.cursor_pos.2 % rows), row_attr); /* clear gap if available height is more than count of entries */ if top_idx + rows > self.length { - clear_area( - grid, + grid.clear_area( ( pos_inc(upper_left, (0, self.length - top_idx)), bottom_right, @@ -1052,10 +1051,10 @@ impl PlainListing { columns[3].size().0, ); - clear_area(&mut columns[0], ((0, idx), (min_width.0, idx)), row_attr); - clear_area(&mut columns[1], ((0, idx), (min_width.1, idx)), row_attr); - clear_area(&mut columns[2], ((0, idx), (min_width.2, idx)), row_attr); - clear_area(&mut columns[3], ((0, idx), (min_width.3, idx)), row_attr); + columns[0].clear_area(((0, idx), (min_width.0, idx)), row_attr); + columns[1].clear_area(((0, idx), (min_width.1, idx)), row_attr); + columns[2].clear_area(((0, idx), (min_width.2, idx)), row_attr); + columns[3].clear_area(((0, idx), (min_width.3, idx)), row_attr); let (x, _) = columns[0].write_string_to_grid( &idx.to_string(), @@ -1168,8 +1167,8 @@ impl Component for PlainListing { area, Some(get_x(upper_left)), ); - clear_area( - grid, + + grid.clear_area( ((x, y), set_y(bottom_right, y)), self.color_cache.theme_default, ); @@ -1381,7 +1380,7 @@ impl Component for PlainListing { } } else { if self.length == 0 && self.dirty { - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); context.dirty_areas.push_back(area); return; } diff --git a/meli/src/mail/listing/thread.rs b/meli/src/mail/listing/thread.rs index 8e70cf51..7716c981 100644 --- a/meli/src/mail/listing/thread.rs +++ b/meli/src/mail/listing/thread.rs @@ -492,7 +492,7 @@ impl ListingTrait for ThreadListing { let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); if self.length == 0 { - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); context.dirty_areas.push_back(area); return; } @@ -562,7 +562,7 @@ impl ListingTrait for ThreadListing { highlight, self.rows.selection[&env_hash] ); - change_theme(grid, new_area, row_attr); + grid.change_theme(new_area, row_attr); } context.dirty_areas.push_back(new_area); } @@ -590,7 +590,7 @@ impl ListingTrait for ThreadListing { _ = self .data_columns .recalc_widths((width!(area), height!(area)), top_idx); - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); /* copy table columns */ self.data_columns .draw(grid, top_idx, self.cursor_pos.2, grid.bounds_iter(area)); @@ -607,7 +607,7 @@ impl ListingTrait for ThreadListing { self.cursor_pos.2 == idx, self.rows.selection[&env_hash] ); - change_theme(grid, nth_row_area(area, idx % rows), row_attr); + grid.change_theme(nth_row_area(area, idx % rows), row_attr); } } @@ -620,13 +620,12 @@ impl ListingTrait for ThreadListing { true, // because self.cursor_pos.2 == idx, self.rows.selection[&env_hash] ); - change_theme(grid, nth_row_area(area, self.cursor_pos.2 % rows), row_attr); + grid.change_theme(nth_row_area(area, self.cursor_pos.2 % rows), row_attr); } /* clear gap if available height is more than count of entries */ if top_idx + rows > self.length { - clear_area( - grid, + grid.clear_area( ( pos_inc(upper_left, (0, self.length - top_idx)), bottom_right, @@ -1100,11 +1099,11 @@ impl ThreadListing { columns[4].size().0, ); - clear_area(&mut columns[0], ((0, idx), (min_width.0, idx)), row_attr); - clear_area(&mut columns[1], ((0, idx), (min_width.1, idx)), row_attr); - clear_area(&mut columns[2], ((0, idx), (min_width.2, idx)), row_attr); - clear_area(&mut columns[3], ((0, idx), (min_width.3, idx)), row_attr); - clear_area(&mut columns[4], ((0, idx), (min_width.4, idx)), row_attr); + columns[0].clear_area(((0, idx), (min_width.0, idx)), row_attr); + columns[1].clear_area(((0, idx), (min_width.1, idx)), row_attr); + columns[2].clear_area(((0, idx), (min_width.2, idx)), row_attr); + columns[3].clear_area(((0, idx), (min_width.3, idx)), row_attr); + columns[4].clear_area(((0, idx), (min_width.4, idx)), row_attr); *self.rows.entries.get_mut(idx).unwrap() = ((thread_hash, env_hash), strings); } @@ -1125,13 +1124,9 @@ impl ThreadListing { row_attr!(self.color_cache, (top_idx + i) % 2 == 0, false, true, false) }; - clear_area( - &mut self.data_columns.columns[0], - ((0, i), (width - 1, i + 1)), - row_attr, - ); - clear_area( - grid, + self.data_columns.columns[0].clear_area(((0, i), (width - 1, i + 1)), row_attr); + + grid.clear_area( ( pos_inc(upper_left, (0, i)), pos_inc(upper_left, (width - 1, i + 1)), @@ -1374,7 +1369,7 @@ impl Component for ThreadListing { let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); if self.length == 0 && self.dirty { - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); context.dirty_areas.push_back(area); return; } @@ -1390,7 +1385,7 @@ impl Component for ThreadListing { let bottom_entity_rows = (pager_ratio * total_rows) / 100; if bottom_entity_rows > total_rows { - clear_area(grid, area, self.color_cache.theme_default); + grid.clear_area(area, self.color_cache.theme_default); context.dirty_areas.push_back(area); return; } diff --git a/meli/src/mail/status.rs b/meli/src/mail/status.rs index 42bf4a53..a7f1d13d 100644 --- a/meli/src/mail/status.rs +++ b/meli/src/mail/status.rs @@ -351,9 +351,9 @@ impl Component for AccountStatus { std::cmp::min(width.saturating_sub(cols), self.cursor.0), std::cmp::min(height.saturating_sub(rows), self.cursor.1), ); - clear_area(grid, area, self.theme_default); - copy_area( - grid, + grid.clear_area(area, self.theme_default); + + grid.copy_area( &self.content, area, ( diff --git a/meli/src/mail/view.rs b/meli/src/mail/view.rs index fab7fb28..39677c42 100644 --- a/meli/src/mail/view.rs +++ b/meli/src/mail/view.rs @@ -325,7 +325,7 @@ impl Component for MailView { } env_view.draw(grid, area, context); } else if let MailViewState::Error { ref err } = self.state { - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); context.dirty_areas.push_back(area); context.replies.push_back(UIEvent::Notification( Some("Failed to open e-mail".to_string()), @@ -336,7 +336,7 @@ impl Component for MailView { self.init_futures(context); return; } else { - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); context.dirty_areas.push_back(area); return; }; diff --git a/meli/src/mail/view/envelope.rs b/meli/src/mail/view/envelope.rs index 52ce8380..81dc58bd 100644 --- a/meli/src/mail/view/envelope.rs +++ b/meli/src/mail/view/envelope.rs @@ -722,7 +722,7 @@ impl Component for EnvelopeView { let y: usize = { if self.mode.is_source() { - clear_area(grid, area, self.view_settings.theme_default); + grid.clear_area(area, self.view_settings.theme_default); context.dirty_areas.push_back(area); get_y(upper_left) } else { @@ -767,8 +767,8 @@ impl Component for EnvelopeView { ((_x + 1, _y), bottom_right), Some(get_x(upper_left)), ); - clear_area( - grid, + + grid.clear_area( ( (std::cmp::min(_x, get_x(bottom_right)), _y), (get_x(bottom_right), _y), @@ -874,8 +874,7 @@ impl Component for EnvelopeView { let mut x = get_x(upper_left); if let Some(id) = id { if sticky || skip_header_ctr == 0 { - clear_area( - grid, + grid.clear_area( (set_y(upper_left, y), set_y(bottom_right, y)), headers_area, ); @@ -978,11 +977,8 @@ impl Component for EnvelopeView { } self.force_draw_headers = false; - clear_area( - grid, - (set_y(upper_left, y), set_y(bottom_right, y)), - headers_area, - ); + + grid.clear_area((set_y(upper_left, y), set_y(bottom_right, y)), headers_area); context.dirty_areas.push_back(( upper_left, set_y(bottom_right, std::cmp::min(y + 3, get_y(bottom_right))), @@ -1234,8 +1230,7 @@ impl Component for EnvelopeView { let l = nth_row_area(area, height!(area)); if self.cmd_buf.is_empty() { - clear_area( - grid, + grid.clear_area( (pos_inc(l.0, (width!(area).saturating_sub(8), 0)), l.1), self.view_settings.theme_default, ); diff --git a/meli/src/mail/view/thread.rs b/meli/src/mail/view/thread.rs index fab21451..6a8032a9 100644 --- a/meli/src/mail/view/thread.rs +++ b/meli/src/mail/view/thread.rs @@ -399,7 +399,7 @@ impl ThreadView { if let Some(len) = highlight_reply_subjects[y] { let index = e.index.0 * 4 + 1 + e.heading.grapheme_width() - len; let area = ((index, 2 * y), (width - 2, 2 * y)); - change_theme(&mut content, area, highlight_theme); + content.change_theme(area, highlight_theme); } set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical); set_and_join_box( @@ -420,7 +420,7 @@ impl ThreadView { for i in 0..e.index.0 { let att = self.indentation_colors[(i).wrapping_rem(self.indentation_colors.len())]; - change_theme(&mut content, ((x, 2 * y), (x + 3, 2 * y + 1)), att); + content.change_theme(((x, 2 * y), (x + 3, 2 * y + 1)), att); x += 4; } if y > 0 && content.get_mut(e.index.0 * 4, 2 * y - 1).is_some() { @@ -465,7 +465,7 @@ impl ThreadView { if highlight_reply_subjects[y].is_some() { let index = e.index.0 * 4 + 1; let area = ((index, 2 * y), (width - 2, 2 * y)); - change_theme(&mut content, area, highlight_theme); + content.change_theme(area, highlight_theme); } set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical); set_and_join_box( @@ -505,8 +505,8 @@ impl ThreadView { } else { Attr::REVERSE }; - change_theme( - grid, + + grid.change_theme( dest_area, ThemeAttribute { fg: theme_default.fg, @@ -517,7 +517,7 @@ impl ThreadView { return; } - copy_area(grid, &self.content, dest_area, src_area); + grid.copy_area(&self.content, dest_area, src_area); } fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { @@ -587,7 +587,7 @@ impl ThreadView { if self.dirty || (page_no != prev_page_no) { if page_no != prev_page_no { - clear_area(grid, area, crate::conf::value(context, "theme_default")); + grid.clear_area(area, crate::conf::value(context, "theme_default")); } let visibles: Vec<&usize> = self.visible_entries.iter().flat_map(|v| v.iter()).collect(); @@ -597,8 +597,8 @@ impl ThreadView { break; } let idx = *v; - copy_area( - grid, + + grid.copy_area( &self.content, ( pos_inc(upper_left, (0, 2 * visible_entry_counter)), // dest_area @@ -654,8 +654,7 @@ impl ThreadView { ); } if 2 * top_idx + rows > 2 * visibles.len() + 1 { - clear_area( - grid, + grid.clear_area( ( pos_inc(upper_left, (0, 2 * (visibles.len() - top_idx) + 1)), bottom_right, @@ -738,7 +737,7 @@ impl ThreadView { let theme_default = crate::conf::value(context, "theme_default"); /* First draw the thread subject on the first row */ let y = if self.dirty { - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); let account = &context.accounts[&self.coordinates.0]; let threads = account.collection.get_threads(self.coordinates.1); let thread_root = threads.thread_iter(self.thread_group).next().unwrap().1; @@ -776,11 +775,8 @@ impl ThreadView { set_x(bottom_right, std::cmp::min(get_x(bottom_right), mid)), )); } - clear_area( - grid, - ((mid, y + 1), set_x(bottom_right, mid)), - theme_default, - ); + + grid.clear_area(((mid, y + 1), set_x(bottom_right, mid)), theme_default); y + 2 } else { get_y(upper_left) + 2 @@ -814,8 +810,7 @@ impl ThreadView { ); } ThreadViewFocus::Thread => { - clear_area( - grid, + grid.clear_area( ((mid + 1, get_y(upper_left) + y - 1), bottom_right), theme_default, ); @@ -854,7 +849,7 @@ impl ThreadView { let theme_default = crate::conf::value(context, "theme_default"); /* First draw the thread subject on the first row */ let y = { - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); let account = &context.accounts[&self.coordinates.0]; let threads = account.collection.get_threads(self.coordinates.1); let thread_root = threads.thread_iter(self.thread_group).next().unwrap().1; @@ -901,8 +896,7 @@ impl ThreadView { return; } - clear_area( - grid, + grid.clear_area( (set_y(upper_left, y), set_y(bottom_right, mid + 1)), theme_default, ); @@ -924,8 +918,7 @@ impl ThreadView { let page_no = (self.new_cursor_pos).wrapping_div(rows); let top_idx = page_no * rows; - copy_area( - grid, + grid.copy_area( &self.content, area, ((0, 2 * top_idx), (width - 1, height - 1)), @@ -945,8 +938,8 @@ impl ThreadView { } let page_no = (self.new_cursor_pos).wrapping_div(rows); let top_idx = page_no * rows; - copy_area( - grid, + + grid.copy_area( &self.content, area, ((0, 2 * top_idx), (width - 1, height - 1)), diff --git a/meli/src/mailbox_management.rs b/meli/src/mailbox_management.rs index 05f4d825..d878114b 100644 --- a/meli/src/mailbox_management.rs +++ b/meli/src/mailbox_management.rs @@ -191,9 +191,9 @@ impl MailboxManager { let (upper_left, bottom_right) = area; if self.length == 0 { - clear_area(grid, area, self.theme_default); - copy_area( - grid, + grid.clear_area(area, self.theme_default); + + grid.copy_area( &self.data_columns.columns[0], area, ((0, 0), pos_dec(self.data_columns.columns[0].size(), (1, 1))), @@ -281,7 +281,7 @@ impl MailboxManager { } else { self.theme_default }; - change_theme(grid, new_area, row_attr); + grid.change_theme(new_area, row_attr); context.dirty_areas.push_back(new_area); } return; @@ -296,22 +296,21 @@ impl MailboxManager { _ = self .data_columns .recalc_widths((width!(area), height!(area)), top_idx); - clear_area(grid, area, self.theme_default); + grid.clear_area(area, self.theme_default); /* copy table columns */ self.data_columns .draw(grid, top_idx, self.cursor_pos, grid.bounds_iter(area)); /* highlight cursor */ - change_theme( - grid, + + grid.change_theme( nth_row_area(area, self.cursor_pos % rows), self.highlight_theme, ); /* clear gap if available height is more than count of entries */ if top_idx + rows > self.length { - clear_area( - grid, + grid.clear_area( ( pos_inc(upper_left, (0, self.length - top_idx)), bottom_right, diff --git a/meli/src/state.rs b/meli/src/state.rs index cfdb5ad4..b8606aab 100644 --- a/meli/src/state.rs +++ b/meli/src/state.rs @@ -805,7 +805,9 @@ impl State { }, ), ); - copy_area(&mut self.screen.overlay_grid, &self.screen.grid, area, area); + self.screen + .overlay_grid + .copy_area(&self.screen.grid, area, area); self.overlay.get_index_mut(0).unwrap().1.draw( &mut self.screen.overlay_grid, area, diff --git a/meli/src/terminal/cells.rs b/meli/src/terminal/cells.rs index 248ec2a8..8c454ae8 100644 --- a/meli/src/terminal/cells.rs +++ b/meli/src/terminal/cells.rs @@ -566,6 +566,204 @@ impl CellBuffer { } (x, y) } + + pub fn copy_area_with_break(&mut self, grid_src: &Self, dest: Area, src: Area) -> Pos { + if !is_valid_area!(dest) || !is_valid_area!(src) { + log::debug!( + "BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", + src, + dest + ); + return upper_left!(dest); + } + + if grid_src.is_empty() || self.is_empty() { + return upper_left!(dest); + } + + let mut ret = bottom_right!(dest); + let mut src_x = get_x(upper_left!(src)); + let mut src_y = get_y(upper_left!(src)); + + 'y_: for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) { + 'x_: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) { + if grid_src[(src_x, src_y)].ch() == '\n' { + src_y += 1; + src_x = 0; + if src_y >= get_y(bottom_right!(src)) { + ret.1 = y; + break 'y_; + } + continue 'y_; + } + + self[(x, y)] = grid_src[(src_x, src_y)]; + src_x += 1; + if src_x >= get_x(bottom_right!(src)) { + src_y += 1; + src_x = 0; + if src_y >= get_y(bottom_right!(src)) { + //clear_area(self, ((get_x(upper_left!(dest)), y), bottom_right!(dest))); + ret.1 = y; + break 'y_; + } + break 'x_; + } + } + } + ret + } + + /// Copy a source `Area` to a destination. + pub fn copy_area(&mut self, grid_src: &Self, dest: Area, src: Area) -> Pos { + if !is_valid_area!(dest) || !is_valid_area!(src) { + log::debug!( + "BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", + src, + dest + ); + return upper_left!(dest); + } + + if grid_src.is_empty() || self.is_empty() { + return upper_left!(dest); + } + + let mut ret = bottom_right!(dest); + let mut src_x = get_x(upper_left!(src)); + let mut src_y = get_y(upper_left!(src)); + let (cols, rows) = grid_src.size(); + if src_x >= cols || src_y >= rows { + log::debug!("BUG: src area outside of grid_src in copy_area",); + return upper_left!(dest); + } + + let tag_associations = grid_src.tag_associations(); + let start_idx = grid_src.pos_to_index(src_x, src_y).unwrap(); + let mut tag_offset: usize = tag_associations + .binary_search_by(|probe| probe.0.cmp(&start_idx)) + .unwrap_or_else(|i| i); + let mut stack: std::collections::BTreeSet<&FormatTag> = + std::collections::BTreeSet::default(); + for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) { + 'for_x: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) { + let idx = grid_src.pos_to_index(src_x, src_y).unwrap(); + while tag_offset < tag_associations.len() && tag_associations[tag_offset].0 <= idx { + if tag_associations[tag_offset].2 { + stack.insert(&grid_src.tag_table()[&tag_associations[tag_offset].1]); + } else { + stack.remove(&grid_src.tag_table()[&tag_associations[tag_offset].1]); + } + tag_offset += 1; + } + self[(x, y)] = grid_src[(src_x, src_y)]; + for t in &stack { + if let Some(fg) = t.fg { + self[(x, y)].set_fg(fg).set_keep_fg(true); + } + if let Some(bg) = t.bg { + self[(x, y)].set_bg(bg).set_keep_bg(true); + } + if let Some(attrs) = t.attrs { + self[(x, y)].attrs |= attrs; + self[(x, y)].set_keep_attrs(true); + } + } + if src_x >= get_x(bottom_right!(src)) { + break 'for_x; + } + src_x += 1; + } + src_x = get_x(upper_left!(src)); + src_y += 1; + if src_y > get_y(bottom_right!(src)) { + for row in + self.bounds_iter(((get_x(upper_left!(dest)), y + 1), bottom_right!(dest))) + { + for c in row { + self[c].set_ch(' '); + } + } + ret.1 = y; + break; + } + } + ret + } + + /// Change foreground and background colors in an `Area` + pub fn change_colors(&mut self, area: Area, fg_color: Color, bg_color: Color) { + if cfg!(feature = "debug-tracing") { + let bounds = self.size(); + let upper_left = upper_left!(area); + let bottom_right = bottom_right!(area); + let (x, y) = upper_left; + if y > (get_y(bottom_right)) + || x > get_x(bottom_right) + || y >= get_y(bounds) + || x >= get_x(bounds) + { + log::debug!("BUG: Invalid area in change_colors:\n area: {:?}", area); + return; + } + if !is_valid_area!(area) { + log::debug!("BUG: Invalid area in change_colors:\n area: {:?}", area); + return; + } + } + for row in self.bounds_iter(area) { + for c in row { + self[c].set_fg(fg_color).set_bg(bg_color); + } + } + } + + /// Change [`ThemeAttribute`] in an `Area` + pub fn change_theme(&mut self, area: Area, theme: ThemeAttribute) { + if cfg!(feature = "debug-tracing") { + let bounds = self.size(); + let upper_left = upper_left!(area); + let bottom_right = bottom_right!(area); + let (x, y) = upper_left; + if y > (get_y(bottom_right)) + || x > get_x(bottom_right) + || y >= get_y(bounds) + || x >= get_x(bounds) + { + log::debug!("BUG: Invalid area in change_theme:\n area: {:?}", area); + return; + } + if !is_valid_area!(area) { + log::debug!("BUG: Invalid area in change_theme:\n area: {:?}", area); + return; + } + } + for row in self.bounds_iter(area) { + for c in row { + self[c] + .set_fg(theme.fg) + .set_bg(theme.bg) + .set_attrs(theme.attrs); + } + } + } + + /// Completely clear an `Area` with an empty char and the terminal's default + /// colors. + pub fn clear_area(&mut self, area: Area, attributes: ThemeAttribute) { + if !is_valid_area!(area) { + return; + } + for row in self.bounds_iter(area) { + for c in row { + self[c] = Cell::default(); + self[c] + .set_fg(attributes.fg) + .set_bg(attributes.bg) + .set_attrs(attributes.attrs); + } + } + } } impl Deref for CellBuffer { @@ -1081,208 +1279,6 @@ impl Attr { } } -pub fn copy_area_with_break( - grid_dest: &mut CellBuffer, - grid_src: &CellBuffer, - dest: Area, - src: Area, -) -> Pos { - if !is_valid_area!(dest) || !is_valid_area!(src) { - log::debug!( - "BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", - src, - dest - ); - return upper_left!(dest); - } - - if grid_src.is_empty() || grid_dest.is_empty() { - return upper_left!(dest); - } - - let mut ret = bottom_right!(dest); - let mut src_x = get_x(upper_left!(src)); - let mut src_y = get_y(upper_left!(src)); - - 'y_: for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) { - 'x_: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) { - if grid_src[(src_x, src_y)].ch() == '\n' { - src_y += 1; - src_x = 0; - if src_y >= get_y(bottom_right!(src)) { - ret.1 = y; - break 'y_; - } - continue 'y_; - } - - grid_dest[(x, y)] = grid_src[(src_x, src_y)]; - src_x += 1; - if src_x >= get_x(bottom_right!(src)) { - src_y += 1; - src_x = 0; - if src_y >= get_y(bottom_right!(src)) { - //clear_area(grid_dest, ((get_x(upper_left!(dest)), y), bottom_right!(dest))); - ret.1 = y; - break 'y_; - } - break 'x_; - } - } - } - ret -} - -/// Copy a source `Area` to a destination. -pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) -> Pos { - if !is_valid_area!(dest) || !is_valid_area!(src) { - log::debug!( - "BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", - src, - dest - ); - return upper_left!(dest); - } - - if grid_src.is_empty() || grid_dest.is_empty() { - return upper_left!(dest); - } - - let mut ret = bottom_right!(dest); - let mut src_x = get_x(upper_left!(src)); - let mut src_y = get_y(upper_left!(src)); - let (cols, rows) = grid_src.size(); - if src_x >= cols || src_y >= rows { - log::debug!("BUG: src area outside of grid_src in copy_area",); - return upper_left!(dest); - } - - let tag_associations = grid_src.tag_associations(); - let start_idx = grid_src.pos_to_index(src_x, src_y).unwrap(); - let mut tag_offset: usize = tag_associations - .binary_search_by(|probe| probe.0.cmp(&start_idx)) - .unwrap_or_else(|i| i); - let mut stack: std::collections::BTreeSet<&FormatTag> = std::collections::BTreeSet::default(); - for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) { - 'for_x: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) { - let idx = grid_src.pos_to_index(src_x, src_y).unwrap(); - while tag_offset < tag_associations.len() && tag_associations[tag_offset].0 <= idx { - if tag_associations[tag_offset].2 { - stack.insert(&grid_src.tag_table()[&tag_associations[tag_offset].1]); - } else { - stack.remove(&grid_src.tag_table()[&tag_associations[tag_offset].1]); - } - tag_offset += 1; - } - grid_dest[(x, y)] = grid_src[(src_x, src_y)]; - for t in &stack { - if let Some(fg) = t.fg { - grid_dest[(x, y)].set_fg(fg).set_keep_fg(true); - } - if let Some(bg) = t.bg { - grid_dest[(x, y)].set_bg(bg).set_keep_bg(true); - } - if let Some(attrs) = t.attrs { - grid_dest[(x, y)].attrs |= attrs; - grid_dest[(x, y)].set_keep_attrs(true); - } - } - if src_x >= get_x(bottom_right!(src)) { - break 'for_x; - } - src_x += 1; - } - src_x = get_x(upper_left!(src)); - src_y += 1; - if src_y > get_y(bottom_right!(src)) { - for row in - grid_dest.bounds_iter(((get_x(upper_left!(dest)), y + 1), bottom_right!(dest))) - { - for c in row { - grid_dest[c].set_ch(' '); - } - } - ret.1 = y; - break; - } - } - ret -} - -/// Change foreground and background colors in an `Area` -pub fn change_colors(grid: &mut CellBuffer, area: Area, fg_color: Color, bg_color: Color) { - if cfg!(feature = "debug-tracing") { - let bounds = grid.size(); - let upper_left = upper_left!(area); - let bottom_right = bottom_right!(area); - let (x, y) = upper_left; - if y > (get_y(bottom_right)) - || x > get_x(bottom_right) - || y >= get_y(bounds) - || x >= get_x(bounds) - { - log::debug!("BUG: Invalid area in change_colors:\n area: {:?}", area); - return; - } - if !is_valid_area!(area) { - log::debug!("BUG: Invalid area in change_colors:\n area: {:?}", area); - return; - } - } - for row in grid.bounds_iter(area) { - for c in row { - grid[c].set_fg(fg_color).set_bg(bg_color); - } - } -} - -/// Change [`ThemeAttribute`] in an `Area` -pub fn change_theme(grid: &mut CellBuffer, area: Area, theme: ThemeAttribute) { - if cfg!(feature = "debug-tracing") { - let bounds = grid.size(); - let upper_left = upper_left!(area); - let bottom_right = bottom_right!(area); - let (x, y) = upper_left; - if y > (get_y(bottom_right)) - || x > get_x(bottom_right) - || y >= get_y(bounds) - || x >= get_x(bounds) - { - log::debug!("BUG: Invalid area in change_theme:\n area: {:?}", area); - return; - } - if !is_valid_area!(area) { - log::debug!("BUG: Invalid area in change_theme:\n area: {:?}", area); - return; - } - } - for row in grid.bounds_iter(area) { - for c in row { - grid[c] - .set_fg(theme.fg) - .set_bg(theme.bg) - .set_attrs(theme.attrs); - } - } -} - -/// Completely clear an `Area` with an empty char and the terminal's default -/// colors. -pub fn clear_area(grid: &mut CellBuffer, area: Area, attributes: ThemeAttribute) { - if !is_valid_area!(area) { - return; - } - for row in grid.bounds_iter(area) { - for c in row { - grid[c] = Cell::default(); - grid[c] - .set_fg(attributes.fg) - .set_bg(attributes.bg) - .set_attrs(attributes.attrs); - } - } -} - /// Use `RowIterator` to iterate the cells of a row without the need to do any /// bounds checking; the iterator will simply return `None` when it reaches the /// end of the row. `RowIterator` can be created via the `CellBuffer::row_iter` diff --git a/meli/src/terminal/embed/grid.rs b/meli/src/terminal/embed/grid.rs index 5b4f2792..efa687dd 100644 --- a/meli/src/terminal/embed/grid.rs +++ b/meli/src/terminal/embed/grid.rs @@ -659,8 +659,8 @@ impl EmbedGrid { (b'J', State::Csi) => { /* Erase in Display (ED), VT100. */ /* Erase Below (default). */ - clear_area( - grid, + + grid.clear_area( ( ( 0, @@ -757,8 +757,8 @@ impl EmbedGrid { } } //log::trace!("{}", EscCode::from((&(*state), byte))); - clear_area( - grid, + + grid.clear_area( ((0, 0), pos_dec(*terminal_size, (1, 1))), Default::default(), ); @@ -767,8 +767,8 @@ impl EmbedGrid { (b'J', State::Csi1(ref buf)) if buf.as_ref() == b"0" => { /* Erase in Display (ED), VT100. */ /* Erase Below (default). */ - clear_area( - grid, + + grid.clear_area( ( ( 0, @@ -790,8 +790,8 @@ impl EmbedGrid { (b'J', State::Csi1(ref buf)) if buf.as_ref() == b"1" => { /* Erase in Display (ED), VT100. */ /* Erase Above */ - clear_area( - grid, + + grid.clear_area( ( (0, 0), ( @@ -807,8 +807,8 @@ impl EmbedGrid { (b'J', State::Csi1(ref buf)) if buf.as_ref() == b"2" => { /* Erase in Display (ED), VT100. */ /* Erase All */ - clear_area( - grid, + + grid.clear_area( ((0, 0), pos_dec(*terminal_size, (1, 1))), Default::default(), ); diff --git a/meli/src/utilities.rs b/meli/src/utilities.rs index cb3f246c..29dd43f8 100644 --- a/meli/src/utilities.rs +++ b/meli/src/utilities.rs @@ -234,7 +234,7 @@ impl StatusBar { } fn draw_command_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { - clear_area(grid, area, crate::conf::value(context, "theme_default")); + grid.clear_area(area, crate::conf::value(context, "theme_default")); let command_bar = crate::conf::value(context, "status.command_bar"); let (_, y) = grid.write_string_to_grid( self.ex_buffer.as_str(), @@ -244,7 +244,7 @@ impl StatusBar { area, None, ); - change_theme(grid, area, command_bar); + grid.change_theme(area, command_bar); if let Some(ref mut cell) = grid.get_mut( pos_inc(upper_left!(area), (self.ex_buffer.cursor(), 0)).0, y, @@ -392,11 +392,8 @@ impl Component for StatusBar { hist_height, self.auto_complete.suggestions().len(), ); - change_theme( - grid, - hist_area, - crate::conf::value(context, "status.history"), - ); + + grid.change_theme(hist_area, crate::conf::value(context, "status.history")); context.dirty_areas.push_back(hist_area); hist_area } else { @@ -418,14 +415,11 @@ impl Component for StatusBar { } else { self.auto_complete.cursor() }; - clear_area( - grid, - hist_area, - crate::conf::value(context, "theme_default"), - ); + + grid.clear_area(hist_area, crate::conf::value(context, "theme_default")); let history_hints = crate::conf::value(context, "status.history.hints"); if hist_height > 0 { - change_theme(grid, hist_area, history_hints); + grid.change_theme(hist_area, history_hints); } for (y_offset, s) in self .auto_complete @@ -458,8 +452,7 @@ impl Component for StatusBar { None, ); if y_offset + offset == self.auto_complete.cursor() { - change_theme( - grid, + grid.change_theme( ( set_y( upper_left!(hist_area), @@ -854,7 +847,7 @@ impl Tabbed { let bottom_right = bottom_right!(area); let tab_bar_attribute = crate::conf::value(context, "tab.bar"); - clear_area(grid, area, tab_bar_attribute); + grid.clear_area(area, tab_bar_attribute); if self.children.is_empty() { return; } @@ -950,8 +943,7 @@ impl std::fmt::Display for Tabbed { impl Component for Tabbed { fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { if self.dirty { - clear_area( - grid, + grid.clear_area( ( upper_left!(area), set_x(upper_left!(area), get_x(bottom_right!(area))), @@ -1013,7 +1005,7 @@ impl Component for Tabbed { Alignment::Center, ); context.dirty_areas.push_back(dialog_area); - clear_area(grid, dialog_area, self.theme_default); + grid.clear_area(dialog_area, self.theme_default); let inner_area = create_box(grid, dialog_area); let (x, y) = grid.write_string_to_grid( "shortcuts", @@ -1039,8 +1031,8 @@ impl Component for Tabbed { ); let (width, height) = self.help_content.size(); let (cols, rows) = (width!(inner_area), height!(inner_area)); - copy_area( - grid, + + grid.copy_area( &self.help_content, inner_area, ( @@ -1189,7 +1181,7 @@ impl Component for Tabbed { Alignment::Center, ); context.dirty_areas.push_back(dialog_area); - clear_area(grid, dialog_area, self.theme_default); + grid.clear_area(dialog_area, self.theme_default); let inner_area = create_box(grid, dialog_area); let (x, y) = grid.write_string_to_grid( "shortcuts", @@ -1296,8 +1288,8 @@ impl Component for Tabbed { None, ); } - copy_area( - grid, + + grid.copy_area( &self.help_content, inner_area, ( @@ -1632,9 +1624,9 @@ impl Component for RawBuffer { std::cmp::min(width.saturating_sub(cols), self.cursor.0), std::cmp::min(height.saturating_sub(rows), self.cursor.1), ); - clear_area(grid, area, crate::conf::value(context, "theme_default")); - copy_area( - grid, + grid.clear_area(area, crate::conf::value(context, "theme_default")); + + grid.copy_area( &self.buf, area, ( diff --git a/meli/src/utilities/dialogs.rs b/meli/src/utilities/dialogs.rs index 1409782f..9dbca033 100644 --- a/meli/src/utilities/dialogs.rs +++ b/meli/src/utilities/dialogs.rs @@ -377,8 +377,8 @@ impl Component f .set_bg(highlighted_attrs.bg) .set_attrs(highlighted_attrs.attrs); } - change_theme( - &mut self.content, + + self.content.change_theme( ( ((width - OK_CANCEL.len()) / 2 + CANCEL_OFFSET, height - 1), ( @@ -702,8 +702,8 @@ impl Component for UIConfirmationDialog { .set_bg(highlighted_attrs.bg) .set_attrs(highlighted_attrs.attrs); } - change_theme( - &mut self.content, + + self.content.change_theme( ( ((width - OK_CANCEL.len()) / 2 + CANCEL_OFFSET, height - 1), ( @@ -885,7 +885,7 @@ impl total_cols, (true, false) => 0, (false, false) => { - clear_area(grid, area, crate::conf::value(context, "theme_default")); + grid.clear_area(area, crate::conf::value(context, "theme_default")); return; } }; diff --git a/meli/src/utilities/pager.rs b/meli/src/utilities/pager.rs index a7f94251..921ca075 100644 --- a/meli/src/utilities/pager.rs +++ b/meli/src/utilities/pager.rs @@ -309,8 +309,7 @@ impl Pager { if let Some((ref cmd, ref filtered_content)) = self.filtered_content { match filtered_content { Ok(ref content) => { - copy_area( - grid, + grid.copy_area( content, area, ( @@ -371,8 +370,7 @@ impl Pager { } if get_y(upper_left) <= get_y(bottom_right) { - clear_area( - grid, + grid.clear_area( (upper_left, bottom_right), crate::conf::value(context, "theme_default"), ); @@ -530,7 +528,7 @@ impl Component for Pager { } } - clear_area(grid, area, crate::conf::value(context, "theme_default")); + grid.clear_area(area, crate::conf::value(context, "theme_default")); let (mut cols, mut rows) = (width!(area), height!(area)); let (has_more_lines, (width, height)) = if self.filtered_content.is_some() { (false, (self.width, self.height)) diff --git a/meli/src/utilities/tables.rs b/meli/src/utilities/tables.rs index 0f8c187a..ecb26a6a 100644 --- a/meli/src/utilities/tables.rs +++ b/meli/src/utilities/tables.rs @@ -266,8 +266,8 @@ impl DataColumns { } let mut column_area = bounds.add_x(column_width + 2); - copy_area( - grid, + + grid.copy_area( &self.columns[col], column_area.area(), ( @@ -281,14 +281,14 @@ impl DataColumns { let gap_area = column_area.add_x(column_width); match self.theme_config.theme { TableTheme::Single(row_attr) => { - change_theme(grid, gap_area.area(), row_attr); + grid.change_theme(gap_area.area(), row_attr); } TableTheme::EvenOdd { even, odd } => { - change_theme(grid, gap_area.area(), even); + grid.change_theme(gap_area.area(), even); let mut top_idx = top_idx; for row in gap_area { if top_idx % 2 != 0 { - change_theme(grid, row.area(), odd); + grid.change_theme(row.area(), odd); } top_idx += 1; } @@ -305,8 +305,7 @@ impl DataColumns { TableTheme::EvenOdd { even: _, odd } => odd, }; - change_theme( - grid, + grid.change_theme( ( pos_inc(upper_left!(total_area), (0, offset)), pos_inc(upper_left!(total_area), (width, offset)), diff --git a/meli/src/utilities/text.rs b/meli/src/utilities/text.rs index 00177c88..19b5398a 100644 --- a/meli/src/utilities/text.rs +++ b/meli/src/utilities/text.rs @@ -99,8 +99,8 @@ impl TextField { } else { self.inner.grapheme_pos() }; - change_colors( - grid, + + grid.change_colors( (pos_inc(upper_left, (pos, 0)), pos_inc(upper_left, (pos, 0))), crate::conf::value(context, "theme_default").fg, crate::conf::value(context, "highlight").bg, diff --git a/meli/src/utilities/widgets.rs b/meli/src/utilities/widgets.rs index f64f0de6..ca2d7363 100644 --- a/meli/src/utilities/widgets.rs +++ b/meli/src/utilities/widgets.rs @@ -352,8 +352,8 @@ impl Component for if self.is_dirty() { let theme_default = crate::conf::value(context, "theme_default"); - clear_area( - grid, + + grid.clear_area( ( upper_left, set_y(bottom_right, get_y(upper_left) + self.layout.len()), @@ -424,8 +424,8 @@ impl Component for } let length = self.layout.len(); - clear_area( - grid, + + grid.clear_area( ( pos_inc(upper_left, (0, length)), set_y(bottom_right, length + 2 + get_y(upper_left)), @@ -443,8 +443,7 @@ impl Component for ); } if length + 4 < height!(area) { - clear_area( - grid, + grid.clear_area( (pos_inc(upper_left, (0, length + 4)), bottom_right), theme_default, ); @@ -646,7 +645,7 @@ where fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { if self.dirty { let theme_default = crate::conf::value(context, "theme_default"); - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); let upper_left = upper_left!(area); let mut len = 0; @@ -786,9 +785,9 @@ impl Component for AutoComplete { let x_offset = if rows < self.entries.len() { 1 } else { 0 }; let (width, height) = self.content.size(); - clear_area(grid, area, crate::conf::value(context, "theme_default")); - copy_area( - grid, + grid.clear_area(area, crate::conf::value(context, "theme_default")); + + grid.copy_area( &self.content, (upper_left, pos_dec(bottom_right, (x_offset, 0))), ( @@ -799,8 +798,8 @@ impl Component for AutoComplete { /* Highlight cursor */ if self.cursor > 0 { let highlight = crate::conf::value(context, "highlight"); - change_theme( - grid, + + grid.change_theme( ( pos_inc(upper_left, (0, (self.cursor - 1) % rows)), ( @@ -971,7 +970,7 @@ impl ScrollBar { return; } let theme_default = crate::conf::value(context, "theme_default"); - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); let visible_rows = std::cmp::min(visible_rows, length); let ascii_drawing = grid.ascii_drawing; @@ -1027,7 +1026,7 @@ impl ScrollBar { return; } let theme_default = crate::conf::value(context, "theme_default"); - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); let visible_cols = std::cmp::min(visible_cols, length); let ascii_drawing = grid.ascii_drawing; @@ -1238,7 +1237,7 @@ impl std::fmt::Display for ProgressSpinner { impl Component for ProgressSpinner { fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { if self.dirty { - clear_area(grid, area, self.theme_attr); + grid.clear_area(area, self.theme_attr); if self.active { grid.write_string_to_grid( match self.kind.as_ref() { diff --git a/tools/src/embed.rs b/tools/src/embed.rs index 75b82daa..445355ed 100644 --- a/tools/src/embed.rs +++ b/tools/src/embed.rs @@ -120,9 +120,9 @@ impl Component for EmbedContainer { match embed_pty { EmbedStatus::Running(_) => { let mut guard = embed_pty.lock().unwrap(); - clear_area(grid, embed_area, theme_default); - copy_area( - grid, + grid.clear_area(embed_area, theme_default); + + grid.copy_area( guard.grid.buffer(), embed_area, ((0, 0), pos_dec(guard.grid.terminal_size, (1, 1))), @@ -134,14 +134,14 @@ impl Component for EmbedContainer { } EmbedStatus::Stopped(_) => { let guard = embed_pty.lock().unwrap(); - copy_area( - grid, + + grid.copy_area( guard.grid.buffer(), embed_area, ((0, 0), pos_dec(guard.grid.terminal_size, (1, 1))), ); - change_theme( - grid, + + grid.change_theme( embed_area, ThemeAttribute { fg: Color::Byte(8), @@ -170,7 +170,7 @@ impl Component for EmbedContainer { ), ), ); - clear_area(grid, inner_area, theme_default); + grid.clear_area(inner_area, theme_default); for (i, l) in [ stopped_message.as_str(), stopped_message_2.as_str(), @@ -195,7 +195,7 @@ impl Component for EmbedContainer { } } else { let theme_default = crate::conf::value(context, "theme_default"); - clear_area(grid, area, theme_default); + grid.clear_area(area, theme_default); self.embed_area = (upper_left!(area), bottom_right!(area)); match create_pty( width!(self.embed_area),