mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
also use status fetching for spinner state
This commit is contained in:
parent
f502c81187
commit
12cef5fccd
3 changed files with 19 additions and 3 deletions
|
|
@ -3,7 +3,10 @@ use crossbeam_channel::Sender;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use std::{
|
use std::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
sync::{Arc, Mutex},
|
sync::{
|
||||||
|
atomic::{AtomicUsize, Ordering},
|
||||||
|
Arc, Mutex,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use sync::status::StatusType;
|
use sync::status::StatusType;
|
||||||
|
|
||||||
|
|
@ -20,6 +23,7 @@ pub struct AsyncStatus {
|
||||||
current: Arc<Mutex<Request<u64, Status>>>,
|
current: Arc<Mutex<Request<u64, Status>>>,
|
||||||
last: Arc<Mutex<Status>>,
|
last: Arc<Mutex<Status>>,
|
||||||
sender: Sender<AsyncNotification>,
|
sender: Sender<AsyncNotification>,
|
||||||
|
pending: Arc<AtomicUsize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncStatus {
|
impl AsyncStatus {
|
||||||
|
|
@ -29,6 +33,7 @@ impl AsyncStatus {
|
||||||
current: Arc::new(Mutex::new(Request(0, None))),
|
current: Arc::new(Mutex::new(Request(0, None))),
|
||||||
last: Arc::new(Mutex::new(Status::default())),
|
last: Arc::new(Mutex::new(Status::default())),
|
||||||
sender,
|
sender,
|
||||||
|
pending: Arc::new(AtomicUsize::new(0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,6 +43,11 @@ impl AsyncStatus {
|
||||||
last.clone()
|
last.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
pub fn is_pending(&self) -> bool {
|
||||||
|
self.pending.load(Ordering::Relaxed) > 0
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
pub fn fetch(&mut self, request: u64) -> Option<Status> {
|
pub fn fetch(&mut self, request: u64) -> Option<Status> {
|
||||||
let hash_request = hash(&request);
|
let hash_request = hash(&request);
|
||||||
|
|
@ -58,7 +68,10 @@ impl AsyncStatus {
|
||||||
let arc_current = Arc::clone(&self.current);
|
let arc_current = Arc::clone(&self.current);
|
||||||
let arc_last = Arc::clone(&self.last);
|
let arc_last = Arc::clone(&self.last);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
let arc_pending = Arc::clone(&self.pending);
|
||||||
rayon_core::spawn(move || {
|
rayon_core::spawn(move || {
|
||||||
|
arc_pending.fetch_add(1, Ordering::Relaxed);
|
||||||
|
|
||||||
let res = Self::get_status();
|
let res = Self::get_status();
|
||||||
trace!("status fetched: {}", hash(&res));
|
trace!("status fetched: {}", hash(&res));
|
||||||
|
|
||||||
|
|
@ -74,6 +87,8 @@ impl AsyncStatus {
|
||||||
*last = res;
|
*last = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arc_pending.fetch_sub(1, Ordering::Relaxed);
|
||||||
|
|
||||||
sender
|
sender
|
||||||
.send(AsyncNotification::Status)
|
.send(AsyncNotification::Status)
|
||||||
.expect("error sending status");
|
.expect("error sending status");
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ impl App {
|
||||||
|
|
||||||
///
|
///
|
||||||
pub fn any_work_pending(&self) -> bool {
|
pub fn any_work_pending(&self) -> bool {
|
||||||
self.git_diff.is_pending()
|
self.git_diff.is_pending() || self.git_status.is_pending()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,13 @@ pub struct Spinner {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Spinner {
|
impl Spinner {
|
||||||
///
|
/// increment spinner graphic by one
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
self.idx %= SPINNER_CHARS.len();
|
self.idx %= SPINNER_CHARS.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// draws or removes spinner char depending on `pending` state
|
||||||
pub fn draw<B: Backend>(
|
pub fn draw<B: Backend>(
|
||||||
&self,
|
&self,
|
||||||
terminal: &mut Terminal<B>,
|
terminal: &mut Terminal<B>,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue