feat: 1.7.5, supports dialoguer

This commit is contained in:
2024-01-12 23:53:12 +08:00
parent c093f865ab
commit 6283c28fff
5 changed files with 71 additions and 8 deletions

View File

@@ -7,6 +7,8 @@ use std::process::Command;
use std::time::{Instant, SystemTime};
use clap::Args;
use dialoguer::Select;
use dialoguer::theme::ColorfulTheme;
use flate2::Compression;
use openpgp_card::crypto_data::Cryptogram;
use rust_util::{
@@ -743,11 +745,26 @@ pub fn select_envelop<'a>(meta: &'a TinyEncryptMeta, key_id: &Option<String>, co
}
}
// TODO optimize select for exec-env
envelops.iter().enumerate().for_each(|(i, envelop)| {
println_ex!("#{} {}", i + 1, util_envelop::format_envelop(envelop, config));
});
let envelop_number = util::read_number("Please select an envelop:", 1, envelops.len());
let use_dialoguer = util_env::get_use_dialoguer();
let envelop_number = if use_dialoguer {
let format_envelops = envelops.iter().map(|envelop| {
format!("#{}", util_envelop::format_envelop(envelop, config))
}).collect::<Vec<_>>();
// TODO catch ctrl-c Term::show_cursor()
let select_result = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Please select envelop: ")
.items(&format_envelops[..])
.default(0)
.report(false)
.clear(true)
.interact();
opt_result!(select_result, "Select envelop error: {}") + 1
} else {
envelops.iter().enumerate().for_each(|(i, envelop)| {
println_ex!("#{} {}", i + 1, util_envelop::format_envelop(envelop, config));
});
util::read_number("Please select an envelop:", 1, envelops.len())
};
let selected_envelop = &envelops[envelop_number - 1];
if silent {

View File

@@ -8,6 +8,7 @@ use crate::consts;
pub const TINY_ENCRYPT_ENV_DEFAULT_ALGORITHM: &str = "TINY_ENCRYPT_DEFAULT_ALGORITHM";
pub const TINY_ENCRYPT_ENV_DEFAULT_COMPRESS: &str = "TINY_ENCRYPT_DEFAULT_COMPRESS";
pub const TINY_ENCRYPT_ENV_NO_PROGRESS: &str = "TINY_ENCRYPT_NO_PROGRESS";
pub const TINY_ENCRYPT_ENV_USE_DIALOGUER: &str = "TINY_ENCRYPT_USE_DIALOGUER";
pub const TINY_ENCRYPT_ENV_PIN: &str = "TINY_ENCRYPT_PIN";
pub const TINY_ENCRYPT_ENV_KEY_ID: &str = "TINY_ENCRYPT_KEY_ID";
pub const TINY_ENCRYPT_ENV_AUTO_SELECT_KEY_IDS: &str = "TINY_ENCRYPT_AUTO_SELECT_KEY_IDS";
@@ -61,4 +62,8 @@ pub fn get_no_progress() -> bool {
pub fn get_no_default_pin_hint() -> bool {
rust_util_env::is_env_on(TINY_ENCRYPT_ENV_NO_DEFAULT_PIN_HINT)
}
}
pub fn get_use_dialoguer() -> bool {
rust_util_env::is_env_on(TINY_ENCRYPT_ENV_USE_DIALOGUER)
}