-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Screenshot>, | ||
#[serde(rename = "clipboard")] | ||
pub clipboard: Option<Clipboard>, | ||
#[serde(rename = "filesystem")] | ||
pub filesystem: Option<Filesystem>, | ||
} | ||
|
||
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<Config> { | ||
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<String>, | ||
pub cursor: Option<bool>, | ||
} | ||
|
||
impl Default for Screenshot { | ||
fn default() -> Self { | ||
Screenshot { | ||
display: None, | ||
cursor: Some(false), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct Clipboard { | ||
pub clipboard: Option<bool>, | ||
} | ||
|
||
impl Default for Clipboard { | ||
fn default() -> Self { | ||
Clipboard { | ||
clipboard: Some(true), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct Filesystem { | ||
pub filesystem: Option<bool>, | ||
pub path: Option<PathBuf>, | ||
pub format: Option<String>, | ||
pub encoding: Option<EncodingFormat>, | ||
} | ||
|
||
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), | ||
} | ||
} | ||
} |