mirror of https://github.com/sayanarijit/xplr
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
840 B
Rust
38 lines
840 B
Rust
use crate::node::Node;
|
|
use serde::{Deserialize, Serialize};
|
|
use time::OffsetDateTime;
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
|
pub struct DirectoryBuffer {
|
|
pub parent: String,
|
|
pub nodes: Vec<Node>,
|
|
pub total: usize,
|
|
pub focus: usize,
|
|
|
|
#[serde(skip, default = "now")]
|
|
pub explored_at: OffsetDateTime,
|
|
}
|
|
|
|
impl DirectoryBuffer {
|
|
pub fn new(parent: String, nodes: Vec<Node>, focus: usize) -> Self {
|
|
let total = nodes.len();
|
|
Self {
|
|
parent,
|
|
nodes,
|
|
total,
|
|
focus,
|
|
explored_at: now(),
|
|
}
|
|
}
|
|
|
|
pub fn focused_node(&self) -> Option<&Node> {
|
|
self.nodes.get(self.focus)
|
|
}
|
|
}
|
|
|
|
fn now() -> OffsetDateTime {
|
|
OffsetDateTime::now_local()
|
|
.ok()
|
|
.unwrap_or_else(OffsetDateTime::now_utc)
|
|
}
|