summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTim Oram <mitmaro@gmail.com>2017-11-21 20:38:01 -0330
committerTim Oram <mitmaro@gmail.com>2017-11-21 20:46:05 -0330
commit478ed4d0b8ed8e9789da6d8c9e3a80994d8b717d (patch)
treec9c347d994b471a1ebd2ae0b6e46065de026a10d /src
parent843954248d312149f13235146f2fa6de44284550 (diff)
Integrate and fix clippy errors
Diffstat (limited to 'src')
-rw-r--r--src/application.rs6
-rw-r--r--src/main.rs18
-rw-r--r--src/mocks.rs16
-rw-r--r--src/utils.rs14
-rw-r--r--src/window.rs54
5 files changed, 48 insertions, 60 deletions
diff --git a/src/application.rs b/src/application.rs
index 0bc40de..4d218e6 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -26,8 +26,8 @@ pub struct Application {
impl Application {
pub fn new(git_interactive: GitInteractive, window: Window) -> Self {
Application {
- git_interactive: git_interactive,
- window: window,
+ git_interactive,
+ window,
exit_code: None,
state: State::List
}
@@ -173,7 +173,7 @@ mod tests {
fn application_read_all_actions() {
let gi = GitInteractive::new_from_filepath("test/git-rebase-todo-all-actions.in").unwrap();
let window = Window::new();
- let mut app = Application::new(gi, window);
+ let app = Application::new(gi, window);
assert_eq!(app.git_interactive.get_lines().len(), 12);
}
diff --git a/src/main.rs b/src/main.rs
index 5a21829..918cc95 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,9 @@
// TODO:
// - Add execute command
+
+#![cfg_attr(feature="clippy", feature(plugin))]
+#![cfg_attr(feature="clippy", plugin(clippy))]
+
extern crate pancurses;
extern crate pad;
@@ -11,8 +15,6 @@ mod action;
mod application;
mod git_interactive;
mod line;
-#[macro_use]
-mod utils;
mod window;
#[cfg(test)]
mod mocks;
@@ -26,24 +28,24 @@ fn main() {
let filepath = match env::args().nth(1) {
Some(filepath) => filepath,
None => {
- print_err!(
+ eprintln!(
"Must provide a filepath.\n\n\
Usage: git-interactive <filepath>"
);
- process::exit(1);
+ process::exit(1)
}
};
let git_interactive = match GitInteractive::new_from_filepath(&filepath) {
Ok(gi) => gi,
Err(msg) => {
- print_err!("{}", msg);
- process::exit(1);
+ eprintln!("{}", msg);
+ process::exit(1)
}
};
if git_interactive.get_lines().is_empty() {
- print_err!("{}", &"Nothing to rebase");
+ eprintln!("{}", &"Nothing to rebase");
process::exit(0);
}
@@ -59,7 +61,7 @@ fn main() {
match application.end() {
Ok(_) => {},
Err(msg) => {
- print_err!("{}", msg);
+ eprintln!("{}", msg);
process::exit(1);
}
};
diff --git a/src/mocks.rs b/src/mocks.rs
index e7bac7a..50d2099 100644
--- a/src/mocks.rs
+++ b/src/mocks.rs
@@ -23,14 +23,14 @@ pub mod mockcurses {
next_char: Input::KeyClear
}
}
- pub fn curs_set(visibility: i32) {}
+ pub fn curs_set(_visibility: i32) {}
pub fn noecho() {}
pub fn has_colors() -> bool {
false
}
pub fn start_color() {}
pub fn use_default_colors() {}
- pub fn init_pair(pair_index: i16, foreground_color: i16, background_color: i16) {}
+ pub fn init_pair(_pair_index: i16, _foreground_color: i16, _background_color: i16) {}
pub fn endwin() {}
#[derive(Debug)]
@@ -40,15 +40,15 @@ pub mod mockcurses {
}
impl Window {
- pub fn addstr(&self, string: &str) {}
- pub fn attron(&self, attributes: chtype) {}
- pub fn attroff(&self, attributes: chtype) {}
- pub fn attrset(&self, attributes: chtype) {}
- pub fn mvaddstr(&self, y: i32, x: i32, string: &str) {}
+ pub fn addstr(&self, _string: &str) {}
+ pub fn attron(&self, _attributes: chtype) {}
+ pub fn attroff(&self, _attributes: chtype) {}
+ pub fn attrset(&self, _attributes: chtype) {}
+ pub fn mvaddstr(&self, _y: i32, _x: i32, _string: &str) {}
pub fn clear(&self) {}
pub fn get_max_y(&self) -> i32 {self.max_y}
pub fn getch(&self) -> Option<Input> {Some(self.next_char)}
- pub fn keypad(&self, a: bool) {}
+ pub fn keypad(&self, _a: bool) {}
pub fn refresh(&self) {}
}
diff --git a/src/utils.rs b/src/utils.rs
deleted file mode 100644
index 28affca..0000000
--- a/src/utils.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-macro_rules! print_err {
- ($($arg:tt)*) => (
- {
- use std::io::prelude::*;
- if let Err(e) = write!(&mut ::std::io::stderr(), "{}\n", format_args!($($arg)*)) {
- panic!(
- "Failed to write to stderr.\n\
- Original error output: {}\n\
- Secondary error writing to stderr: {}", format!($($arg)*), e
- );
- }
- }
- )
-}
diff --git a/src/window.rs b/src/window.rs
index c7ad577..d68789c 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -100,7 +100,7 @@ impl Window {
}
fn draw_more_indicator(&self, remaining: usize) {
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.window.attron(pancurses::A_DIM);
self.window.attron(pancurses::A_REVERSE);
self.window.addstr(&format!(" -- {} -- ", remaining));
@@ -109,7 +109,7 @@ impl Window {
}
fn draw_title(&self) {
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.set_dim(true);
self.set_underline(true);
self.window.addstr("Git Interactive Rebase ? for help\n");
@@ -118,7 +118,7 @@ impl Window {
}
fn draw_line(&self, line: &Line, selected: bool) {
- self.set_color(Color::White);
+ self.set_color(&Color::White);
if selected {
self.window.addstr(" > ");
}
@@ -126,20 +126,20 @@ impl Window {
self.window.addstr(" ");
}
match *line.get_action() {
- Action::Pick => self.set_color(Color::Green),
- Action::Reword => self.set_color(Color::Yellow),
- Action::Edit => self.set_color(Color::Blue),
- Action::Squash => self.set_color(Color::Cyan),
- Action::Fixup => self.set_color(Color::Magenta),
- Action::Drop => self.set_color(Color::Red)
+ Action::Pick => self.set_color(&Color::Green),
+ Action::Reword => self.set_color(&Color::Yellow),
+ Action::Edit => self.set_color(&Color::Blue),
+ Action::Squash => self.set_color(&Color::Cyan),
+ Action::Fixup => self.set_color(&Color::Magenta),
+ Action::Drop => self.set_color(&Color::Red)
}
- self.window.addstr(&format!("{:6}", action_to_str(&line.get_action())));
- self.set_color(Color::White);
+ self.window.addstr(&format!("{:6}", action_to_str(line.get_action())));
+ self.set_color(&Color::White);
self.window.addstr(&format!(" {} {}\n", line.get_hash(), line.get_comment()));
}
fn draw_footer(&self) {
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.set_dim(true);
self.window.mvaddstr(
self.window.get_max_y() - 1,
@@ -165,12 +165,12 @@ impl Window {
self.draw_title();
match result {
Ok(output) => {
- self.set_color(Color::White);
+ self.set_color(&Color::White);
match Commit::new(&String::from_utf8_lossy(&output.stdout)) {
Ok(commit_data) => {
- self.set_color(Color::Yellow);
+ self.set_color(&Color::Yellow);
self.window.addstr(&format!("\nCommit: {}\n", commit));
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.window.addstr(&format!(
"Author: {} <{}>\n", commit_data.get_author_name(), commit_data.get_author_email()
));
@@ -195,32 +195,32 @@ impl Window {
.fold(0, |a, x| cmp::max(a, x.get_added().len()));
for file_stat in commit_data.get_file_stats() {
- self.set_color(Color::Green);
+ self.set_color(&Color::Green);
self.window.addstr(
&file_stat.get_added().pad_to_width_with_alignment(max_add_change_length, Alignment::Right)
);
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.window.addstr(" | ");
- self.set_color(Color::Red);
+ self.set_color(&Color::Red);
self.window.addstr(
&file_stat.get_removed().pad_to_width_with_alignment(max_remove_change_length, Alignment::Left)
);
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.window.addstr(&format!(" {}\n", &file_stat.get_name()));
}
},
Err(msg) => {
- self.set_color(Color::Red);
+ self.set_color(&Color::Red);
self.window.addstr(&msg);
}
}
},
Err(msg) => {
- self.set_color(Color::Red);
+ self.set_color(&Color::Red);
self.window.addstr(msg.description());
}
}
- self.set_color(Color::Yellow);
+ self.set_color(&Color::Yellow);
self.window.addstr("\n\nHit any key to close");
self.window.refresh();
}
@@ -228,7 +228,7 @@ impl Window {
pub fn draw_help(&self) {
self.window.clear();
self.draw_title();
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.window.addstr("\n Key Action\n");
self.window.addstr(" --------------------------------------------------\n");
self.draw_help_command("Up", "Move selection up");
@@ -254,14 +254,14 @@ impl Window {
}
fn draw_help_command(&self, command: &str, help: &str) {
- self.set_color(Color::Blue);
+ self.set_color(&Color::Blue);
self.window.addstr(&format!(" {:9} ", command));
- self.set_color(Color::White);
+ self.set_color(&Color::White);
self.window.addstr(&format!("{}\n", help));
}
- fn set_color(&self, color: Color) {
- match color {
+ fn set_color(&self, color: &Color) {
+ match *color {
Color::White => self.window.attrset(pancurses::COLOR_PAIR(0)),
Color::Yellow => self.window.attrset(pancurses::COLOR_PAIR(1)),
Color::Blue => self.window.attrset(pancurses::COLOR_PAIR(2)),