Skip to content

Commit 19f2fd0

Browse files
author
Stephan Dilly
authored
app has its own async notifications now (#813)
* app has its own async notifications now
1 parent aacc7a3 commit 19f2fd0

File tree

8 files changed

+98
-64
lines changed

8 files changed

+98
-64
lines changed

asyncgit/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ pub enum AsyncGitNotification {
8383
Fetch,
8484
///
8585
Blame,
86-
///
87-
//TODO: this does not belong here
88-
SyntaxHighlighting,
89-
///
90-
//TODO: this does not belong here
91-
RemoteTags,
9286
}
9387

9488
/// current working directory `./`

src/app.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{
1818
strings::{self, order},
1919
tabs::{FilesTab, Revlog, StashList, Stashing, Status},
2020
ui::style::{SharedTheme, Theme},
21+
AsyncAppNotification, AsyncNotification,
2122
};
2223
use anyhow::{bail, Result};
2324
use asyncgit::{sync, AsyncGitNotification, CWD};
@@ -79,6 +80,7 @@ impl App {
7980
#[allow(clippy::too_many_lines)]
8081
pub fn new(
8182
sender: &Sender<AsyncGitNotification>,
83+
sender_app: &Sender<AsyncAppNotification>,
8284
input: Input,
8385
theme: Theme,
8486
key_config: KeyConfig,
@@ -108,7 +110,7 @@ impl App {
108110
),
109111
revision_files_popup: RevisionFilesPopup::new(
110112
&queue,
111-
sender,
113+
sender_app,
112114
theme.clone(),
113115
key_config.clone(),
114116
),
@@ -167,7 +169,7 @@ impl App {
167169
),
168170
tags_popup: TagListComponent::new(
169171
&queue,
170-
sender,
172+
sender_app,
171173
theme.clone(),
172174
key_config.clone(),
173175
),
@@ -206,7 +208,7 @@ impl App {
206208
key_config.clone(),
207209
),
208210
files_tab: FilesTab::new(
209-
sender,
211+
sender_app,
210212
&queue,
211213
theme.clone(),
212214
key_config.clone(),
@@ -342,21 +344,24 @@ impl App {
342344
}
343345

344346
///
345-
pub fn update_git(
347+
pub fn update_async(
346348
&mut self,
347-
ev: AsyncGitNotification,
349+
ev: AsyncNotification,
348350
) -> Result<()> {
349-
log::trace!("update_git: {:?}", ev);
350-
351-
self.status_tab.update_git(ev)?;
352-
self.stashing_tab.update_git(ev)?;
353-
self.files_tab.update_git(ev);
354-
self.revlog.update_git(ev)?;
355-
self.blame_file_popup.update_git(ev)?;
356-
self.inspect_commit_popup.update_git(ev)?;
357-
self.push_popup.update_git(ev)?;
358-
self.push_tags_popup.update_git(ev)?;
359-
self.pull_popup.update_git(ev)?;
351+
log::trace!("update_async: {:?}", ev);
352+
353+
if let AsyncNotification::Git(ev) = ev {
354+
self.status_tab.update_git(ev)?;
355+
self.stashing_tab.update_git(ev)?;
356+
self.revlog.update_git(ev)?;
357+
self.blame_file_popup.update_git(ev)?;
358+
self.inspect_commit_popup.update_git(ev)?;
359+
self.push_popup.update_git(ev)?;
360+
self.push_tags_popup.update_git(ev)?;
361+
self.pull_popup.update_git(ev)?;
362+
}
363+
364+
self.files_tab.update_async(ev);
360365
self.revision_files_popup.update(ev);
361366
self.tags_popup.update(ev);
362367

src/components/revision_files.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ use crate::{
88
queue::{InternalEvent, Queue},
99
strings::{self, order},
1010
ui::{self, common_nav, style::SharedTheme},
11+
AsyncAppNotification, AsyncNotification,
1112
};
1213
use anyhow::Result;
1314
use asyncgit::{
1415
sync::{self, CommitId, TreeFile},
15-
AsyncGitNotification, CWD,
16+
CWD,
1617
};
1718
use crossbeam_channel::Sender;
1819
use crossterm::event::Event;
@@ -52,7 +53,7 @@ impl RevisionFilesComponent {
5253
///
5354
pub fn new(
5455
queue: &Queue,
55-
sender: &Sender<AsyncGitNotification>,
56+
sender: &Sender<AsyncAppNotification>,
5657
theme: SharedTheme,
5758
key_config: SharedKeyConfig,
5859
) -> Self {
@@ -90,7 +91,7 @@ impl RevisionFilesComponent {
9091
}
9192

9293
///
93-
pub fn update(&mut self, ev: AsyncGitNotification) {
94+
pub fn update(&mut self, ev: AsyncNotification) {
9495
self.current_file.update(ev);
9596
}
9697

src/components/revision_files_popup.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use crate::{
88
queue::Queue,
99
strings::{self},
1010
ui::style::SharedTheme,
11+
AsyncAppNotification, AsyncNotification,
1112
};
1213
use anyhow::Result;
13-
use asyncgit::{sync::CommitId, AsyncGitNotification};
14+
use asyncgit::sync::CommitId;
1415
use crossbeam_channel::Sender;
1516
use crossterm::event::Event;
1617
use tui::{backend::Backend, layout::Rect, widgets::Clear, Frame};
@@ -25,7 +26,7 @@ impl RevisionFilesPopup {
2526
///
2627
pub fn new(
2728
queue: &Queue,
28-
sender: &Sender<AsyncGitNotification>,
29+
sender: &Sender<AsyncAppNotification>,
2930
theme: SharedTheme,
3031
key_config: SharedKeyConfig,
3132
) -> Self {
@@ -50,7 +51,7 @@ impl RevisionFilesPopup {
5051
}
5152

5253
///
53-
pub fn update(&mut self, ev: AsyncGitNotification) {
54+
pub fn update(&mut self, ev: AsyncNotification) {
5455
self.files.update(ev);
5556
}
5657

@@ -68,16 +69,6 @@ impl DrawableComponent for RevisionFilesPopup {
6869
) -> Result<()> {
6970
if self.is_visible() {
7071
f.render_widget(Clear, area);
71-
// f.render_widget(
72-
// Block::default()
73-
// .borders(Borders::TOP)
74-
// .title(Span::styled(
75-
// format!(" {}", self.title),
76-
// self.theme.title(true),
77-
// ))
78-
// .border_style(self.theme.block(true)),
79-
// area,
80-
// );
8172

8273
self.files.draw(f, area)?;
8374
}

src/components/syntax_text.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ use crate::{
99
self, common_nav, style::SharedTheme, AsyncSyntaxJob,
1010
ParagraphState, ScrollPos, StatefulParagraph,
1111
},
12+
AsyncAppNotification, AsyncNotification,
1213
};
1314
use anyhow::Result;
1415
use asyncgit::{
1516
asyncjob::AsyncSingleJob,
1617
sync::{self, TreeFile},
17-
AsyncGitNotification, CWD,
18+
CWD,
1819
};
1920
use crossbeam_channel::Sender;
2021
use crossterm::event::Event;
@@ -32,7 +33,7 @@ use tui::{
3233
pub struct SyntaxTextComponent {
3334
current_file: Option<(String, Either<ui::SyntaxText, String>)>,
3435
async_highlighting:
35-
AsyncSingleJob<AsyncSyntaxJob, AsyncGitNotification>,
36+
AsyncSingleJob<AsyncSyntaxJob, AsyncAppNotification>,
3637
key_config: SharedKeyConfig,
3738
paragraph_state: Cell<ParagraphState>,
3839
focused: bool,
@@ -42,14 +43,14 @@ pub struct SyntaxTextComponent {
4243
impl SyntaxTextComponent {
4344
///
4445
pub fn new(
45-
sender: &Sender<AsyncGitNotification>,
46+
sender: &Sender<AsyncAppNotification>,
4647
key_config: SharedKeyConfig,
4748
theme: SharedTheme,
4849
) -> Self {
4950
Self {
5051
async_highlighting: AsyncSingleJob::new(
5152
sender.clone(),
52-
AsyncGitNotification::SyntaxHighlighting,
53+
AsyncAppNotification::SyntaxHighlighting,
5354
),
5455
current_file: None,
5556
paragraph_state: Cell::new(ParagraphState::default()),
@@ -60,8 +61,13 @@ impl SyntaxTextComponent {
6061
}
6162

6263
///
63-
pub fn update(&mut self, ev: AsyncGitNotification) {
64-
if ev == AsyncGitNotification::SyntaxHighlighting {
64+
pub fn update(&mut self, ev: AsyncNotification) {
65+
if matches!(
66+
ev,
67+
AsyncNotification::App(
68+
AsyncAppNotification::SyntaxHighlighting
69+
)
70+
) {
6571
if let Some(job) = self.async_highlighting.take_last() {
6672
if let Some((path, content)) =
6773
self.current_file.as_mut()

src/components/taglist.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
queue::{Action, InternalEvent, Queue},
99
strings,
1010
ui::{self, Size},
11+
AsyncAppNotification, AsyncNotification,
1112
};
1213
use anyhow::Result;
1314
use asyncgit::{
@@ -46,7 +47,7 @@ pub struct TagListComponent {
4647
missing_remote_tags: Option<Vec<String>>,
4748
basic_credential: Option<BasicAuthCredential>,
4849
async_remote_tags:
49-
AsyncSingleJob<AsyncRemoteTagsJob, AsyncGitNotification>,
50+
AsyncSingleJob<AsyncRemoteTagsJob, AsyncAppNotification>,
5051
key_config: SharedKeyConfig,
5152
}
5253

@@ -250,7 +251,7 @@ impl Component for TagListComponent {
250251
impl TagListComponent {
251252
pub fn new(
252253
queue: &Queue,
253-
sender: &Sender<AsyncGitNotification>,
254+
sender: &Sender<AsyncAppNotification>,
254255
theme: SharedTheme,
255256
key_config: SharedKeyConfig,
256257
) -> Self {
@@ -265,7 +266,7 @@ impl TagListComponent {
265266
missing_remote_tags: None,
266267
async_remote_tags: AsyncSingleJob::new(
267268
sender.clone(),
268-
AsyncGitNotification::RemoteTags,
269+
AsyncAppNotification::RemoteTags,
269270
),
270271
key_config,
271272
}
@@ -297,15 +298,21 @@ impl TagListComponent {
297298
}
298299

299300
///
300-
pub fn update(&mut self, event: AsyncGitNotification) {
301-
if event == AsyncGitNotification::RemoteTags {
301+
pub fn update(&mut self, ev: AsyncNotification) {
302+
if matches!(
303+
ev,
304+
AsyncNotification::App(AsyncAppNotification::RemoteTags)
305+
) {
302306
if let Some(job) = self.async_remote_tags.take_last() {
303307
if let Some(Ok(missing_remote_tags)) = job.result() {
304308
self.missing_remote_tags =
305309
Some(missing_remote_tags);
306310
}
307311
}
308-
} else if event == AsyncGitNotification::PushTags {
312+
} else if matches!(
313+
ev,
314+
AsyncNotification::Git(AsyncGitNotification::PushTags)
315+
) {
309316
self.update_missing_remote_tags();
310317
}
311318
}

0 commit comments

Comments
 (0)