mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-23 11:42:56 +03:00
put components into seperate mod
This commit is contained in:
parent
ecdfef6d45
commit
c2a80225ae
@ -1,6 +1,5 @@
|
||||
use crate::commit::CommandInfo;
|
||||
use crate::commit::{UICommit, UIElement};
|
||||
use crate::{
|
||||
components::{commit::CommitComponent, CommandInfo, Component},
|
||||
git_status::StatusLists,
|
||||
git_utils::{self, Diff, DiffLine, DiffLineType},
|
||||
};
|
||||
@ -25,7 +24,7 @@ pub struct App {
|
||||
diff: Diff,
|
||||
offset: u16,
|
||||
do_quit: bool,
|
||||
commit: UICommit,
|
||||
commit: CommitComponent,
|
||||
}
|
||||
|
||||
impl App {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use super::{CommandInfo, Component};
|
||||
use crate::{clear::Clear, git_utils, tui_utils};
|
||||
use crossterm::event::{Event, KeyCode};
|
||||
use std::borrow::Cow;
|
||||
@ -9,36 +10,14 @@ use tui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
///
|
||||
pub struct CommandInfo {
|
||||
pub name: String,
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
///
|
||||
pub trait UIElement {
|
||||
///
|
||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, rect: Rect);
|
||||
///
|
||||
fn commands(&self) -> Vec<CommandInfo>;
|
||||
///
|
||||
fn event(&mut self, ev: Event) -> bool;
|
||||
///
|
||||
fn is_visible(&self) -> bool;
|
||||
///
|
||||
fn hide(&mut self);
|
||||
///
|
||||
fn show(&mut self);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UICommit {
|
||||
pub struct CommitComponent {
|
||||
msg: String,
|
||||
// focused: bool,
|
||||
visible: bool,
|
||||
}
|
||||
|
||||
impl UIElement for UICommit {
|
||||
impl Component for CommitComponent {
|
||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
|
||||
if self.visible {
|
||||
let txt = if self.msg.len() > 0 {
|
||||
@ -131,7 +110,7 @@ impl UIElement for UICommit {
|
||||
}
|
||||
}
|
||||
|
||||
impl UICommit {
|
||||
impl CommitComponent {
|
||||
fn commit(&mut self) {
|
||||
git_utils::commit(&self.msg);
|
||||
self.msg.clear();
|
26
src/components/mod.rs
Normal file
26
src/components/mod.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use crossterm::event::Event;
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
pub mod commit;
|
||||
|
||||
///
|
||||
pub struct CommandInfo {
|
||||
pub name: String,
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
///
|
||||
pub trait Component {
|
||||
///
|
||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, rect: Rect);
|
||||
///
|
||||
fn commands(&self) -> Vec<CommandInfo>;
|
||||
///
|
||||
fn event(&mut self, ev: Event) -> bool;
|
||||
///
|
||||
fn is_visible(&self) -> bool;
|
||||
///
|
||||
fn hide(&mut self);
|
||||
///
|
||||
fn show(&mut self);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
mod app;
|
||||
mod clear;
|
||||
mod commit;
|
||||
mod components;
|
||||
mod git_status;
|
||||
mod git_utils;
|
||||
mod poll;
|
||||
|
Loading…
Reference in New Issue
Block a user