summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-03-18 19:01:16 -0500
committerToby Vincent <tobyv13@gmail.com>2023-03-18 19:01:16 -0500
commitb9890b578d8bcdb0d0a9c12ba3901b4e34514286 (patch)
tree6efbe30d3dfb5a26c7ea45d29bf357b60eb63015 /src/lib.rs
parent9b4f0bb63002a2657d89c7519697aabe515282b4 (diff)
feat: impl history file and sorting
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs51
1 files changed, 44 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d465d78..8d33eac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,13 +1,50 @@
+use std::{collections::HashMap, fmt::Display, iter::IntoIterator};
+
+use serde::Deserialize;
+
pub use config::Config;
+pub use history::History;
+pub use tmux::Tmux;
+
+mod config;
+mod history;
+mod tmux;
+
+pub type Timestamp = Option<u64>;
+
+pub trait SessionSource {
+ type Error: std::error::Error;
-mod config {
- use clap::Parser;
+ type Iter: IntoIterator<Item = Session>;
- #[derive(Debug, Clone, Parser)]
- pub struct Config {
- pub target: Option<String>,
+ fn sessions(&self) -> Result<Self::Iter, Self::Error>;
+
+ fn update(
+ &self,
+ mut hash_map: HashMap<String, Timestamp>,
+ ) -> Result<HashMap<String, Timestamp>, Self::Error> {
+ for session in self.sessions()? {
+ hash_map
+ .entry(session.name)
+ .and_modify(|o| {
+ if let Some(timestamp) = session.timestamp {
+ *o = o.map(|t| timestamp.max(t));
+ }
+ })
+ .or_insert(session.timestamp);
+ }
+ Ok(hash_map)
+ }
+}
+
+#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize)]
+pub struct Session {
+ pub timestamp: Timestamp,
+ pub name: String,
+}
- #[arg(short, long)]
- pub list: bool,
+impl Display for Session {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.name)
}
}