diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-11-28 01:45:38 -0600 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-11-28 01:45:38 -0600 |
commit | 3c3c95b54d12b1654c5c0810f7431190bc7d7580 (patch) | |
tree | c06be9a70fb259ba8f77a673db898c7d7e281810 /src/project.rs | |
parent | 3f188dea518fe29324f7a2416316c436cea8e88a (diff) |
feat: add previewer trait
Diffstat (limited to 'src/project.rs')
-rw-r--r-- | src/project.rs | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/project.rs b/src/project.rs index 5f1edc5..e6faf66 100644 --- a/src/project.rs +++ b/src/project.rs @@ -1,5 +1,7 @@ use std::{ + io::Write, path::PathBuf, + process::{Command, Stdio}, time::{Duration, SystemTime}, }; @@ -13,6 +15,20 @@ mod path; pub type ProjectItem = Box<dyn Project<Error = Error>>; +pub trait Project: Timestamp { + fn to_path_buf(&self) -> &PathBuf; +} + +impl<T> Project for T +where + T: Timestamp, + T: AsRef<PathBuf>, +{ + fn to_path_buf(&self) -> &PathBuf { + self.as_ref() + } +} + pub trait Timestamp { type Error; @@ -34,16 +50,26 @@ where } } -pub trait Project: Timestamp { - fn to_path_buf(&self) -> &PathBuf; +pub trait Preview { + type Error; + + fn preview(&self) -> Result<(), Self::Error>; } -impl<T> Project for T +impl<T> Preview for T where - T: Timestamp, T: AsRef<PathBuf>, { - fn to_path_buf(&self) -> &PathBuf { - self.as_ref() + type Error = std::io::Error; + + fn preview(&self) -> Result<(), Self::Error> { + let output = Command::new("ls") + .arg("-l") + .arg("-a") + .arg(self.to_path_buf()) + .stdout(Stdio::piped()) + .output()?; + + std::io::stdout().write_all(&output.stdout) } } |