aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer/mod.rs (renamed from src/state/mod.rs)20
-rw-r--r--src/buffer/threads.rs (renamed from src/state/threads.rs)36
-rw-r--r--src/main.rs8
3 files changed, 32 insertions, 32 deletions
diff --git a/src/state/mod.rs b/src/buffer/mod.rs
index 0fe9f40..fe83a97 100644
--- a/src/state/mod.rs
+++ b/src/buffer/mod.rs
@@ -7,13 +7,13 @@ use termion::input::TermRead;
pub use threads::Threads;
pub struct Client {
- states: Vec<State>,
+ buffers: Vec<Buffer>,
}
impl Client {
- pub fn new(initial_state: State) -> Self {
+ pub fn new(initial_buffer: Buffer) -> Self {
Self {
- states: vec![initial_state],
+ buffers: vec![initial_buffer],
}
}
@@ -23,25 +23,25 @@ impl Client {
// Global keybinds
match c {
Key::Char('q') => {
- self.states.pop().unwrap();
- if self.states.is_empty() {
+ self.buffers.pop().unwrap();
+ if self.buffers.is_empty() {
break;
}
},
_ => ()
}
- let next_state = match self.states.last_mut().unwrap() {
- State::Threads(s) => s.tick(&mut screen, c),
+ let next_buffer = match self.buffers.last_mut().unwrap() {
+ Buffer::Threads(s) => s.tick(&mut screen, c),
};
- if let Some(next_state) = next_state {
- self.states.push(next_state);
+ if let Some(next_buffer) = next_buffer {
+ self.buffers.push(next_buffer);
}
}
}
}
-pub enum State {
+pub enum Buffer {
Threads(Threads),
}
diff --git a/src/state/threads.rs b/src/buffer/threads.rs
index be566e5..ddef067 100644
--- a/src/state/threads.rs
+++ b/src/buffer/threads.rs
@@ -1,5 +1,5 @@
use crate::db;
-use super::State;
+use super::Buffer;
use notmuch::DatabaseMode;
use std::io::Write;
@@ -65,10 +65,10 @@ impl Threads {
}
pub fn init<W: Write>(&self, out: &mut W) {
- draw(&self, out);
+ self.draw(out);
}
- pub fn tick<W: Write>(&mut self, out: &mut W, key: Key) -> Option<State> {
+ pub fn tick<W: Write>(&mut self, out: &mut W, key: Key) -> Option<Buffer> {
match key {
Key::Char('j') => self.i += 1,
Key::Char('k') => self.i =
@@ -83,7 +83,7 @@ impl Threads {
Key::Char('s') => {
let sent = Threads::from_query(String::from("tag:sent"));
sent.init(out);
- return Some(State::Threads(sent));
+ return Some(Buffer::Threads(sent));
}
Key::Char('r') => self.reload(),
_ => (),
@@ -91,24 +91,24 @@ impl Threads {
if !self.threads.is_empty() {
self.i = self.i.rem_euclid(self.threads.len());
}
- draw(&self, out);
+ self.draw(out);
None
}
-}
-fn draw<W: Write>(state: &Threads, out: &mut W) {
- write!(out, "{}", termion::clear::All).unwrap();
+ fn draw<W: Write>(&self, out: &mut W) {
+ write!(out, "{}", termion::clear::All).unwrap();
- for (i, thread) in state.threads.iter().enumerate() {
- write!(out, "{}", termion::cursor::Goto(1, (i + 1) as u16)).unwrap();
- let highlight = i == state.i;
- if highlight {
- write!(out, "{}", color::Fg(color::Red)).unwrap();
- }
- write!(out, "thread {:?}, {:?}", thread.subject, thread.authors).unwrap();
- if highlight {
- write!(out, "{}", color::Fg(color::Reset)).unwrap();
+ for (i, thread) in self.threads.iter().enumerate() {
+ write!(out, "{}", termion::cursor::Goto(1, (i + 1) as u16)).unwrap();
+ let highlight = i == self.i;
+ if highlight {
+ write!(out, "{}", color::Fg(color::Red)).unwrap();
+ }
+ write!(out, "thread {:?}, {:?}", thread.subject, thread.authors).unwrap();
+ if highlight {
+ write!(out, "{}", color::Fg(color::Reset)).unwrap();
+ }
}
+ out.flush().unwrap();
}
- out.flush().unwrap();
}
diff --git a/src/main.rs b/src/main.rs
index 58c084e..a1a4220 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,8 @@
mod db;
-mod state;
+mod buffer;
-use crate::state::{Client, State};
-use crate::state::Threads;
+use crate::buffer::{Client, Buffer};
+use crate::buffer::Threads;
use std::io::{stdin, stdout};
use termion::raw::IntoRawMode;
@@ -18,6 +18,6 @@ fn main() {
let threads = Threads::from_query(String::from("tag:inbox"));
threads.init(&mut screen);
- let client = Client::new(State::Threads(threads));
+ let client = Client::new(Buffer::Threads(threads));
client.run(screen, stdin);
}