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

Experimental branch that adds invisble cursor key reads #301

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Expand Up @@ -25,13 +25,16 @@ password = ["zeroize"]
completion = []

[dependencies]
console = "0.15.0"
console = "0.15.8"
tempfile = { version = "3", optional = true }
zeroize = { version = "1.1.1", optional = true }
fuzzy-matcher = { version = "0.3.7", optional = true }
shell-words = "1.1.0"
thiserror = "1.0.40"

[patch.crates-io]
console = { path = "../console" }

[[example]]
name = "password"
required-features = ["password"]
Expand Down
8 changes: 2 additions & 6 deletions src/prompts/confirm.rs
Expand Up @@ -164,8 +164,6 @@ impl Confirm<'_> {
};

render.confirm_prompt(&self.prompt, default_if_show)?;

term.hide_cursor()?;
term.flush()?;

let rv;
Expand All @@ -176,7 +174,7 @@ impl Confirm<'_> {
let mut value = default_if_show;

loop {
let input = term.read_key()?;
let input = term.read_key_no_cursor()?;

match input {
Key::Char('y') | Key::Char('Y') => {
Expand Down Expand Up @@ -211,7 +209,7 @@ impl Confirm<'_> {
// Default behavior: matches continuously on every keystroke,
// and does not wait for user to hit the Enter key.
loop {
let input = term.read_key()?;
let input = term.read_key_no_cursor()?;
let value = match input {
Key::Char('y') | Key::Char('Y') => Some(true),
Key::Char('n') | Key::Char('N') => Some(false),
Expand All @@ -231,8 +229,6 @@ impl Confirm<'_> {
if self.report {
render.confirm_prompt_selection(&self.prompt, rv)?;
}
term.show_cursor()?;
term.flush()?;

Ok(rv)
}
Expand Down
6 changes: 1 addition & 5 deletions src/prompts/fuzzy_select.rs
Expand Up @@ -223,8 +223,6 @@ impl FuzzySelect<'_> {
// Variable used to determine if we need to scroll through the list.
let mut starting_row = 0;

term.hide_cursor()?;

let mut vim_mode = false;

loop {
Expand Down Expand Up @@ -265,7 +263,7 @@ impl FuzzySelect<'_> {
}
term.flush()?;

match (term.read_key()?, sel, vim_mode) {
match (term.read_key_no_cursor()?, sel, vim_mode) {
(Key::Escape, _, false) if self.enable_vim_mode => {
vim_mode = true;
}
Expand All @@ -274,7 +272,6 @@ impl FuzzySelect<'_> {
render.clear()?;
term.flush()?;
}
term.show_cursor()?;
return Ok(None);
}
(Key::Char('i' | 'a'), _, true) => {
Expand Down Expand Up @@ -339,7 +336,6 @@ impl FuzzySelect<'_> {
let sel_string_pos_in_items =
self.items.iter().position(|item| item.eq(sel_string));

term.show_cursor()?;
return Ok(sel_string_pos_in_items);
}
(Key::Backspace, _, _) if cursor > 0 => {
Expand Down
6 changes: 1 addition & 5 deletions src/prompts/multi_select.rs
Expand Up @@ -230,8 +230,6 @@ impl MultiSelect<'_> {

let mut checked: Vec<bool> = self.defaults.clone();

term.hide_cursor()?;

loop {
if let Some(ref prompt) = self.prompt {
paging
Expand All @@ -250,7 +248,7 @@ impl MultiSelect<'_> {

term.flush()?;

match term.read_key()? {
match term.read_key_no_cursor()? {
Key::ArrowDown | Key::Tab | Key::Char('j') => {
if sel == !0 {
sel = 0;
Expand Down Expand Up @@ -294,7 +292,6 @@ impl MultiSelect<'_> {
term.clear_last_lines(paging.capacity)?;
}

term.show_cursor()?;
term.flush()?;

return Ok(None);
Expand Down Expand Up @@ -323,7 +320,6 @@ impl MultiSelect<'_> {
}
}

term.show_cursor()?;
term.flush()?;

return Ok(Some(
Expand Down
5 changes: 1 addition & 4 deletions src/prompts/select.rs
Expand Up @@ -218,7 +218,6 @@ impl Select<'_> {
size_vec.push(*size);
}

term.hide_cursor()?;
paging.update_page(sel);

loop {
Expand All @@ -238,7 +237,7 @@ impl Select<'_> {

term.flush()?;

match term.read_key()? {
match term.read_key_no_cursor()? {
Key::ArrowDown | Key::Tab | Key::Char('j') => {
if sel == !0 {
sel = 0;
Expand All @@ -254,7 +253,6 @@ impl Select<'_> {
term.clear_last_lines(paging.capacity)?;
}

term.show_cursor()?;
term.flush()?;

return Ok(None);
Expand Down Expand Up @@ -290,7 +288,6 @@ impl Select<'_> {
}
}

term.show_cursor()?;
term.flush()?;

return Ok(Some(sel));
Expand Down
10 changes: 1 addition & 9 deletions src/prompts/sort.rs
Expand Up @@ -198,8 +198,6 @@ impl Sort<'_> {
let mut order: Vec<_> = (0..self.items.len()).collect();
let mut checked: bool = false;

term.hide_cursor()?;

loop {
if let Some(ref prompt) = self.prompt {
paging.render_prompt(|paging_info| render.sort_prompt(prompt, paging_info))?;
Expand All @@ -216,7 +214,7 @@ impl Sort<'_> {

term.flush()?;

match term.read_key()? {
match term.read_key_no_cursor()? {
Key::ArrowDown | Key::Tab | Key::Char('j') => {
let old_sel = sel;

Expand Down Expand Up @@ -299,9 +297,6 @@ impl Sort<'_> {
term.clear_last_lines(paging.capacity)?;
}

term.show_cursor()?;
term.flush()?;

return Ok(None);
}
}
Expand All @@ -321,9 +316,6 @@ impl Sort<'_> {
}
}

term.show_cursor()?;
term.flush()?;

return Ok(Some(order));
}
_ => {}
Expand Down