diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..a3ae0072 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width=70 \ No newline at end of file diff --git a/src/app.rs b/src/app.rs index c9e8a7fc..9dd65e12 100644 --- a/src/app.rs +++ b/src/app.rs @@ -12,7 +12,9 @@ use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, - widgets::{Block, Borders, Paragraph, SelectableList, Tabs, Text, Widget}, + widgets::{ + Block, Borders, Paragraph, SelectableList, Tabs, Text, Widget, + }, Frame, }; @@ -54,7 +56,9 @@ impl App { /// fn update_diff(&mut self) { let new_diff = match self.status_select { - Some(i) => git_utils::get_diff(Path::new(self.status.wt_items[i].path.as_str())), + Some(i) => git_utils::get_diff(Path::new( + self.status.wt_items[i].path.as_str(), + )), None => Diff::default(), }; @@ -88,12 +92,24 @@ impl App { let chunks = Layout::default() .direction(Direction::Horizontal) - .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .constraints( + [ + Constraint::Percentage(50), + Constraint::Percentage(50), + ] + .as_ref(), + ) .split(chunks_main[1]); let left_chunks = Layout::default() .direction(Direction::Vertical) - .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .constraints( + [ + Constraint::Percentage(50), + Constraint::Percentage(50), + ] + .as_ref(), + ) .split(chunks[0]); draw_list( @@ -123,11 +139,15 @@ impl App { match e.line_type { DiffLineType::Delete => Text::Styled( content.into(), - Style::default().fg(Color::Red).bg(Color::Black), + Style::default() + .fg(Color::Red) + .bg(Color::Black), ), DiffLineType::Add => Text::Styled( content.into(), - Style::default().fg(Color::Green).bg(Color::Black), + Style::default() + .fg(Color::Green) + .bg(Color::Black), ), DiffLineType::Header => Text::Styled( content.into(), @@ -142,7 +162,11 @@ impl App { .collect::>(); Paragraph::new(txt.iter()) - .block(Block::default().title("Diff [d]").borders(Borders::ALL)) + .block( + Block::default() + .title("Diff [d]") + .borders(Borders::ALL), + ) .alignment(Alignment::Left) .scroll(self.offset) .render(f, chunks[1]); @@ -179,7 +203,8 @@ impl App { } if !self.commit.is_visible() { - if ev == Event::Key(KeyCode::Esc.into()) || ev == Event::Key(KeyCode::Char('q').into()) + if ev == Event::Key(KeyCode::Esc.into()) + || ev == Event::Key(KeyCode::Char('q').into()) { self.do_quit = true; } @@ -197,7 +222,8 @@ impl App { if ev == Event::Key(KeyCode::PageUp.into()) { self.scroll(false); } - if let Event::Mouse(MouseEvent::ScrollDown(_, _, _)) = ev { + if let Event::Mouse(MouseEvent::ScrollDown(_, _, _)) = ev + { self.scroll(true); } if let Event::Mouse(MouseEvent::ScrollUp(_, _, _)) = ev { @@ -210,12 +236,22 @@ impl App { } } - fn draw_commands(&self, f: &mut Frame, r: Rect, cmds: Vec) { - let splitter = Text::Styled(Cow::from(" "), Style::default().bg(Color::Black)); + fn draw_commands( + &self, + f: &mut Frame, + r: Rect, + cmds: Vec, + ) { + let splitter = Text::Styled( + Cow::from(" "), + Style::default().bg(Color::Black), + ); - let style_enabled = Style::default().fg(Color::White).bg(Color::Blue); + let style_enabled = + Style::default().fg(Color::White).bg(Color::Blue); - let style_disabled = Style::default().fg(Color::DarkGray).bg(Color::Blue); + let style_disabled = + Style::default().fg(Color::DarkGray).bg(Color::Blue); let texts = cmds .iter() .map(|c| { @@ -246,7 +282,8 @@ impl App { let mut index = repo.index().unwrap(); - let path = Path::new(self.status.wt_items[i].path.as_str()); + let path = + Path::new(self.status.wt_items[i].path.as_str()); let cb = &mut |p: &Path, _matched_spec: &[u8]| -> i32 { if p == path { @@ -258,7 +295,8 @@ impl App { if let Ok(_) = index.add_all( path, - IndexAddOption::DISABLE_PATHSPEC_MATCH | IndexAddOption::CHECK_PATHSPEC, + IndexAddOption::DISABLE_PATHSPEC_MATCH + | IndexAddOption::CHECK_PATHSPEC, Some(cb as &mut git2::IndexMatchedPath), ) { index.write().unwrap(); @@ -269,7 +307,8 @@ impl App { fn scroll(&mut self, inc: bool) { if inc { - self.offset = self.offset.checked_add(1).unwrap_or(self.offset); + self.offset = + self.offset.checked_add(1).unwrap_or(self.offset); } else { self.offset = self.offset.checked_sub(1).unwrap_or(0); } diff --git a/src/commit.rs b/src/commit.rs index 3b1b24c7..a897368e 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -52,7 +52,11 @@ impl UIElement for UICommit { Clear::new( Paragraph::new(txt.iter()) - .block(Block::default().title("Commit").borders(Borders::ALL)) + .block( + Block::default() + .title("Commit") + .borders(Borders::ALL), + ) .alignment(Alignment::Left), ) .render(f, tui_utils::centered_rect(60, 20, f.size())); diff --git a/src/git_status.rs b/src/git_status.rs index 8456f20a..92cd75f8 100644 --- a/src/git_status.rs +++ b/src/git_status.rs @@ -69,7 +69,9 @@ impl StatusLists { let status: Status = e.status(); let path = if let Some(diff) = e.head_to_index() { - String::from(diff.new_file().path().unwrap().to_str().unwrap()) + String::from( + diff.new_file().path().unwrap().to_str().unwrap(), + ) } else { e.path().unwrap().to_string() }; diff --git a/src/git_utils.rs b/src/git_utils.rs index ecfc4298..6dd0ad77 100644 --- a/src/git_utils.rs +++ b/src/git_utils.rs @@ -1,4 +1,6 @@ -use git2::{DiffFormat, DiffOptions, Repository, StatusOptions, StatusShow}; +use git2::{ + DiffFormat, DiffOptions, Repository, StatusOptions, StatusShow, +}; use std::path::Path; /// @@ -34,7 +36,8 @@ pub fn get_diff(p: &Path) -> Diff { let mut opt = DiffOptions::new(); opt.pathspec(p); - let diff = repo.diff_index_to_workdir(None, Some(&mut opt)).unwrap(); + let diff = + repo.diff_index_to_workdir(None, Some(&mut opt)).unwrap(); let mut res = Vec::new(); @@ -50,7 +53,8 @@ pub fn get_diff(p: &Path) -> Diff { }; let diff_line = DiffLine { - content: String::from_utf8_lossy(line.content()).to_string(), + content: String::from_utf8_lossy(line.content()) + .to_string(), line_type, }; @@ -91,7 +95,8 @@ pub fn commit(msg: &String) { let tree_id = index.write_tree().unwrap(); let tree = repo.find_tree(tree_id).unwrap(); - let parent = repo.find_commit(reference.target().unwrap()).unwrap(); + let parent = + repo.find_commit(reference.target().unwrap()).unwrap(); repo.commit( Some("HEAD"), @@ -109,7 +114,9 @@ pub fn index_empty() -> bool { let repo = repo(); let statuses = repo - .statuses(Some(StatusOptions::default().show(StatusShow::Index))) + .statuses(Some( + StatusOptions::default().show(StatusShow::Index), + )) .unwrap(); statuses.is_empty() diff --git a/src/main.rs b/src/main.rs index d658f2a0..c72c7f94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,10 @@ mod tui_utils; use app::App; use crossterm::{ event::{DisableMouseCapture, EnableMouseCapture}, - terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, + terminal::{ + disable_raw_mode, enable_raw_mode, EnterAlternateScreen, + LeaveAlternateScreen, + }, ExecutableCommand, Result, }; use poll::PollResult; @@ -36,7 +39,9 @@ fn main() -> Result<()> { terminal.draw(|mut f| app.draw(&mut f))?; loop { - if let PollResult::Event(e) = poll::poll(Duration::from_millis(10)) { + if let PollResult::Event(e) = + poll::poll(Duration::from_millis(10)) + { app.event(e); } else { break; diff --git a/src/tui_utils.rs b/src/tui_utils.rs index 2b557946..abe5b282 100644 --- a/src/tui_utils.rs +++ b/src/tui_utils.rs @@ -2,7 +2,11 @@ use tui::layout::{Constraint, Direction, Layout, Rect}; /// use layouts to create a rects that /// centers inside `r` and sizes `percent_x`/`percent_x` of `r` -pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect { +pub fn centered_rect( + percent_x: u16, + percent_y: u16, + r: Rect, +) -> Rect { let popup_layout = Layout::default() .direction(Direction::Vertical) .constraints(