summaryrefslogtreecommitdiffstats
path: root/src/context
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-05-01 09:57:58 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-05-01 10:00:45 -0400
commit4409199315c5cc22bfba6cc63052a49dbdddfeb1 (patch)
treecfda2851a0c01cd183643810a6fe0941129f103a /src/context
parent297a06ef3a529687e7edb84d5f67376c654b1927 (diff)
remove methods
Diffstat (limited to 'src/context')
-rw-r--r--src/context/context.rs57
1 files changed, 22 insertions, 35 deletions
diff --git a/src/context/context.rs b/src/context/context.rs
index bee44aa..dfc1b89 100644
--- a/src/context/context.rs
+++ b/src/context/context.rs
@@ -6,20 +6,26 @@ use std::thread;
use crate::config;
use crate::context::{LocalStateContext, TabContext};
use crate::io::{IoWorkerObserver, IoWorkerProgress, IoWorkerThread};
-use crate::util::display::DisplayOption;
use crate::util::event::{AppEvent, Events};
use crate::util::search::SearchPattern;
-use crate::util::sort;
pub struct AppContext {
pub exit: bool,
+ // app config
config: config::AppConfig,
+ // event loop querying
events: Events,
+ // context related to tabs
tab_context: TabContext,
+ // context related to local file state
local_state: Option<LocalStateContext>,
+ // context related to searching
search_state: Option<SearchPattern>,
+ // message queue for displaying messages
message_queue: VecDeque<String>,
+ // queue of IO workers
worker_queue: VecDeque<IoWorkerThread>,
+ // current worker
worker: Option<IoWorkerObserver>,
}
@@ -38,28 +44,22 @@ impl AppContext {
}
}
- pub fn config_ref(&self) -> &config::AppConfig {
- &self.config
- }
-
- pub fn config_mut(&mut self) -> &mut config::AppConfig {
- &mut self.config
+ // event related
+ pub fn poll_event(&self) -> Result<AppEvent, mpsc::RecvError> {
+ self.events.next()
}
-
- pub fn display_options_ref(&self) -> &DisplayOption {
- self.config_ref().display_options_ref()
+ pub fn get_event_tx(&self) -> mpsc::Sender<AppEvent> {
+ self.events.event_tx.clone()
}
-
- pub fn display_options_mut(&mut self) -> &mut DisplayOption {
- self.config_mut().display_options_mut()
+ pub fn flush_event(&self) {
+ self.events.flush();
}
- pub fn sort_options_ref(&self) -> &sort::SortOption {
- self.config_ref().display_options_ref().sort_options_ref()
+ pub fn config_ref(&self) -> &config::AppConfig {
+ &self.config
}
-
- pub fn sort_options_mut(&mut self) -> &mut sort::SortOption {
- self.config_mut().display_options_mut().sort_options_mut()
+ pub fn config_mut(&mut self) -> &mut config::AppConfig {
+ &mut self.config
}
pub fn tab_context_ref(&self) -> &TabContext {
@@ -79,17 +79,6 @@ impl AppContext {
self.message_queue.pop_front()
}
- // event related
- pub fn poll_event(&self) -> Result<AppEvent, mpsc::RecvError> {
- self.events.next()
- }
- pub fn get_event_tx(&self) -> mpsc::Sender<AppEvent> {
- self.events.event_tx.clone()
- }
- pub fn flush_event(&self) {
- self.events.flush();
- }
-
// local state related
pub fn set_local_state(&mut self, state: LocalStateContext) {
self.local_state = Some(state);
@@ -98,13 +87,12 @@ impl AppContext {
self.local_state.take()
}
- pub fn set_search_state(&mut self, pattern: SearchPattern) {
- self.search_state = Some(pattern);
- }
-
pub fn get_search_state(&self) -> Option<&SearchPattern> {
self.search_state.as_ref()
}
+ pub fn set_search_state(&mut self, pattern: SearchPattern) {
+ self.search_state = Some(pattern);
+ }
// worker related
pub fn add_worker(&mut self, thread: IoWorkerThread) {
@@ -120,7 +108,6 @@ impl AppContext {
pub fn worker_iter(&self) -> Iter<IoWorkerThread> {
self.worker_queue.iter()
}
-
pub fn worker_ref(&self) -> Option<&IoWorkerObserver> {
self.worker.as_ref()
}