From 5605cf596d084d97417337276bee0f7c9dbd2c99 Mon Sep 17 00:00:00 2001 From: Dave Kane Date: Thu, 23 May 2019 11:15:59 +0200 Subject: [PATCH 1/5] Cargo lock --- Cargo.lock | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f8e0636..77e780b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,6 +80,11 @@ name = "libc" version = "0.2.53" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "natord" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "num" version = "0.1.42" @@ -241,7 +246,9 @@ dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "natord 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)", + "shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -266,6 +273,11 @@ dependencies = [ "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "shellexpand" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "strsim" version = "0.8.0" @@ -332,6 +344,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "ec350a9417dfd244dc9a6c4a71e13895a4db6b92f0b106f07ebbc3f3bc580cee" +"checksum natord 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "308d96db8debc727c3fd9744aac51751243420e46edf401010908da7f8d5e57c" "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124" @@ -352,6 +365,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d051a07231e303f5f719da78cb6f7394f6d5b54f733aef5b0b447804a83edd7b" "checksum sdl2-sys 0.32.6 (registry+https://github.com/rust-lang/crates.io-index)" = "34e71125077d297d57e4c1acfe8981b5bdfbf5a20e7b589abfdcb33bf1127f86" +"checksum shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de7a5b5a9142fd278a10e0209b021a1b85849352e6951f4f914735c976737564" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" From 63031c7e0e9bf83bf56cebb9207abaa47a06b4e1 Mon Sep 17 00:00:00 2001 From: Dave Kane Date: Fri, 24 May 2019 00:03:58 +0200 Subject: [PATCH 2/5] Glob in quotes again --- src/cli.rs | 31 ++++++++++++++----------------- src/paths.rs | 15 +++++++++++++++ src/program/command_mode.rs | 17 ++--------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 58f900f..b4a4155 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,8 +2,10 @@ //! //! The cli module is used for setting up the command line app and parsing the arguments. +use crate::paths; use crate::sort::SortOrder; use clap::{App, Arg}; +use glob::glob; use std::path::PathBuf; /// Args contains the arguments that have been successfully parsed by the clap cli app @@ -30,7 +32,7 @@ pub fn cli() -> Result { .about("The command line image viewer") .arg( Arg::with_name("paths") - .multiple(true) + .default_value("*") .help("The directory or files to search for image files. A glob can be used here."), ) .arg( @@ -77,22 +79,17 @@ pub fn cli() -> Result { .help("Start app in fullscreen mode"), ) .get_matches(); - match matches.values_of("paths") { - Some(path_matches) => { - for path in path_matches { - push_image_path(&mut files, PathBuf::from(path)); - } - } - None => { - let path_matches = glob::glob("*").map_err(|e| e.to_string())?; - for path in path_matches { - match path { - Ok(p) => { - push_image_path(&mut files, p); - } - Err(e) => eprintln!("Unexpected path {}", e), - } - } + + let path_glob = match matches.value_of("paths") { + Some(v) => v, + None => panic!("No value for paths!"), + }; + let path_glob = paths::convert_to_globable(path_glob)?; + let glob_matches = glob(&path_glob).map_err(|e| e.to_string())?; + for path in glob_matches { + match path { + Ok(p) => push_image_path(&mut files, p), + Err(e) => eprintln!("Path not processable {}", e), } } diff --git a/src/paths.rs b/src/paths.rs index 4811511..2cd3d44 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -1,6 +1,7 @@ //! Paths contains the Paths struct which contains all path related information required for the //! running of the program. +use shellexpand::full; use std::path::PathBuf; /// Paths contains all path information related to the running of the program. @@ -20,3 +21,17 @@ pub struct Paths { /// Actual length the user said was maximum for images pub actual_max_viewable: usize, } + +/// Converts the provided path by user to a path that can be glob'd +/// Directories are changed from /home/etc to /home/etc/* +pub fn convert_to_globable(path: &str) -> Result { + let expanded_path = full(path).map_err(|e| format!("\"{}\": {}", e.var_name, e.cause))?; + // remove escaped spaces + let absolute_path = String::from(expanded_path).replace(r"\ ", " "); + // If path is a dir, add /* to glob + let mut pathbuf = PathBuf::from(&absolute_path); + if pathbuf.is_dir() { + pathbuf = pathbuf.join("*"); + } + Ok(pathbuf.to_string_lossy().to_string()) +} diff --git a/src/program/command_mode.rs b/src/program/command_mode.rs index 6a813dc..eff5c03 100644 --- a/src/program/command_mode.rs +++ b/src/program/command_mode.rs @@ -1,6 +1,7 @@ //! File that contains Command mode functionality, command mode is a mode that allows verbose input //! from the user to perform tasks or edit stored data in the application during runtime use super::Program; +use crate::paths; use crate::sort::SortOrder; use crate::ui::{process_command_mode, Action, Mode}; use shellexpand::full; @@ -67,27 +68,13 @@ impl FromStr for Commands { } } -/// Converts the provided path by user to a path that can be glob'd -/// Directories are changed from /home/etc to /home/etc/* -fn convert_path_to_globable(path: &str) -> Result { - let expanded_path = full(path).map_err(|e| format!("\"{}\": {}", e.var_name, e.cause))?; - // remove escaped spaces - let absolute_path = String::from(expanded_path).replace(r"\ ", " "); - // If path is a dir, add /* to glob - let mut pathbuf = PathBuf::from(&absolute_path); - if pathbuf.is_dir() { - pathbuf = pathbuf.join("*"); - } - Ok(pathbuf.to_string_lossy().to_string()) -} - /// Globs the passed path, returning an error if no images are in that path, glob::glob fails, or /// path is unexpected fn glob_path(path: &str) -> Result, String> { use crate::cli::push_image_path; let mut new_images: Vec = Vec::new(); - let globable_path = convert_path_to_globable(path)?; + let globable_path = paths::convert_to_globable(path)?; let path_matches = glob::glob(&globable_path).map_err(|e| e.to_string())?; for path in path_matches { match path { From eeab843054a7a82ff237f1bbb1431c8831f97bb0 Mon Sep 17 00:00:00 2001 From: Dave Kane Date: Fri, 24 May 2019 00:17:43 +0200 Subject: [PATCH 3/5] Move helper func to top level instead --- src/cli.rs | 3 +-- src/lib.rs | 17 +++++++++++++++++ src/paths.rs | 14 -------------- src/program/command_mode.rs | 3 +-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index b4a4155..6f5e882 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,7 +2,6 @@ //! //! The cli module is used for setting up the command line app and parsing the arguments. -use crate::paths; use crate::sort::SortOrder; use clap::{App, Arg}; use glob::glob; @@ -84,7 +83,7 @@ pub fn cli() -> Result { Some(v) => v, None => panic!("No value for paths!"), }; - let path_glob = paths::convert_to_globable(path_glob)?; + let path_glob = crate::convert_to_globable(path_glob)?; let glob_matches = glob(&path_glob).map_err(|e| e.to_string())?; for path in glob_matches { match path { diff --git a/src/lib.rs b/src/lib.rs index 9deef0b..cd5d184 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,3 +22,20 @@ pub mod program; pub mod screen; pub mod sort; pub mod ui; + +use shellexpand::full; +use std::path::PathBuf; + +/// Converts the provided path by user to a path that can be glob'd +/// Directories are changed from /home/etc to /home/etc/* +pub fn convert_to_globable(path: &str) -> Result { + let expanded_path = full(path).map_err(|e| format!("\"{}\": {}", e.var_name, e.cause))?; + // remove escaped spaces + let absolute_path = String::from(expanded_path).replace(r"\ ", " "); + // If path is a dir, add /* to glob + let mut pathbuf = PathBuf::from(&absolute_path); + if pathbuf.is_dir() { + pathbuf = pathbuf.join("*"); + } + Ok(pathbuf.to_string_lossy().to_string()) +} diff --git a/src/paths.rs b/src/paths.rs index e2e57e2..69e9fff 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -1,7 +1,6 @@ //! Paths contains the Paths struct which contains all path related information required for the //! running of the program. -use shellexpand::full; use std::path::PathBuf; /// Paths contains all path information related to the running of the program. @@ -20,16 +19,3 @@ pub struct Paths { pub actual_max_viewable: usize, } -/// Converts the provided path by user to a path that can be glob'd -/// Directories are changed from /home/etc to /home/etc/* -pub fn convert_to_globable(path: &str) -> Result { - let expanded_path = full(path).map_err(|e| format!("\"{}\": {}", e.var_name, e.cause))?; - // remove escaped spaces - let absolute_path = String::from(expanded_path).replace(r"\ ", " "); - // If path is a dir, add /* to glob - let mut pathbuf = PathBuf::from(&absolute_path); - if pathbuf.is_dir() { - pathbuf = pathbuf.join("*"); - } - Ok(pathbuf.to_string_lossy().to_string()) -} diff --git a/src/program/command_mode.rs b/src/program/command_mode.rs index 8abdc64..9707cbe 100644 --- a/src/program/command_mode.rs +++ b/src/program/command_mode.rs @@ -1,7 +1,6 @@ //! File that contains Command mode functionality, command mode is a mode that allows verbose input //! from the user to perform tasks or edit stored data in the application during runtime use super::Program; -use crate::paths; use crate::sort::SortOrder; use crate::ui::{process_command_mode, Action, Mode}; use shellexpand::full; @@ -74,7 +73,7 @@ fn glob_path(path: &str) -> Result, String> { use crate::cli::push_image_path; let mut new_images: Vec = Vec::new(); - let globable_path = paths::convert_to_globable(path)?; + let globable_path = crate::convert_to_globable(path)?; let path_matches = glob::glob(&globable_path).map_err(|e| e.to_string())?; for path in path_matches { match path { From b4623db4522009383444ed9ce116b31e0800e2b9 Mon Sep 17 00:00:00 2001 From: Dave Kane Date: Fri, 24 May 2019 00:21:32 +0200 Subject: [PATCH 4/5] Touch up README --- README.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1ad793d..1e4d3c0 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Generally the options are:- * Preview - Clunky and really only good for viewing one image at a time * Others that require a GUI folder browser -Riv on the other hand runs from the command line, and accepts a glob. For example:- +Riv on the other hand runs from the command line, and accepts a path with globs in quotes (with globstar `**` for recursive search). For example:- -```$ riv **/*.jpg``` +```$ riv "**/*.jpg"``` ## Manual @@ -17,9 +17,9 @@ Start riv with ```$ riv```. -As an optional second parameter you can add a glob, space separated filepaths or even a single filepath. +As an optional second parameter you can add a path with globs. -```$ riv **/*.png``` +```$ riv "**/*.png"``` Without any second parameter, riv will look for all images in the current directory. @@ -29,25 +29,7 @@ Set a destination folder for moving files with the `f` flag. The folder will be Set a sorting order with the `s` or `--sort` flag, case insensitive. -```$ riv -s alphabetical **/*.png``` - -### Sorting Options - -| Options | Description | -|------------------|------------------------------------------------------------------------------------------| -| Alphabetical | Alphabetically by filename only | -| Date | By date last modified, most recent first | -| Size | By size, largest first | -| DepthFirst | [Default] Ordered by farthest depth from current directory first | -| BreadthFirst | Ordered by farthest depth from current directory last | - -Reverse the sorting order with `r` or `--reverse` flag - -```$ riv -sr date **/*.png``` - -Set the maximum number of images to be displayed `m` or `--max` flag. 0 means infinitely many images. - -```$ riv -m 0 **/*.png``` +```$ riv -s alphabetical "**/*.png"``` ### Normal Mode Controls @@ -82,6 +64,24 @@ Set the maximum number of images to be displayed `m` or `--max` flag. 0 means in | df OR destfolder [path] | **Required argument** new folder to move/copy images to | | m OR max [positive integer] | **Required argument** new maximum number of files to view| +### Sorting Options + +| Options | Description | +|------------------|------------------------------------------------------------------------------------------| +| Alphabetical | Alphabetically by filename only | +| Date | By date last modified, most recent first | +| Size | By size, largest first | +| DepthFirst | [Default] Ordered by farthest depth from current directory first | +| BreadthFirst | Ordered by farthest depth from current directory last | + +Reverse the sorting order with `r` or `--reverse` flag + +```$ riv -sr date **/*.png``` + +Set the maximum number of images to be displayed `m` or `--max` flag. 0 means infinitely many images. + +```$ riv -m 0 **/*.png``` + ## Getting Started From 1085972d51b5040b3065d973f6d6f9da78564fc2 Mon Sep 17 00:00:00 2001 From: Dave Kane Date: Fri, 24 May 2019 06:59:58 +0200 Subject: [PATCH 5/5] fmt --- src/paths.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/paths.rs b/src/paths.rs index 69e9fff..2a56478 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -18,4 +18,3 @@ pub struct Paths { /// Actual length the user said was maximum for images pub actual_max_viewable: usize, } -