diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2018-08-07 15:01:15 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:27 +0300 |
commit | c30f77a312b981c2269c63f12eab5602da1036dd (patch) | |
tree | 324db001556aeb791ad9602d49e92b02daf3754d /ui | |
parent | 43ad31d2ab28c94fdd6b6c36d841971bad93964a (diff) |
Run clippy and rustfmt
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/mail/listing.rs | 180 | ||||
-rw-r--r-- | ui/src/components/mail/mod.rs | 64 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 105 | ||||
-rw-r--r-- | ui/src/components/mod.rs | 8 | ||||
-rw-r--r-- | ui/src/components/notifications.rs | 38 | ||||
-rw-r--r-- | ui/src/components/utilities.rs | 100 | ||||
-rw-r--r-- | ui/src/execute/actions.rs | 30 | ||||
-rw-r--r-- | ui/src/execute/mod.rs | 98 | ||||
-rw-r--r-- | ui/src/lib.rs | 4 | ||||
-rw-r--r-- | ui/src/state.rs | 110 | ||||
-rw-r--r-- | ui/src/types/cells.rs | 50 | ||||
-rw-r--r-- | ui/src/types/helpers.rs | 23 | ||||
-rw-r--r-- | ui/src/types/keys.rs | 28 | ||||
-rw-r--r-- | ui/src/types/mod.rs | 23 | ||||
-rw-r--r-- | ui/src/types/position.rs | 66 |
15 files changed, 617 insertions, 310 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 01cd46cf..15c18e9c 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -1,8 +1,28 @@ +/* + * meli - ui crate. + * + * Copyright 2017-2018 Manos Pitsidianakis + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see <http://www.gnu.org/licenses/>. + */ + use super::*; const MAX_COLS: usize = 500; - /// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a /// `MailView`. pub struct MailListing { @@ -21,6 +41,12 @@ pub struct MailListing { view: Option<MailView>, } +impl Default for MailListing { + fn default() -> Self { + Self::new() + } +} + impl MailListing { /// Helper function to format entry strings for MailListing */ /* TODO: Make this configurable */ @@ -67,11 +93,9 @@ impl MailListing { // Get mailbox as a reference. // loop { - match context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) { - Ok(()) => { break; }, - Err(_) => { - // TODO: Show progress visually - } + // TODO: Show progress visually + if let Ok(()) = context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) { + break; } } let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1] @@ -92,7 +116,7 @@ impl MailListing { Color::Default, ((0, 0), (MAX_COLS - 1, 0)), true, - ); + ); self.content = content; return; } @@ -101,31 +125,29 @@ impl MailListing { if threaded { let mut indentations: Vec<bool> = Vec::with_capacity(6); let mut thread_idx = 0; // needed for alternate thread colors - /* Draw threaded view. */ + /* Draw threaded view. */ let mut local_collection: Vec<usize> = mailbox.threaded_collection.clone(); - let mut threads: Vec<&Container> = mailbox.threads.iter().map(|v| v).collect(); - local_collection.sort_by(|a, b| { - match self.sort { - (SortField::Date, SortOrder::Desc) => { - mailbox.thread(*b).date().cmp(&mailbox.thread(*a).date()) - }, - (SortField::Date, SortOrder::Asc) => { - mailbox.thread(*a).date().cmp(&mailbox.thread(*b).date()) - }, - (SortField::Subject, SortOrder::Desc) => { - let a = mailbox.thread(*a); - let b = mailbox.thread(*b); - let ma = &mailbox.collection[*a.message().as_ref().unwrap()]; - let mb = &mailbox.collection[*b.message().as_ref().unwrap()]; - ma.subject().cmp(&mb.subject()) - }, - (SortField::Subject, SortOrder::Asc) => { - let a = mailbox.thread(*a); - let b = mailbox.thread(*b); - let ma = &mailbox.collection[*a.message().as_ref().unwrap()]; - let mb = &mailbox.collection[*b.message().as_ref().unwrap()]; - mb.subject().cmp(&ma.subject()) - }, + let threads: &Vec<Container> = &mailbox.threads; + local_collection.sort_by(|a, b| match self.sort { + (SortField::Date, SortOrder::Desc) => { + mailbox.thread(*b).date().cmp(&mailbox.thread(*a).date()) + } + (SortField::Date, SortOrder::Asc) => { + mailbox.thread(*a).date().cmp(&mailbox.thread(*b).date()) + } + (SortField::Subject, SortOrder::Desc) => { + let a = mailbox.thread(*a); + let b = mailbox.thread(*b); + let ma = &mailbox.collection[*a.message().as_ref().unwrap()]; + let mb = &mailbox.collection[*b.message().as_ref().unwrap()]; + ma.subject().cmp(&mb.subject()) + } + (SortField::Subject, SortOrder::Asc) => { + let a = mailbox.thread(*a); + let b = mailbox.thread(*b); + let ma = &mailbox.collection[*a.message().as_ref().unwrap()]; + let mb = &mailbox.collection[*b.message().as_ref().unwrap()]; + mb.subject().cmp(&ma.subject()) } }); let mut iter = local_collection.iter().enumerate().peekable(); @@ -137,14 +159,14 @@ impl MailListing { .count(); /* This is just a desugared for loop so that we can use .peek() */ while let Some((idx, i)) = iter.next() { - let container = threads[*i]; + let container = &threads[*i]; let indentation = container.indentation(); if indentation == 0 { thread_idx += 1; } - assert!(container.has_message() == true); + assert!(container.has_message()); match iter.peek() { Some(&(_, x)) if threads[*x].indentation() == indentation => { indentations.pop(); @@ -180,13 +202,13 @@ impl MailListing { container, &indentations, len, - ), - &mut content, - fg_color, - bg_color, - ((0, idx), (MAX_COLS - 1, idx)), - false, - ); + ), + &mut content, + fg_color, + bg_color, + ((0, idx), (MAX_COLS - 1, idx)), + false, + ); for x in x..MAX_COLS { content[(x, idx)].set_ch(' '); content[(x, idx)].set_bg(bg_color); @@ -236,7 +258,7 @@ impl MailListing { bg_color, ((0, y), (MAX_COLS - 1, y)), false, - ); + ); for x in x..MAX_COLS { content[(x, y)].set_ch(' '); @@ -269,15 +291,19 @@ impl MailListing { } else { Color::Default }; - let bg_color = - if !envelope.is_seen() { - Color::Byte(251) - } else if idx % 2 == 0 { - Color::Byte(236) - } else { - Color::Default - }; - change_colors(&mut self.content, ((0, idx), (MAX_COLS-1, idx)), fg_color, bg_color); + let bg_color = if !envelope.is_seen() { + Color::Byte(251) + } else if idx % 2 == 0 { + Color::Byte(236) + } else { + Color::Default + }; + change_colors( + &mut self.content, + ((0, idx), (MAX_COLS - 1, idx)), + fg_color, + bg_color, + ); } fn highlight_line(&self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) { @@ -301,14 +327,12 @@ impl MailListing { }; let bg_color = if self.cursor_pos.2 == idx { Color::Byte(246) + } else if !envelope.is_seen() { + Color::Byte(251) + } else if idx % 2 == 0 { + Color::Byte(236) } else { - if !envelope.is_seen() { - Color::Byte(251) - } else if idx % 2 == 0 { - Color::Byte(236) - } else { - Color::Default - } + Color::Default }; change_colors(grid, area, fg_color, bg_color); } @@ -337,7 +361,7 @@ impl MailListing { if self.cursor_pos.2 != self.new_cursor_pos.2 && prev_page_no == page_no { let old_cursor_pos = self.cursor_pos; self.cursor_pos = self.new_cursor_pos; - for idx in [old_cursor_pos.2, self.new_cursor_pos.2].iter() { + for idx in &[old_cursor_pos.2, self.new_cursor_pos.2] { if *idx >= self.length { continue; //bounds check } @@ -370,8 +394,6 @@ impl MailListing { context, ); context.dirty_areas.push_back(area); - - } fn make_thread_entry( @@ -379,7 +401,7 @@ impl MailListing { idx: usize, indent: usize, container: &Container, - indentations: &Vec<bool>, + indentations: &[bool], idx_width: usize, ) -> String { let has_sibling = container.has_sibling(); @@ -508,10 +530,9 @@ impl Component for MailListing { } { /* TODO: Move the box drawing business in separate functions */ - if get_x(upper_left) > 0 { - if grid[(get_x(upper_left) - 1, mid)].ch() == VERT_BOUNDARY { - grid[(get_x(upper_left) - 1, mid)].set_ch(LIGHT_VERTICAL_AND_RIGHT); - } + if get_x(upper_left) > 0 && grid[(get_x(upper_left) - 1, mid)].ch() == VERT_BOUNDARY + { + grid[(get_x(upper_left) - 1, mid)].set_ch(LIGHT_VERTICAL_AND_RIGHT); } for i in get_x(upper_left)..=get_x(bottom_right) { @@ -524,17 +545,18 @@ impl Component for MailListing { // TODO: Make headers view configurable if !self.dirty { - self.view - .as_mut() - .map(|v| v.draw(grid, (set_y(upper_left, mid + 1), bottom_right), context)); + if let Some(v) = self.view.as_mut() { + v.draw(grid, (set_y(upper_left, mid + 1), bottom_right), context); + } return; } self.view = Some(MailView::new(self.cursor_pos, None, None)); - self.view - .as_mut() - .map(|v| v.draw(grid, (set_y(upper_left, mid + 1), bottom_right), context)); + self.view.as_mut().unwrap().draw( + grid, + (set_y(upper_left, mid + 1), bottom_right), + context, + ); self.dirty = false; - } } fn process_event(&mut self, event: &UIEvent, context: &mut Context) { @@ -551,11 +573,11 @@ impl Component for MailListing { self.dirty = true; } } - UIEventType::Input(Key::Char('\n')) if self.unfocused == false => { + UIEventType::Input(Key::Char('\n')) if !self.unfocused => { self.unfocused = true; self.dirty = true; } - UIEventType::Input(Key::Char('m')) if self.unfocused == false => { + UIEventType::Input(Key::Char('m')) if !self.unfocused => { use std::process::{Command, Stdio}; /* Kill input thread so that spawned command can be sole receiver of stdin */ { @@ -602,7 +624,7 @@ impl Component for MailListing { }); return; } - UIEventType::Input(Key::Char('i')) if self.unfocused == true => { + UIEventType::Input(Key::Char('i')) if self.unfocused => { self.unfocused = false; self.dirty = true; self.view = None; @@ -683,20 +705,20 @@ impl Component for MailListing { self.refresh_mailbox(context); self.dirty = true; return; - }, + } Action::ViewMailbox(idx) => { self.new_cursor_pos.1 = *idx; self.dirty = true; self.refresh_mailbox(context); return; - }, + } Action::Sort(field, order) => { self.sort = (field.clone(), order.clone()); self.dirty = true; self.refresh_mailbox(context); return; - }, - _ => {}, + } + _ => {} }, _ => {} } diff --git a/ui/src/components/mail/mod.rs b/ui/src/components/mail/mod.rs index 775c4f7b..b15b069a 100644 --- a/ui/src/components/mail/mod.rs +++ b/ui/src/components/mail/mod.rs @@ -1,3 +1,24 @@ +/* + * meli - ui crate. + * + * Copyright 2017-2018 Manos Pitsidianakis + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see <http://www.gnu.org/licenses/>. + */ + /*! Entities that handle Mail specific functions. */ use super::*; @@ -23,7 +44,7 @@ pub struct AccountMenu { } impl AccountMenu { - pub fn new(accounts: &Vec<Account>) -> Self { + pub fn new(accounts: &[Account]) -> Self { let accounts = accounts .iter() .enumerate() @@ -40,12 +61,18 @@ impl AccountMenu { }) .collect(); AccountMenu { - accounts: accounts, + accounts, dirty: true, cursor: None, } } - fn print_account(&self, grid: &mut CellBuffer, area: Area, a: &AccountMenuEntry, context: &mut Context) -> usize { + fn print_account( + &self, + grid: &mut CellBuffer, + area: Area, + a: &AccountMenuEntry, + context: &mut Context, + ) -> usize { if !is_valid_area!(area) { eprintln!("BUG: invalid area in print_account"); } @@ -70,7 +97,7 @@ impl AccountMenu { let mut inc = 0; let mut depth = String::from(""); - let mut s = String::from(format!("{}\n", a.name)); + let mut s = format!("{}\n", a.name); fn pop(depth: &mut String) { depth.pop(); depth.pop(); @@ -82,24 +109,33 @@ impl AccountMenu { fn print( root: usize, - parents: &Vec<Option<usize>>, + parents: &[Option<usize>], depth: &mut String, - entries: &Vec<(usize, Folder)>, + entries: &[(usize, Folder)], s: &mut String, inc: &mut usize, index: usize, //account index context: &mut Context, - ) -> () { + ) -> () { let len = s.len(); match context.accounts[index].status(root) { - Ok(()) => {}, + Ok(()) => {} Err(_) => { return; // TODO: Show progress visually } } - let count = context.accounts[index][root].as_ref().unwrap().collection.iter().filter(|e| !e.is_seen()).count(); - s.insert_str(len, &format!("{} {} {}\n ", *inc, &entries[root].1.name(), count)); + let count = context.accounts[index][root] + .as_ref() + .unwrap() + .collection + .iter() + .filter(|e| !e.is_seen()) + .count(); + s.insert_str( + len, + &format!("{} {} {}\n ", *inc, &entries[root].1.name(), count), + ); *inc += 1; let children_no = entries[root].1.children().len(); for (idx, child) in entries[root].1.children().iter().enumerate() { @@ -111,7 +147,9 @@ impl AccountMenu { } } for r in roots { - print(r, &parents, &mut depth, &a.entries, &mut s, &mut inc, a.index, context); + print( + r, &parents, &mut depth, &a.entries, &mut s, &mut inc, a.index, context, + ); } let lines: Vec<&str> = s.lines().collect(); @@ -125,9 +163,9 @@ impl AccountMenu { break; } let s = if idx == lines_len - 2 { - format!("{}", lines[idx].replace("├", "└")) + lines[idx].replace("├", "└") } else { - format!("{}", lines[idx]) + lines[idx].to_string() }; let (color_fg, color_bg) = if highlight { if idx > 1 && self.cursor.unwrap().1 == idx - 2 { diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 8c1a47cf..8a8c2212 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -1,3 +1,24 @@ +/* + * meli - ui crate. + * + * Copyright 2017-2018 Manos Pitsidianakis + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see <http://www.gnu.org/licenses/>. + */ + use super::*; use linkify::{Link, LinkFinder}; use std::process::{Command, Stdio}; @@ -40,9 +61,9 @@ impl MailView { subview: Option<Box<MailView>>, ) -> Self { MailView { - coordinates: coordinates, - pager: pager, - subview: subview, + coordinates, + pager, + subview, dirty: true, mode: ViewMode::Normal, @@ -73,9 +94,7 @@ impl Component for MailView { if self.mode == ViewMode::Raw { clear_area(grid, area); - context - .dirty_areas - .push_back(area); + context.dirty_areas.push_back(area); (envelope_idx, get_y(upper_left) - 1) } else { let (x, y) = write_string_to_grid( @@ -85,7 +104,7 @@ impl Component for MailView { Color::Default, area, true, - ); + ); for x in x..=get_x(bottom_right) { grid[(x, y)].set_ch(' '); grid[(x, y)].set_bg(Color::Default); @@ -98,7 +117,7 @@ impl Component for MailView { Color::Default, (set_y(upper_left, y + 1), bottom_right), true, - ); + ); for x in x..=get_x(bottom_right) { grid[(x, y)].set_ch(' '); grid[(x, y)].set_bg(Color::Default); @@ -111,7 +130,7 @@ impl Component for MailView { Color::Default, (set_y(upper_left, y + 1), bottom_right), true, - ); + ); for x in x..=get_x(bottom_right) { grid[(x, y)].set_ch(' '); grid[(x, y)].set_bg(Color::Default); @@ -124,7 +143,7 @@ impl Component for MailView { Color::Default, (set_y(upper_left, y + 1), bottom_right), true, - ); + ); for x in x..=get_x(bottom_right) { grid[(x, y)].set_ch(' '); grid[(x, y)].set_bg(Color::Default); @@ -137,7 +156,7 @@ impl Component for MailView { Color::Default, (set_y(upper_left, y + 1), bottom_right), true, - ); + ); for x in x..=get_x(bottom_right) { grid[(x, y)].set_ch(' '); grid[(x, y)].set_bg(Color::Default); @@ -174,9 +193,7 @@ impl Component for MailView { } t } - ViewMode::Raw => { - String::from_utf8_lossy(&envelope.bytes()).into_owned() - }, + ViewMode::Raw => String::from_utf8_lossy(&envelope.bytes()).into_owned(), ViewMode::Url => { let mut t = envelope.body().text().to_string(); for (lidx, l) in finder.links(&envelope.body().text()).enumerate() { @@ -195,28 +212,25 @@ impl Component for MailView { } ViewMode::Attachment(aidx) => { let attachments = envelope.body().attachments(); - let mut ret = format!("Viewing attachment. Press `r` to return \n"); + let mut ret = "Viewing attachment. Press `r` to return \n".to_string(); ret.push_str(&attachments[aidx].text()); ret } }; let mut buf = CellBuffer::from(&text); - match self.mode { - ViewMode::Url => { - // URL indexes must be colored (ugh..) - let lines: Vec<&str> = text.split('\n').collect(); - let mut shift = 0; - for r in lines.iter() { - for l in finder.links(&r) { - buf[(l.start() + shift - 1, 0)].set_fg(Color::Byte(226)); - buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226)); - buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226)); - } - // Each Cell represents one char so next line will be: - shift += r.chars().count() + 1; + if self.mode == ViewMode::Url { + // URL indexes must be colored (ugh..) + let lines: Vec<&str> = text.split('\n').collect(); + let mut shift = 0; + for r in &lines { + for l in finder.links(&r) { + buf[(l.start() + shift - 1, 0)].set_fg(Color::Byte(226)); + buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226)); + buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226)); } + // Each Cell represents one char so next line will be: + shift += r.chars().count() + 1; } - _ => {} } buf }; @@ -225,12 +239,13 @@ impl Component for MailView { } else { self.pager.as_mut().map(|p| p.cursor_pos()) }; - self.pager = Some(Pager::from_buf(buf, cursor_pos)); + self.pager = Some(Pager::from_buf(&buf, cursor_pos)); self.dirty = false; } - self.pager - .as_mut() - .map(|p| p.draw(grid, (set_y(upper_left, y + 1), bottom_right), context)); + + if let Some(p) = self.pager.as_mut() { + p.draw(grid, (set_y(upper_left, y + 1), bottom_right), context); + } } fn process_event(&mut self, event: &UIEvent, context: &mut Context) { @@ -241,7 +256,9 @@ impl Component for MailView { UIEventType::Input(Key::Char(c)) if c >= '0' && c <= '9' => { self.cmd_buf.push(c); } - UIEventType::Input(Key::Char('r')) if self.mode == ViewMode::Normal || self.mode == ViewMode::Raw => { + UIEventType::Input(Key::Char('r')) + if self.mode == ViewMode::Normal || self.mode == ViewMode::Raw => + { self.mode = if self.mode == ViewMode::Raw { ViewMode::Normal } else { @@ -254,7 +271,7 @@ impl Component for MailView { self.dirty = true; } UIEventType::Input(Key::Char('a')) - if self.cmd_buf.len() > 0 && self.mode == ViewMode::Normal => + if !self.cmd_buf.is_empty() && self.mode == ViewMode::Normal => { let lidx = self.cmd_buf.parse::<usize>().unwrap(); self.cmd_buf.clear(); @@ -282,9 +299,9 @@ impl Component for MailView { ContentType::Multipart { .. } => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "Multipart attachments are not supported yet." - )), + event_type: UIEventType::StatusNotification( + "Multipart attachments are not supported yet.".to_string(), + ), }); return; } @@ -298,7 +315,9 @@ impl Component for MailView { .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() - .expect(&format!("Failed to start {}", binary.display())); + .unwrap_or_else(|_| { + panic!("Failed to start {}", binary.display()) + }); } else { context.replies.push_back(UIEvent { id: 0, @@ -324,7 +343,7 @@ impl Component for MailView { }; } UIEventType::Input(Key::Char('g')) - if self.cmd_buf.len() > 0 && self.mode == ViewMode::Url => + if !self.cmd_buf.is_empty() && self.mode == ViewMode::Url => { let lidx = self.cmd_buf.parse::<usize>().unwrap(); self.cmd_buf.clear(); @@ -378,10 +397,8 @@ impl Component for MailView { } if let Some(ref mut sub) = self.subview { sub.process_event(event, context); - } else { - if let Some(ref mut p) = self.pager { - p.process_event(event, context); - } + } else if let Some(ref mut p) = self.pager { + p.process_event(event, context); } } fn is_dirty(&self) -> bool { diff --git a/ui/src/components/mod.rs b/ui/src/components/mod.rs index c900d1e2..490c6f1c 100644 --- a/ui/src/components/mod.rs +++ b/ui/src/components/mod.rs @@ -1,5 +1,5 @@ /* - * meli - ui module. + * meli - ui crate. * * Copyright 2017-2018 Manos Pitsidianakis * @@ -35,7 +35,6 @@ pub mod notifications; pub mod utilities; pub use self::utilities::*; - use super::{Key, UIEvent, UIEventType}; /// The upper and lower boundary char. const HORZ_BOUNDARY: char = '─'; @@ -140,11 +139,8 @@ pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, let mut src_y = get_y(upper_left!(src)); let (cols, rows) = grid_src.size(); if src_x >= cols || src_y >= rows { - eprintln!( - "DEBUG: src area outside of grid_src in copy_area", - ); + eprintln!("DEBUG: src area outside of grid_src in copy_area",); return; - } for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) { diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs index 7c394281..1478420b 100644 --- a/ui/src/components/notifications.rs +++ b/ui/src/components/notifications.rs @@ -1,3 +1,24 @@ +/* + * meli - ui crate. + * + * Copyright 2017-2018 Manos Pitsidianakis + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see <http://www.gnu.org/licenses/>. + */ + /*! Notification handling components. */ @@ -11,16 +32,13 @@ pub struct XDGNotifications {} impl Component for XDGNotifications { fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {} fn process_event(&mut self, event: &UIEvent, _context: &mut Context) { - match event.event_type { - UIEventType::Notification(ref t) => { - notify_Notification::new() - .summary("Refresh Event") - .body(t) - .icon("dialog-information") - .show() - .unwrap(); - } - _ => {} + if let UIEventType::Notification(ref t) = event.event_type { + notify_Notification::new() + .summary("Refresh Event") + .body(t) + .icon("dialog-information") + .show() + .unwrap(); } } } diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index f28ddf05..e41d8826 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -1,3 +1,24 @@ +/* + * meli - ui crate. + * + * Copyright 2017-2018 Manos Pitsidianakis + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see <http://www.gnu.org/licenses/>. + */ + /*! Various useful components that can be used in a generic fashion. */ use super::*; @@ -13,10 +34,10 @@ pub struct HSplit { impl HSplit { pub fn new(top: Entity, bottom: Entity, ratio: usize, show_divider: bool) -> Self { HSplit { - top: top, - bottom: bottom, - show_divider: show_divider, - ratio: ratio, + top, + bottom, + show_divider, + ratio, } } } @@ -37,7 +58,7 @@ impl Component for HSplit { grid[(i, mid)].set_ch('─'); } } - let _ = self.top.component.draw( + self.top.component.draw( grid, ( upper_left, @@ -45,7 +66,7 @@ impl Component for HSplit { ), context, ); - let _ = self.bottom.component.draw( + self.bottom.component.draw( grid, ((get_x(upper_left), get_y(upper_left) + mid), bottom_right), context, @@ -72,10 +93,10 @@ pub struct VSplit { impl VSplit { pub fn new(left: Ent |