From f30b3c561253e8ef9c5ba9103cb24252fb3e8cf0 Mon Sep 17 00:00:00 2001 From: eatradish Date: Tue, 6 Aug 2024 13:47:47 +0800 Subject: [PATCH] fix: handle Ctrl-C in `ciel new` --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/actions/onboarding.rs | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9078de1..de1223e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,6 +358,7 @@ dependencies = [ "clap", "clap_complete", "console", + "ctrlc", "dialoguer", "dotenvy", "faster-hex", @@ -524,6 +525,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctrlc" +version = "3.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "672465ae37dc1bc6380a6547a8883d5dd397b0f1faaad4f265726cc7042a5345" +dependencies = [ + "nix 0.28.0", + "windows-sys 0.52.0", +] + [[package]] name = "deranged" version = "0.3.11" diff --git a/Cargo.toml b/Cargo.toml index e6f1863..5a88a9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ sha2 = "0.10" time = { version = "0.3", default-features = false, features = ["serde-human-readable", "macros"] } fs3 = "0.5" clap = { version = "^4", features = ["wrap_help", "string", "env"] } +ctrlc = "3.4.4" # repo scan ar = "0.9" faster-hex = "0.9" diff --git a/src/actions/onboarding.rs b/src/actions/onboarding.rs index bbe0d07..51c9be8 100644 --- a/src/actions/onboarding.rs +++ b/src/actions/onboarding.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, Result}; -use console::{style, user_attended}; +use console::{style, user_attended, Term}; use dialoguer::{theme::ColorfulTheme, Confirm, Input}; use std::{fs, path::Path}; @@ -17,6 +17,10 @@ use super::{load_os, mount_fs}; /// Show interactive onboarding guide, triggered by issuing `ciel new` pub fn onboarding(custom_tarball: Option<&String>, arch: Option<&str>) -> Result<()> { + ctrlc::set_handler(move || { + let _ = Term::stderr().show_cursor(); + }).expect("Error setting Ctrl-C handler"); + let theme = ColorfulTheme::default(); info!("Welcome to ciel!"); if Path::new(".ciel").exists() {