forked from michael/leanshot
strftime the path
This commit is contained in:
parent
49adf62ee4
commit
c4669d6340
5 changed files with 22 additions and 3 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -368,6 +368,7 @@ dependencies = [
|
|||
"gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -420,6 +421,16 @@ dependencies = [
|
|||
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.4"
|
||||
|
@ -496,6 +507,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
|
||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||
"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"
|
||||
"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
|
||||
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
|
||||
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||
|
|
|
@ -13,3 +13,4 @@ failure = "0.1.1"
|
|||
gdk = "0.8.0"
|
||||
gdk-pixbuf = "0.4.0"
|
||||
gtk = { version = "0.4.1", features = ["v3_16"] }
|
||||
time = "0.1.40"
|
||||
|
|
|
@ -6,6 +6,7 @@ use gdk::prelude::*;
|
|||
use gdk::{ContextExt, Display, DisplayExt, Screen, ScreenExt, Window as GdkWindow, WindowExt};
|
||||
use gdk_pixbuf::Pixbuf;
|
||||
use gtk::{Clipboard, ClipboardExt};
|
||||
use time;
|
||||
|
||||
use errors::ScreenshotError;
|
||||
use options::{Options, Region};
|
||||
|
@ -36,6 +37,7 @@ pub fn capture(options: Options) -> Result<(), Error> {
|
|||
Some(window_) => window = window_,
|
||||
None => bail!("Failed to locate root window."),
|
||||
}
|
||||
window.process_updates(true);
|
||||
|
||||
// take a screenshot of it
|
||||
let width: i32 = window.get_width();
|
||||
|
@ -61,7 +63,10 @@ pub fn capture(options: Options) -> Result<(), Error> {
|
|||
ctx.paint();
|
||||
|
||||
// write surface to file
|
||||
let mut file = File::create(options.outfile)?;
|
||||
|
||||
let now = time::now();
|
||||
let path = time::strftime(&options.outfile.as_os_str().to_str().unwrap(), &now)?;
|
||||
let mut file = File::create(path)?;
|
||||
surface.write_to_png(&mut file)?;
|
||||
|
||||
if options.clip {
|
||||
|
|
|
@ -8,6 +8,7 @@ extern crate failure;
|
|||
extern crate gdk;
|
||||
extern crate gdk_pixbuf;
|
||||
extern crate gtk;
|
||||
extern crate time;
|
||||
|
||||
mod capture;
|
||||
mod errors;
|
||||
|
@ -62,7 +63,7 @@ fn run() -> Result<(), Error> {
|
|||
"select" | "selection" => Region::Selection,
|
||||
_ => bail!("Please choose a valid region [fullscreen|active|select]"),
|
||||
};
|
||||
let path = PathBuf::from(app.value_of("output").unwrap());
|
||||
let path = String::from(app.value_of("output").unwrap());
|
||||
let clip = app.is_present("clip");
|
||||
let options = Options::new(region, path, clip)?;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct Options {
|
|||
}
|
||||
|
||||
impl Options {
|
||||
pub fn new(region: Region, outfile: PathBuf, clip: bool) -> Result<Options, Error> {
|
||||
pub fn new(region: Region, outfile: String, clip: bool) -> Result<Options, Error> {
|
||||
OpenOptions::new().create(true).write(true).open(&outfile)?;
|
||||
let outfile = canonicalize(&outfile)?;
|
||||
Ok(Options {
|
||||
|
|
Loading…
Reference in a new issue