Comments (4)
I found a magic solution:
- add crate
ctrlc
, justcargo add ctrlc
- call
ctrlc::set_handler
before calldialoguer
let _ = ctrlc::set_handler(move || {
// DO NOTHING
});
- process dialoguer error
use dialoguer::console::Term;
if dialoguer_result.is_err() {
let _ = Term::stderr().show_cursor();
}
from dialoguer.
Thanks for this. It is a much better solution for me with a clap
program than showing the cursor in set_handler
. My example:
fn main() -> anyhow::Result<()> {
// Ignore SIGINT so we can handle it ourselves
ctrlc::set_handler(move || {}).expect("Error setting Ctrl-C handler");
let app = App::parse();
match &app.command {
// Handle clap commands
}
.map_err(|e| {
let _ = Term::stdout().show_cursor();
e
})
}
from dialoguer.
There are two challenges with dialoguer at the moment about this. The underlying console library is now quite decent at restoring terminal state in more cases, even in light of ctrl-c. However in dialoguer the cursor is explicitly hidden in many interactions which results in this sort of behavior.
It would be weird for console to try to install a ctrl-c handler though. One option would be to say the components do not hide the cursor but Term::read_key_no_cursor
is added which is like read_key
but does not show the cursor. This would result in similar behavior as we have today but it could safely restore the cursor in light of ctrl-c.
from dialoguer.
Playing with this a bit now I do wonder if it would not be a better solution to just provide a convenient way to reset the terminal on ctrl-c with a utility function.
fn main() -> anyhow::Result<()> {
ctrlc::set_handler(|| console::reset_terminal(); };
// ...
}
from dialoguer.
Related Issues (20)
- Feature request: option for newline for `Input`
- Feature suggestion: prompt timeouts HOT 1
- BUG - Input with utf8 chars HOT 1
- Password prompt freezes program when a long password is entered HOT 4
- Unable to change selection of a Select in certain terminals.
- Feature: Tab to select line and move down HOT 1
- Select : prompt is no longer displayed HOT 1
- Cursor disappears after using Select HOT 1
- Select - Let users scroll faster with page-down/up
- Custom shortcuts/keybindings/hotkeys support HOT 3
- FuzzySelect returns wrong index if items has duplicate entries HOT 3
- Feature request: alert message with pressing enter as only option
- Add some example pictures to the readme with links to the corresponding file in examples.
- Tab completion doesn't work on windows. HOT 1
- Backspace behavior at the end of line
- Duplicate line when wrapped HOT 1
- `Password`: Returns `Err` when used in conjunction with input via redirect or pipe HOT 2
- feat: support multi line input HOT 1
- [Issue] No visual indecator on selected items on Windows Terminal HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dialoguer.