mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
show index items separately
This commit is contained in:
parent
27045b64cd
commit
6baf16355c
1 changed files with 40 additions and 21 deletions
61
src/app.rs
61
src/app.rs
|
|
@ -1,20 +1,21 @@
|
|||
use crossterm::event::{Event, KeyCode};
|
||||
use git2::{DiffFormat, Repository};
|
||||
use git2::{DiffFormat, Repository, Status};
|
||||
use std::cmp;
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
layout::{Constraint, Direction, Layout, Rect, Alignment},
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
widgets::{Block, Borders, SelectableList, Widget, Paragraph, Text},
|
||||
widgets::{Block, Borders, Paragraph, SelectableList, Text, Widget},
|
||||
Frame,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct App {
|
||||
status_items: Vec<String>,
|
||||
index_items: Vec<String>,
|
||||
status_select: Option<usize>,
|
||||
diff: String,
|
||||
offset:u16,
|
||||
offset: u16,
|
||||
do_quit: bool,
|
||||
}
|
||||
|
||||
|
|
@ -33,19 +34,29 @@ impl App {
|
|||
Err(e) => panic!("failed to init: {}", e),
|
||||
};
|
||||
|
||||
// println!("state: {:?}",repo.state());
|
||||
// println!("path: {:?}",repo.path());
|
||||
|
||||
if repo.is_bare() {
|
||||
panic!("bare repo")
|
||||
}
|
||||
|
||||
let status = repo.statuses(None).unwrap();
|
||||
let statuses = repo.statuses(None).unwrap();
|
||||
|
||||
self.status_items = status
|
||||
.iter()
|
||||
.map(|e| e.path().unwrap().to_string())
|
||||
.collect();
|
||||
self.status_items = Vec::new();
|
||||
self.index_items= Vec::new();
|
||||
|
||||
for e in statuses.iter() {
|
||||
let status: Status = e.status();
|
||||
if status.is_ignored() {continue;}
|
||||
|
||||
if status.is_index_new() || status.is_index_modified() {
|
||||
self.index_items
|
||||
.push(format!("{} ({:?})", e.path().unwrap().to_string(), status))
|
||||
}
|
||||
|
||||
if status.is_wt_new() || status.is_wt_modified() {
|
||||
self.status_items
|
||||
.push(format!("{} ({:?})", e.path().unwrap().to_string(), status))
|
||||
}
|
||||
}
|
||||
|
||||
self.status_select = if self.status_items.len() > 0 {
|
||||
Some(0)
|
||||
|
|
@ -85,25 +96,33 @@ impl App {
|
|||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||
.split(f.size());
|
||||
|
||||
let left_chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||
.split(chunks[0]);
|
||||
|
||||
draw_list(
|
||||
f,
|
||||
chunks[0],
|
||||
left_chunks[0],
|
||||
"Status".to_string(),
|
||||
self.status_items.as_slice(),
|
||||
self.status_select,
|
||||
);
|
||||
|
||||
draw_list(
|
||||
f,
|
||||
left_chunks[1],
|
||||
"Index".to_string(),
|
||||
self.index_items.as_slice(),
|
||||
None,
|
||||
);
|
||||
|
||||
Paragraph::new([Text::raw(self.diff.clone())].iter())
|
||||
.block(Block::default().title("Diff").borders(Borders::ALL))
|
||||
.style(Style::default().fg(Color::White).bg(Color::Black))
|
||||
.alignment(Alignment::Left)
|
||||
.scroll(self.offset)
|
||||
.render(f, chunks[1]);
|
||||
|
||||
// Block::default()
|
||||
// .title("Diff")
|
||||
// .borders(Borders::ALL)
|
||||
// .render(f, chunks[1]);
|
||||
}
|
||||
|
||||
///
|
||||
|
|
@ -120,11 +139,11 @@ impl App {
|
|||
}
|
||||
|
||||
if ev == Event::Key(KeyCode::PageDown.into()) {
|
||||
self.offset+=1;
|
||||
self.offset += 1;
|
||||
}
|
||||
if ev == Event::Key(KeyCode::PageUp.into()) {
|
||||
if self.offset>0{
|
||||
self.offset-=1;
|
||||
if self.offset > 0 {
|
||||
self.offset -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue