Skip to content

Commit

Permalink
Command mode feature
Browse files Browse the repository at this point in the history
* Add vim like command mode

* Colon now enters command mode
* Added a modal approach kept track of in Program struct
    Current modes: normal, command, exit
* Changed previous fn run -> fn run_normal_mode
* Add basis for future command mode commands

* Add cmd mode for infobar, cmd mode help and quit

* Modified infobar so that it takes a &str called msg in the case of
    command mode displays what the user is currently typing
* Add :help to print the help message and return to normal mode
* Add :quit to terminate the program from command mode

Command mode is any mode that requires user input

 * Moved command_mode related functions into its own file
 * Command Mode Features:
    * newglob (takes only one paramter). Properly handles ~/$HOME when
	provided by user. When the current path exists in the current vec of images
	and in the future one, remain at its index

    * sort (optionally one paramter). if called alone just performs the
	selected sort on the images, if provided with a second argument (a
	SortOrder) switch to that then sort. User is moved to new index
	of current image prior to sort

    * reverse, reverses the current set of images, keeping the index of
	the current image

    * destfolder, sets the destination folder

    * help, exits command mode and displays help info in normal mode

    * quit, terminates program

Increased performance, inside command_mode function get_command by not
rendering user input ever event, but only when it changes

* Add dependency shellexpand to properly handle ~/$HOME/env vars

* Add Mode, Error, to display error messages
* ui.rs Mode variants now take Strings if they need to display on infobar

* sdl2 text_input is used to handle keys like 'j','k', 'q', etc
* changed help to '?' instead of 'h'

* Updated README with Command mode options

* Now properly handles env vars and ~

* Entering command mode toggles bar on by default

* Paths::current_dir -> base_dir, better track of df

* Changes to dest_folder is now kept track for the case
of newglob to maintain the invariant that if the user hasn't set dest
folder, images should be moved to "./keep" by default unless specified
otherwise
  • Loading branch information
NickHackman authored and Davejkane committed May 22, 2019
1 parent f143ac1 commit f2d49ba
Show file tree
Hide file tree
Showing 9 changed files with 618 additions and 106 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ clap = "2.33"
glob = "0.3"
fs_extra = "1.1"
natord = "1.0.9"
shellexpand = "1.0"

[dependencies.sdl2]
version = "0.32"
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Set the maximum number of images to be displayed `m` or `--max` flag. 0 means in

```$ riv -m 0 **/*.png```

### Controls
### Normal Mode Controls


| Key | Action |
Expand All @@ -70,6 +70,19 @@ Set the maximum number of images to be displayed `m` or `--max` flag. 0 means in
| z OR Left Click | Toggle actual size vs scaled image |
| . (period) | Repeat last action |

### Command Mode Controls


| Command | Action |
|-----------------------------|----------------------------------------------------------|
| ng OR newglob [glob] | **Required argument** the new glob/directory/file |
| ? OR help | Toggle fullscreen mode |
| q OR quit | Quit |
| sort (method) | *Optional argument* the new method to sort by |
| 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|


## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn cli() -> Result<Args, String> {
})
}

fn push_image_path(v: &mut Vec<PathBuf>, p: PathBuf) {
pub(crate) fn push_image_path(v: &mut Vec<PathBuf>, p: PathBuf) {
if let Some(ext) = p.extension() {
if let Some(ext_str) = ext.to_str() {
let low = ext_str.to_string().to_lowercase();
Expand Down
62 changes: 41 additions & 21 deletions src/infobar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,52 @@
//! Module InfoBar provides structures and functions for building and rendering an infobar
use crate::paths::Paths;
use crate::ui::Mode;

/// Text contains the strings required to print the infobar.
pub struct Text {
/// current image is the string of the current image path
pub current_image: String,
/// index is the string represention of the index.
pub index: String,
/// Either displays the name of the current image or the current command the user is typing in
/// command mode
pub information: String,
/// In normal mode this is the string represention of the index, in command mode this is
/// "Command"
pub mode: String,
}

impl From<&Paths> for Text {
fn from(p: &Paths) -> Self {
let current_image = match p.images.get(p.index) {
Some(path) => match path.to_str() {
Some(name) => name.to_string(),
None => "No file".to_string(),
},
None => "No file selected".to_string(),
impl Text {
/// Updates the infobar based on the current mode of the applicaiton
/// Normal Mode:
/// mode = index of current image
/// information = path to current image
/// Command Mode:
/// mode = "Command"
/// information = curerntly entered user string
/// Error Mode:
/// mode = "Error"
/// information = error message to display
pub fn update(current_mode: &Mode, paths: &Paths) -> Self {
let (mode, information) = match current_mode {
Mode::Command(msg) => ("Command".to_string(), format!(":{}", msg)),
Mode::Normal => {
let information: String;
let mode: String;
information = match paths.images.get(paths.index) {
Some(path) => match path.to_str() {
Some(name) => name.to_string(),
None => "No file".to_string(),
},
None => "No file selected".to_string(),
};
mode = if paths.images.is_empty() {
"No files in path".to_string()
} else {
format!("{} of {}", paths.index + 1, paths.max_viewable)
};
(mode, information)
}
Mode::Error(msg) => ("Error".to_string(), msg.to_string()),
_ => ("Exit".to_string(), "Exiting... Goodbye".to_string()),
};
let index = if p.images.is_empty() {
"No files in path".to_string()
} else {
format!("{} of {}", p.index + 1, p.max_viewable)
};
Text {
current_image,
index,
}
Text { information, mode }
}
}
6 changes: 5 additions & 1 deletion src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ pub struct Paths {
pub images: Vec<PathBuf>,
/// dest_folder is the path of the destination folder for moving and copying images.
pub dest_folder: PathBuf,
/// dest_folder was modified from the default keep through Command mode df or destfolder
pub changed_dest_folder: bool,
/// current_dir is the path of the current directory where the program was launched from
pub current_dir: PathBuf,
pub base_dir: PathBuf,
/// index is the index of the images vector of the current image to be displayed.
pub index: usize,
/// Artificial user facing length of images limited by max cli argument
pub max_viewable: usize,
/// Actual length the user said was maximum for images
pub actual_max_viewable: usize,
}
Loading

0 comments on commit f2d49ba

Please sign in to comment.