Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filepath select #138

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ba1b47f
Cargo feature for path select
anwarhahjjeffersongeorge May 8, 2023
b6b7501
Support path feature in vscode
anwarhahjjeffersongeorge May 8, 2023
2082f9d
Basic path select prompt and builder
anwarhahjjeffersongeorge May 8, 2023
f5e3af4
Path select prompt examples
anwarhahjjeffersongeorge May 8, 2023
652d1d4
show hidden files option
anwarhahjjeffersongeorge May 8, 2023
7acd6f0
bugfix respect multi-selection mode, refactor pathentry
anwarhahjjeffersongeorge May 9, 2023
07c509b
support optionally showing/browsing symlinks
anwarhahjjeffersongeorge May 9, 2023
2757f97
multiselection mode fix
anwarhahjjeffersongeorge May 9, 2023
5c4b526
rustfmt
anwarhahjjeffersongeorge May 9, 2023
5142567
warnings
anwarhahjjeffersongeorge May 9, 2023
32006bb
Merge branch 'main' into filepath-select
anwarhahjjeffersongeorge May 9, 2023
be8141c
Update path select to new architecture
anwarhahjjeffersongeorge May 9, 2023
5c91a31
rustfmt
anwarhahjjeffersongeorge May 9, 2023
52792a2
do not use nightly features, cleanup unused imports
anwarhahjjeffersongeorge May 9, 2023
9410369
don't derive default on enum to suport msrv
anwarhahjjeffersongeorge May 9, 2023
d382d0c
Update inquire/src/prompts/path_select/action.rs
anwarhahjjeffersongeorge May 17, 2023
f4f31e5
Update inquire/src/prompts/path_select/action.rs
anwarhahjjeffersongeorge May 17, 2023
c2458e3
Update inquire/src/prompts/path_select/mod.rs
anwarhahjjeffersongeorge May 17, 2023
923d2a7
Remove vim mode as suggested at https://github.com/mikaelmello/inquir…
anwarhahjjeffersongeorge May 17, 2023
4a01e87
Add note about vim mode support.
anwarhahjjeffersongeorge May 17, 2023
83e31af
Bust out PathEntry into its own module
anwarhahjjeffersongeorge May 18, 2023
87e31aa
spacing
anwarhahjjeffersongeorge May 18, 2023
8f58450
file size information and sorting modes
anwarhahjjeffersongeorge May 18, 2023
e67a0e5
- Move PathEntry to own module
anwarhahjjeffersongeorge May 18, 2023
ec22cab
remove vim mode option
anwarhahjjeffersongeorge May 18, 2023
7b6d157
Improve display by selectively stripping prefixes
anwarhahjjeffersongeorge May 18, 2023
94c01f8
Relocate `is_path_hidden_file` method to PathSelectPrompt
anwarhahjjeffersongeorge May 18, 2023
3b2df27
remove example
anwarhahjjeffersongeorge May 18, 2023
4b6d119
Update inquire/src/prompts/path_select/mod.rs
anwarhahjjeffersongeorge Aug 13, 2023
1099e74
Update inquire/src/prompts/path_select/mod.rs
anwarhahjjeffersongeorge Aug 13, 2023
3b80840
Update inquire/src/prompts/path_select/mod.rs
anwarhahjjeffersongeorge Aug 13, 2023
c29a281
Update inquire/src/prompts/path_select/prompt.rs
anwarhahjjeffersongeorge Aug 13, 2023
b87ca59
Update inquire/src/prompts/path_select/mod.rs
anwarhahjjeffersongeorge Aug 13, 2023
58d0586
Update inquire/src/prompts/path_select/mod.rs
anwarhahjjeffersongeorge Aug 13, 2023
ec8a71b
unneccessary brace
anwarhahjjeffersongeorge Aug 13, 2023
db958ad
- Eliminate raw_prompt,
anwarhahjjeffersongeorge Aug 14, 2023
a5f53ec
Support PathFilter,
anwarhahjjeffersongeorge Aug 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/settings.json

This file was deleted.

8 changes: 8 additions & 0 deletions inquire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ default = ["macros", "crossterm", "editor"]
macros = []
date = ["chrono"]
editor = ["tempfile"]
path = ["fs-err", "humansize"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -37,6 +38,8 @@ chrono = { version = "0.4", optional = true }

tempfile = { version = "3", optional = true }

fs-err = { version = "2.9.0", optional = true }

thiserror = "1"
bitflags = "2"
dyn-clone = "1"
Expand All @@ -45,6 +48,7 @@ newline-converter = "0.3"

unicode-segmentation = "1"
unicode-width = "0.1"
humansize = { version = "2.1.3", optional = true, features = ["impl_style"] }

[[example]]
name = "form"
Expand Down Expand Up @@ -78,6 +82,10 @@ required-features = ["macros"]
name = "password_full_featured"
required-features = ["macros"]

[[example]]
name = "path_select"
required-features = ["path"]

[[example]]
name = "manual_date_input"
required-features = ["date"]
46 changes: 46 additions & 0 deletions inquire/examples/path_select.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Path picker example
use inquire::{
PathFilter,
PathSelect,
PathSelectionMode,
};

fn main() {
let start_path = std::env::current_dir().expect("must get current dir");

let toml_extension = "toml";
let rs_extension = "rs";
let selection_mode = PathSelectionMode::File(
PathFilter::AcceptAny(vec![
PathFilter::AcceptExtension(toml_extension),
PathFilter::AcceptExtension(rs_extension),
])
);

let ans = PathSelect::new(
&format!("pick an .{toml_extension} or .{rs_extension} file"),
)
.with_start_path(start_path)
.with_select_multiple(true)
.with_selection_mode(selection_mode)
.prompt();

match ans {
Ok(entries) => {
let l = entries.len();
println!(
"\nYou picked {l} items{}",
(!entries.is_empty())
.then(|| {
entries
.iter()
.enumerate()
.map(|(i, entry)| format!("\n{i}: {entry}"))
.collect::<String>()
})
.unwrap_or_default()
)
}
Err(err) => eprintln!("Your choices were wretched:\n{err:#?}"),
}
}
4 changes: 4 additions & 0 deletions inquire/src/prompts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mod dateselect;
mod editor;
mod multiselect;
mod password;
#[cfg(feature = "path")]
mod path_select;
mod prompt;
mod select;
mod text;
Expand All @@ -20,5 +22,7 @@ pub use dateselect::*;
pub use editor::*;
pub use multiselect::*;
pub use password::*;
#[cfg(feature = "path")]
pub use path_select::*;
pub use select::*;
pub use text::*;
67 changes: 67 additions & 0 deletions inquire/src/prompts/path_select/action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use crate::{
ui::{Key, KeyModifiers},
InnerAction, InputAction,
};

use super::config::PathSelectConfig;

/// Set of actions for a MultiSelectPrompt.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PathSelectPromptAction {
/// Action on the value text input handler.
FilterInput(InputAction),
/// Moves the cursor to the option above.
MoveUp,
/// Moves the cursor to the option below.
MoveDown,
/// Moves the cursor to the page above.
PageUp,
/// Moves the cursor to the page below.
PageDown,
/// Moves the cursor to the start of the list.
MoveToStart,
/// Moves the cursor to the end of the list.
MoveToEnd,
/// Toggles the selection of the current option.
ToggleCurrentOption,
/// Selects all options.
SelectAll,
/// Deselects all options.
ClearSelections,
/// Navigates deeper in file tree when current selection is a directory.
NavigateDeeper,
/// Navigates higher in file tree.
///
/// No-op if on a root directory.
NavigateHigher,
/// Changes the [sorting mode](crate::PathSortingMode).
ChangeSortMode,
}

impl InnerAction<PathSelectConfig> for PathSelectPromptAction {
fn from_key(key: Key, _config: &PathSelectConfig) -> Option<Self> {
let action = match key {
Key::Up(KeyModifiers::NONE) => Self::MoveUp,
Key::PageUp => Self::PageUp,
Key::Home => Self::MoveToStart,

Key::Down(KeyModifiers::NONE) => Self::MoveDown,
Key::PageDown => Self::PageDown,
Key::End => Self::MoveToEnd,

Key::Char(' ', KeyModifiers::NONE) => Self::ToggleCurrentOption,
Key::Right(KeyModifiers::SHIFT) => Self::SelectAll,
Key::Right(KeyModifiers::NONE) => Self::NavigateDeeper,
Key::Left(KeyModifiers::SHIFT) => Self::ClearSelections,
Key::Left(KeyModifiers::NONE) => Self::NavigateHigher,
Key::Tab => Self::ChangeSortMode,

key => match InputAction::from_key(key, &()) {
Some(action) => Self::FilterInput(action),
None => return None,
},
};

Some(action)
}
}
20 changes: 20 additions & 0 deletions inquire/src/prompts/path_select/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::PathSelect;

/// Configuration settings used in the execution of a PathSelectPrompt.
#[derive(Copy, Clone, Debug)]
pub struct PathSelectConfig {
/// Page size of the list of options.
pub page_size: usize,
/// Whether to keep the filter text when an option is selected.
pub keep_filter: bool,
}

impl<T> From<&PathSelect<'_, T>> for PathSelectConfig {
fn from(value: &PathSelect<'_, T>) -> Self {
Self {
page_size: value.page_size,
keep_filter: value.keep_filter,
}
}
}

Loading