diff --git a/wayshot/config.toml b/wayshot/config.toml new file mode 100644 index 00000000..24badbc7 --- /dev/null +++ b/wayshot/config.toml @@ -0,0 +1,26 @@ +# base screenshot properties +[screenshot] +# display to take screenshot +display = "default" +# should contain cursor? +cursor = false + +# properties, related to +# clipboard copy +[clipboard] +# should copy resulting screenshot +# to clipborad? +clipboard = true + +# properties related to +# writing screenshot to filesystem +[filesystem] +# should write resulting screenshot +# to filesystem? +filesystem = true +# output directory +path = "~/images/screenshots" +# output filename format +format = "%Y-%m-%d_%H:%M:%S" +# output file encoding +encoding = "png" \ No newline at end of file diff --git a/wayshot/src/config.rs b/wayshot/src/config.rs new file mode 100644 index 00000000..fc580c9a --- /dev/null +++ b/wayshot/src/config.rs @@ -0,0 +1,82 @@ +use serde::{Deserialize, Serialize}; +use std::{fs::File, io::Read, path::PathBuf}; +use toml; + +use crate::utils::EncodingFormat; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Config { + pub screenshot: Option, + #[serde(rename = "clipboard")] + pub clipboard: Option, + #[serde(rename = "filesystem")] + pub filesystem: Option, +} + +impl Default for Config { + fn default() -> Self { + Config { + screenshot: Some(Screenshot::default()), + clipboard: Some(Clipboard::default()), + filesystem: Some(Filesystem::default()), + } + } +} + +impl Config { + pub fn load(path: &PathBuf) -> Option { + let mut config_file = File::open(path).ok()?; + let mut config_str = String::new(); + config_file.read_to_string(&mut config_str).ok()?; + + toml::from_str(&mut config_str).ok()? + } +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Screenshot { + pub display: Option, + pub cursor: Option, +} + +impl Default for Screenshot { + fn default() -> Self { + Screenshot { + display: None, + cursor: Some(false), + } + } +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Clipboard { + pub clipboard: Option, +} + +impl Default for Clipboard { + fn default() -> Self { + Clipboard { + clipboard: Some(true), + } + } +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Filesystem { + pub filesystem: Option, + pub path: Option, + pub format: Option, + pub encoding: Option, +} + +impl Default for Filesystem { + fn default() -> Self { + Filesystem { + filesystem: Some(true), + path: None, + // PR #93 + format: Some("wayshot-%Y_%m_%d-%H_%M_%S".to_string()), + encoding: Some(EncodingFormat::Png), + } + } +}