mirror of
https://github.com/gitui-org/gitui
synced 2026-05-22 08:29:20 +00:00
formating to shorter lines
This commit is contained in:
parent
ca672b3072
commit
ecdfef6d45
7 changed files with 88 additions and 26 deletions
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
max_width=70
|
||||
71
src/app.rs
71
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::<Vec<_>>();
|
||||
|
||||
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<B: Backend>(&self, f: &mut Frame<B>, r: Rect, cmds: Vec<CommandInfo>) {
|
||||
let splitter = Text::Styled(Cow::from(" "), Style::default().bg(Color::Black));
|
||||
fn draw_commands<B: Backend>(
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
r: Rect,
|
||||
cmds: Vec<CommandInfo>,
|
||||
) {
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue