summaryrefslogtreecommitdiffstats
path: root/src/context/tab_context.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-08-29 22:06:19 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-08-29 22:08:23 -0400
commit5be4a5f472655a76e1430bad09a19f6ad111e474 (patch)
tree1fcffa6c8d37cc6d538b29b6fbd773e8de58512d /src/context/tab_context.rs
parent4f3842b56f1729dcd8e81c77f98253ed9dfb23b3 (diff)
big rework and dependency update
- abstract JoshutoContext implementation behind functions - rework io workers in an attempt to fix a bug - update dependencies - remove JoshutoContextWorker
Diffstat (limited to 'src/context/tab_context.rs')
-rw-r--r--src/context/tab_context.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/context/tab_context.rs b/src/context/tab_context.rs
new file mode 100644
index 0000000..272e356
--- /dev/null
+++ b/src/context/tab_context.rs
@@ -0,0 +1,70 @@
+use crate::tab::JoshutoTab;
+
+use std::slice::{Iter, IterMut};
+
+pub struct TabContext {
+ index: usize,
+ tabs: Vec<JoshutoTab>,
+}
+
+impl std::default::Default for TabContext {
+ fn default() -> Self {
+ Self {
+ index: 0,
+ tabs: Vec::new(),
+ }
+ }
+}
+
+impl TabContext {
+ pub fn new() -> Self {
+ Self::default()
+ }
+
+ pub fn get_index(&self) -> usize {
+ self.index
+ }
+
+ pub fn set_index(&mut self, index: usize) {
+ self.index = index;
+ }
+
+ pub fn len(&self) -> usize {
+ self.tabs.len()
+ }
+
+ pub fn tab_ref(&self, i: usize) -> Option<&JoshutoTab> {
+ if i >= self.tabs.len() {
+ return None;
+ }
+ Some(&self.tabs[i])
+ }
+ pub fn tab_mut(&mut self, i: usize) -> Option<&mut JoshutoTab> {
+ if i >= self.tabs.len() {
+ return None;
+ }
+ Some(&mut self.tabs[i])
+ }
+
+ pub fn curr_tab_ref(&self) -> &JoshutoTab {
+ &self.tabs[self.index]
+ }
+ pub fn curr_tab_mut(&mut self) -> &mut JoshutoTab {
+ &mut self.tabs[self.index]
+ }
+ pub fn push_tab(&mut self, tab: JoshutoTab) {
+ self.tabs.push(tab);
+ self.index = self.tabs.len() - 1;
+ }
+ pub fn pop_tab(&mut self, index: usize) -> JoshutoTab {
+ self.tabs.remove(index)
+ }
+
+ pub fn iter(&self) -> Iter<JoshutoTab> {
+ self.tabs.iter()
+ }
+
+ pub fn iter_mut(&mut self) -> IterMut<JoshutoTab> {
+ self.tabs.iter_mut()
+ }
+}