mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 01:18:21 +00:00
make draw take shared ref again
This commit is contained in:
parent
19947a7ec0
commit
0d84abd1c6
20 changed files with 71 additions and 68 deletions
25
src/app.rs
25
src/app.rs
|
|
@ -18,7 +18,7 @@ use anyhow::{anyhow, Result};
|
|||
use asyncgit::{sync, AsyncNotification, CWD};
|
||||
use crossbeam_channel::Sender;
|
||||
use crossterm::event::{Event, KeyEvent};
|
||||
use std::rc::Rc;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use strings::{commands, order};
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
|
|
@ -37,7 +37,7 @@ pub struct App {
|
|||
commit: CommitComponent,
|
||||
stashmsg_popup: StashMsgComponent,
|
||||
inspect_commit_popup: InspectCommitComponent,
|
||||
cmdbar: CommandBar,
|
||||
cmdbar: RefCell<CommandBar>,
|
||||
tab: usize,
|
||||
revlog: Revlog,
|
||||
status_tab: Status,
|
||||
|
|
@ -71,7 +71,7 @@ impl App {
|
|||
theme.clone(),
|
||||
),
|
||||
do_quit: false,
|
||||
cmdbar: CommandBar::new(theme.clone()),
|
||||
cmdbar: RefCell::new(CommandBar::new(theme.clone())),
|
||||
help: HelpComponent::new(theme.clone()),
|
||||
msg: MsgComponent::new(theme.clone()),
|
||||
tab: 0,
|
||||
|
|
@ -89,13 +89,10 @@ impl App {
|
|||
}
|
||||
|
||||
///
|
||||
pub fn draw<B: Backend>(
|
||||
&mut self,
|
||||
f: &mut Frame<B>,
|
||||
) -> Result<()> {
|
||||
pub fn draw<B: Backend>(&self, f: &mut Frame<B>) -> Result<()> {
|
||||
let fsize = f.size();
|
||||
|
||||
self.cmdbar.refresh_width(fsize.width);
|
||||
self.cmdbar.borrow_mut().refresh_width(fsize.width);
|
||||
|
||||
let chunks_main = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
|
@ -103,13 +100,13 @@ impl App {
|
|||
[
|
||||
Constraint::Length(2),
|
||||
Constraint::Min(2),
|
||||
Constraint::Length(self.cmdbar.height()),
|
||||
Constraint::Length(self.cmdbar.borrow().height()),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(fsize);
|
||||
|
||||
self.cmdbar.draw(f, chunks_main[2]);
|
||||
self.cmdbar.borrow().draw(f, chunks_main[2]);
|
||||
|
||||
self.draw_tabs(f, chunks_main[0]);
|
||||
|
||||
|
|
@ -160,7 +157,7 @@ impl App {
|
|||
}
|
||||
|
||||
keys::CMD_BAR_TOGGLE => {
|
||||
self.cmdbar.toggle_more();
|
||||
self.cmdbar.borrow_mut().toggle_more();
|
||||
NeedsUpdate::empty()
|
||||
}
|
||||
|
||||
|
|
@ -312,7 +309,7 @@ impl App {
|
|||
|
||||
fn update_commands(&mut self) {
|
||||
self.help.set_cmds(self.commands(true));
|
||||
self.cmdbar.set_cmds(self.commands(false));
|
||||
self.cmdbar.borrow_mut().set_cmds(self.commands(false));
|
||||
}
|
||||
|
||||
fn process_queue(&mut self) -> Result<NeedsUpdate> {
|
||||
|
|
@ -428,7 +425,7 @@ impl App {
|
|||
}
|
||||
|
||||
fn draw_popups<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
) -> Result<()> {
|
||||
let size = Layout::default()
|
||||
|
|
@ -436,7 +433,7 @@ impl App {
|
|||
.constraints(
|
||||
[
|
||||
Constraint::Min(1),
|
||||
Constraint::Length(self.cmdbar.height()),
|
||||
Constraint::Length(self.cmdbar.borrow().height()),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ impl ChangesComponent {
|
|||
|
||||
impl DrawableComponent for ChangesComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
r: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub struct CommitComponent {
|
|||
|
||||
impl DrawableComponent for CommitComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ impl DetailsComponent {
|
|||
|
||||
impl DrawableComponent for DetailsComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ impl CommitDetailsComponent {
|
|||
|
||||
impl DrawableComponent for CommitDetailsComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ use crate::{
|
|||
use anyhow::Result;
|
||||
use asyncgit::sync;
|
||||
use crossterm::event::Event;
|
||||
use std::{borrow::Cow, cmp, convert::TryFrom, time::Instant};
|
||||
use std::{
|
||||
borrow::Cow, cell::Cell, cmp, convert::TryFrom, time::Instant,
|
||||
};
|
||||
use sync::Tags;
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
|
|
@ -32,8 +34,8 @@ pub struct CommitList {
|
|||
items: ItemBatch,
|
||||
scroll_state: (Instant, f32),
|
||||
tags: Option<Tags>,
|
||||
current_size: (u16, u16),
|
||||
scroll_top: usize,
|
||||
current_size: Cell<(u16, u16)>,
|
||||
scroll_top: Cell<usize>,
|
||||
theme: SharedTheme,
|
||||
}
|
||||
|
||||
|
|
@ -47,8 +49,8 @@ impl CommitList {
|
|||
count_total: 0,
|
||||
scroll_state: (Instant::now(), 0_f32),
|
||||
tags: None,
|
||||
current_size: (0, 0),
|
||||
scroll_top: 0,
|
||||
current_size: Cell::new((0, 0)),
|
||||
scroll_top: Cell::new(0),
|
||||
theme,
|
||||
title: String::from(title),
|
||||
}
|
||||
|
|
@ -70,8 +72,8 @@ impl CommitList {
|
|||
}
|
||||
|
||||
///
|
||||
pub const fn current_size(&self) -> (u16, u16) {
|
||||
self.current_size
|
||||
pub fn current_size(&self) -> (u16, u16) {
|
||||
self.current_size.get()
|
||||
}
|
||||
|
||||
///
|
||||
|
|
@ -121,7 +123,7 @@ impl CommitList {
|
|||
usize::try_from(self.scroll_state.1 as i64)?.max(1);
|
||||
|
||||
let page_offset =
|
||||
usize::from(self.current_size.1).saturating_sub(1);
|
||||
usize::from(self.current_size.get().1).saturating_sub(1);
|
||||
|
||||
let new_selection = match scroll {
|
||||
ScrollType::Up => {
|
||||
|
|
@ -239,7 +241,7 @@ impl CommitList {
|
|||
for (idx, e) in self
|
||||
.items
|
||||
.iter()
|
||||
.skip(self.scroll_top)
|
||||
.skip(self.scroll_top.get())
|
||||
.take(height)
|
||||
.enumerate()
|
||||
{
|
||||
|
|
@ -253,7 +255,7 @@ impl CommitList {
|
|||
|
||||
Self::add_entry(
|
||||
e,
|
||||
idx + self.scroll_top == selection,
|
||||
idx + self.scroll_top.get() == selection,
|
||||
&mut txt,
|
||||
tags,
|
||||
&self.theme,
|
||||
|
|
@ -271,23 +273,23 @@ impl CommitList {
|
|||
|
||||
impl DrawableComponent for CommitList {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
area: Rect,
|
||||
) -> Result<()> {
|
||||
self.current_size = (
|
||||
self.current_size.set((
|
||||
area.width.saturating_sub(2),
|
||||
area.height.saturating_sub(2),
|
||||
);
|
||||
));
|
||||
|
||||
let height_in_lines = self.current_size.1 as usize;
|
||||
let height_in_lines = self.current_size.get().1 as usize;
|
||||
let selection = self.relative_selection();
|
||||
|
||||
self.scroll_top = calc_scroll_top(
|
||||
self.scroll_top,
|
||||
self.scroll_top.set(calc_scroll_top(
|
||||
self.scroll_top.get(),
|
||||
height_in_lines,
|
||||
selection,
|
||||
);
|
||||
));
|
||||
|
||||
let branch_post_fix =
|
||||
self.branch.as_ref().map(|b| format!("- {{{}}}", b));
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
use asyncgit::{hash, sync, DiffLine, DiffLineType, FileDiff, CWD};
|
||||
use bytesize::ByteSize;
|
||||
use crossterm::event::Event;
|
||||
use std::{borrow::Cow, cmp, path::Path};
|
||||
use std::{borrow::Cow, cell::Cell, cmp, path::Path};
|
||||
use strings::commands;
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
|
|
@ -33,10 +33,10 @@ pub struct DiffComponent {
|
|||
diff: Option<FileDiff>,
|
||||
selection: usize,
|
||||
selected_hunk: Option<usize>,
|
||||
current_size: (u16, u16),
|
||||
current_size: Cell<(u16, u16)>,
|
||||
focused: bool,
|
||||
current: Current,
|
||||
scroll_top: usize,
|
||||
scroll_top: Cell<usize>,
|
||||
queue: Option<Queue>,
|
||||
theme: SharedTheme,
|
||||
}
|
||||
|
|
@ -50,9 +50,9 @@ impl DiffComponent {
|
|||
current: Current::default(),
|
||||
selected_hunk: None,
|
||||
diff: None,
|
||||
current_size: (0, 0),
|
||||
current_size: Cell::new((0, 0)),
|
||||
selection: 0,
|
||||
scroll_top: 0,
|
||||
scroll_top: Cell::new(0),
|
||||
theme,
|
||||
}
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ impl DiffComponent {
|
|||
pub fn clear(&mut self) -> Result<()> {
|
||||
self.current = Current::default();
|
||||
self.diff = None;
|
||||
self.scroll_top = 0;
|
||||
self.scroll_top.set(0);
|
||||
self.selection = 0;
|
||||
self.selected_hunk = None;
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ impl DiffComponent {
|
|||
Self::find_selected_hunk(&diff, self.selection)?;
|
||||
|
||||
self.diff = Some(diff);
|
||||
self.scroll_top = 0;
|
||||
self.scroll_top.set(0);
|
||||
self.selection = 0;
|
||||
}
|
||||
|
||||
|
|
@ -120,12 +120,13 @@ impl DiffComponent {
|
|||
ScrollType::End => max,
|
||||
ScrollType::PageDown => {
|
||||
self.selection.saturating_add(
|
||||
self.current_size.1.saturating_sub(1)
|
||||
self.current_size.get().1.saturating_sub(1)
|
||||
as usize,
|
||||
)
|
||||
}
|
||||
ScrollType::PageUp => self.selection.saturating_sub(
|
||||
self.current_size.1.saturating_sub(1) as usize,
|
||||
self.current_size.get().1.saturating_sub(1)
|
||||
as usize,
|
||||
),
|
||||
};
|
||||
|
||||
|
|
@ -207,7 +208,7 @@ impl DiffComponent {
|
|||
} else {
|
||||
let selection = self.selection;
|
||||
|
||||
let min = self.scroll_top;
|
||||
let min = self.scroll_top.get();
|
||||
let max = min + height as usize;
|
||||
|
||||
let mut line_cursor = 0_usize;
|
||||
|
|
@ -415,24 +416,27 @@ impl DiffComponent {
|
|||
|
||||
impl DrawableComponent for DiffComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
r: Rect,
|
||||
) -> Result<()> {
|
||||
self.current_size =
|
||||
(r.width.saturating_sub(2), r.height.saturating_sub(2));
|
||||
self.current_size.set((
|
||||
r.width.saturating_sub(2),
|
||||
r.height.saturating_sub(2),
|
||||
));
|
||||
|
||||
self.scroll_top = calc_scroll_top(
|
||||
self.scroll_top,
|
||||
self.current_size.1 as usize,
|
||||
self.scroll_top.set(calc_scroll_top(
|
||||
self.scroll_top.get(),
|
||||
self.current_size.get().1 as usize,
|
||||
self.selection,
|
||||
);
|
||||
));
|
||||
|
||||
let title =
|
||||
format!("{}{}", strings::TITLE_DIFF, self.current.path);
|
||||
f.render_widget(
|
||||
Paragraph::new(
|
||||
self.get_text(r.width, self.current_size.1)?.iter(),
|
||||
self.get_text(r.width, self.current_size.get().1)?
|
||||
.iter(),
|
||||
)
|
||||
.block(
|
||||
Block::default()
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ impl FileTreeComponent {
|
|||
|
||||
impl DrawableComponent for FileTreeComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
r: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub struct HelpComponent {
|
|||
|
||||
impl DrawableComponent for HelpComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
_rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ pub struct InspectCommitComponent {
|
|||
|
||||
impl DrawableComponent for InspectCommitComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ pub fn visibility_blocking<T: Component>(
|
|||
pub trait DrawableComponent {
|
||||
///
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
rect: Rect,
|
||||
) -> Result<()>;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use anyhow::Result;
|
|||
|
||||
impl DrawableComponent for MsgComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
_rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub struct ResetComponent {
|
|||
|
||||
impl DrawableComponent for ResetComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
_rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub struct StashMsgComponent {
|
|||
|
||||
impl DrawableComponent for StashMsgComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ impl TextInputComponent {
|
|||
|
||||
impl DrawableComponent for TextInputComponent {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
_rect: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ fn main() -> Result<()> {
|
|||
let spinner_ticker = tick(SPINNER_INTERVAL);
|
||||
|
||||
app.update()?;
|
||||
draw(&mut terminal, &mut app)?;
|
||||
draw(&mut terminal, &app)?;
|
||||
|
||||
let mut spinner = Spinner::default();
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ fn main() -> Result<()> {
|
|||
input.set_polling(!app.any_work_pending());
|
||||
|
||||
if needs_draw {
|
||||
draw(&mut terminal, &mut app)?;
|
||||
draw(&mut terminal, &app)?;
|
||||
}
|
||||
|
||||
spinner.draw(
|
||||
|
|
@ -162,7 +162,7 @@ fn shutdown_terminal() -> Result<()> {
|
|||
|
||||
fn draw<B: Backend>(
|
||||
terminal: &mut Terminal<B>,
|
||||
app: &mut App,
|
||||
app: &App,
|
||||
) -> io::Result<()> {
|
||||
terminal.draw(|mut f| {
|
||||
if let Err(e) = app.draw(&mut f) {
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ impl Revlog {
|
|||
|
||||
impl DrawableComponent for Revlog {
|
||||
fn draw<B: Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
area: Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ impl Stashing {
|
|||
|
||||
impl DrawableComponent for Stashing {
|
||||
fn draw<B: tui::backend::Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut tui::Frame<B>,
|
||||
rect: tui::layout::Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ impl StashList {
|
|||
|
||||
impl DrawableComponent for StashList {
|
||||
fn draw<B: tui::backend::Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut tui::Frame<B>,
|
||||
rect: tui::layout::Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ pub struct Status {
|
|||
|
||||
impl DrawableComponent for Status {
|
||||
fn draw<B: tui::backend::Backend>(
|
||||
&mut self,
|
||||
&self,
|
||||
f: &mut tui::Frame<B>,
|
||||
rect: tui::layout::Rect,
|
||||
) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue