mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
put tui tools in separate file
This commit is contained in:
parent
783f2ddb1b
commit
ca672b3072
4 changed files with 34 additions and 33 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{clear::Clear, git_utils};
|
use crate::{clear::Clear, git_utils, tui_utils};
|
||||||
use crossterm::event::{Event, KeyCode};
|
use crossterm::event::{Event, KeyCode};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use tui::backend::Backend;
|
|
||||||
use tui::layout::{Alignment, Rect};
|
|
||||||
use tui::{
|
use tui::{
|
||||||
|
backend::Backend,
|
||||||
|
layout::{Alignment, Rect},
|
||||||
style::{Color, Style},
|
style::{Color, Style},
|
||||||
widgets::{Block, Borders, Paragraph, Text, Widget},
|
widgets::{Block, Borders, Paragraph, Text, Widget},
|
||||||
Frame,
|
Frame,
|
||||||
|
|
@ -55,7 +55,7 @@ impl UIElement for UICommit {
|
||||||
.block(Block::default().title("Commit").borders(Borders::ALL))
|
.block(Block::default().title("Commit").borders(Borders::ALL))
|
||||||
.alignment(Alignment::Left),
|
.alignment(Alignment::Left),
|
||||||
)
|
)
|
||||||
.render(f, git_utils::centered_rect(60, 20, f.size()));
|
.render(f, tui_utils::centered_rect(60, 20, f.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use git2::{DiffFormat, DiffOptions, Repository, StatusOptions, StatusShow};
|
use git2::{DiffFormat, DiffOptions, Repository, StatusOptions, StatusShow};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tui::layout::{Constraint, Direction, Layout, Rect};
|
|
||||||
|
|
||||||
///
|
///
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
|
|
@ -105,34 +104,6 @@ pub fn commit(msg: &String) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 {
|
|
||||||
let popup_layout = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints(
|
|
||||||
[
|
|
||||||
Constraint::Percentage((100 - percent_y) / 2),
|
|
||||||
Constraint::Percentage(percent_y),
|
|
||||||
Constraint::Percentage((100 - percent_y) / 2),
|
|
||||||
]
|
|
||||||
.as_ref(),
|
|
||||||
)
|
|
||||||
.split(r);
|
|
||||||
|
|
||||||
Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints(
|
|
||||||
[
|
|
||||||
Constraint::Percentage((100 - percent_x) / 2),
|
|
||||||
Constraint::Percentage(percent_x),
|
|
||||||
Constraint::Percentage((100 - percent_x) / 2),
|
|
||||||
]
|
|
||||||
.as_ref(),
|
|
||||||
)
|
|
||||||
.split(popup_layout[1])[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
pub fn index_empty() -> bool {
|
pub fn index_empty() -> bool {
|
||||||
let repo = repo();
|
let repo = repo();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ mod commit;
|
||||||
mod git_status;
|
mod git_status;
|
||||||
mod git_utils;
|
mod git_utils;
|
||||||
mod poll;
|
mod poll;
|
||||||
|
mod tui_utils;
|
||||||
|
|
||||||
use app::App;
|
use app::App;
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
|
|
|
||||||
29
src/tui_utils.rs
Normal file
29
src/tui_utils.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
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 {
|
||||||
|
let popup_layout = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Percentage((100 - percent_y) / 2),
|
||||||
|
Constraint::Percentage(percent_y),
|
||||||
|
Constraint::Percentage((100 - percent_y) / 2),
|
||||||
|
]
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.split(r);
|
||||||
|
|
||||||
|
Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Percentage((100 - percent_x) / 2),
|
||||||
|
Constraint::Percentage(percent_x),
|
||||||
|
Constraint::Percentage((100 - percent_x) / 2),
|
||||||
|
]
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.split(popup_layout[1])[1]
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue