From 997b5489a4b37ebf108f1c57360d8c8497e3eb64 Mon Sep 17 00:00:00 2001 From: Robin Bernon Date: Mon, 17 Oct 2022 11:32:24 +0100 Subject: [PATCH 1/4] Fixing default colour scheme to be compatible with windows terminal displays --- src/theme.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/theme.rs b/src/theme.rs index 6f3404d7..7ccb2c33 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -318,24 +318,39 @@ pub struct ColorfulTheme { impl Default for ColorfulTheme { fn default() -> ColorfulTheme { + #[cfg(not(target_os = "windows"))] + mod constants + { + pub(super) const heavy_check_mark: &str = "✔"; + pub(super) const heavy_ballot_x: &str = "✘"; + pub(super) const heavy_right_pointing_angle_quotation_mark_ornament: &str = "❯"; + } + #[cfg(target_os = "windows")] + mod constants + { + pub(super) const heavy_check_mark: &str = "√"; // (subsitute char) + pub(super) const heavy_ballot_x: &str = "×"; // (subsitute char) + pub(super) const heavy_right_pointing_angle_quotation_mark_ornament: &str = ">"; // (subsitute char) + } + ColorfulTheme { defaults_style: Style::new().for_stderr().cyan(), prompt_style: Style::new().for_stderr().bold(), prompt_prefix: style("?".to_string()).for_stderr().yellow(), prompt_suffix: style("›".to_string()).for_stderr().black().bright(), - success_prefix: style("✔".to_string()).for_stderr().green(), + success_prefix: style(constants::heavy_check_mark.to_string()).for_stderr().green(), success_suffix: style("·".to_string()).for_stderr().black().bright(), - error_prefix: style("✘".to_string()).for_stderr().red(), + error_prefix: style(constants::heavy_ballot_x.to_string()).for_stderr().red(), error_style: Style::new().for_stderr().red(), hint_style: Style::new().for_stderr().black().bright(), values_style: Style::new().for_stderr().green(), active_item_style: Style::new().for_stderr().cyan(), inactive_item_style: Style::new().for_stderr(), - active_item_prefix: style("❯".to_string()).for_stderr().green(), + active_item_prefix: style(constants::heavy_right_pointing_angle_quotation_mark_ornament.to_string()).for_stderr().green(), inactive_item_prefix: style(" ".to_string()).for_stderr(), - checked_item_prefix: style("✔".to_string()).for_stderr().green(), - unchecked_item_prefix: style("✔".to_string()).for_stderr().black(), - picked_item_prefix: style("❯".to_string()).for_stderr().green(), + checked_item_prefix: style(constants::heavy_check_mark.to_string()).for_stderr().green(), + unchecked_item_prefix: style(constants::heavy_check_mark.to_string()).for_stderr().black(), + picked_item_prefix: style(constants::heavy_right_pointing_angle_quotation_mark_ornament.to_string()).for_stderr().green(), unpicked_item_prefix: style(" ".to_string()).for_stderr(), #[cfg(feature = "fuzzy-select")] fuzzy_cursor_style: Style::new().for_stderr().black().on_white(), From 1b60b8f52ee8d79ae772fbbd562c98d19e655146 Mon Sep 17 00:00:00 2001 From: Robin Bernon Date: Thu, 3 Nov 2022 12:08:16 +0000 Subject: [PATCH 2/4] Changing to use .wants_emoji() for default display rather than choosing by OS. --- src/theme.rs | 91 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/src/theme.rs b/src/theme.rs index 7ccb2c33..a87cdbbe 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -318,45 +318,58 @@ pub struct ColorfulTheme { impl Default for ColorfulTheme { fn default() -> ColorfulTheme { - #[cfg(not(target_os = "windows"))] - mod constants - { - pub(super) const heavy_check_mark: &str = "✔"; - pub(super) const heavy_ballot_x: &str = "✘"; - pub(super) const heavy_right_pointing_angle_quotation_mark_ornament: &str = "❯"; - } - #[cfg(target_os = "windows")] - mod constants - { - pub(super) const heavy_check_mark: &str = "√"; // (subsitute char) - pub(super) const heavy_ballot_x: &str = "×"; // (subsitute char) - pub(super) const heavy_right_pointing_angle_quotation_mark_ornament: &str = ">"; // (subsitute char) - } - - ColorfulTheme { - defaults_style: Style::new().for_stderr().cyan(), - prompt_style: Style::new().for_stderr().bold(), - prompt_prefix: style("?".to_string()).for_stderr().yellow(), - prompt_suffix: style("›".to_string()).for_stderr().black().bright(), - success_prefix: style(constants::heavy_check_mark.to_string()).for_stderr().green(), - success_suffix: style("·".to_string()).for_stderr().black().bright(), - error_prefix: style(constants::heavy_ballot_x.to_string()).for_stderr().red(), - error_style: Style::new().for_stderr().red(), - hint_style: Style::new().for_stderr().black().bright(), - values_style: Style::new().for_stderr().green(), - active_item_style: Style::new().for_stderr().cyan(), - inactive_item_style: Style::new().for_stderr(), - active_item_prefix: style(constants::heavy_right_pointing_angle_quotation_mark_ornament.to_string()).for_stderr().green(), - inactive_item_prefix: style(" ".to_string()).for_stderr(), - checked_item_prefix: style(constants::heavy_check_mark.to_string()).for_stderr().green(), - unchecked_item_prefix: style(constants::heavy_check_mark.to_string()).for_stderr().black(), - picked_item_prefix: style(constants::heavy_right_pointing_angle_quotation_mark_ornament.to_string()).for_stderr().green(), - unpicked_item_prefix: style(" ".to_string()).for_stderr(), - #[cfg(feature = "fuzzy-select")] - fuzzy_cursor_style: Style::new().for_stderr().black().on_white(), - #[cfg(feature = "fuzzy-select")] - fuzzy_match_highlight_style: Style::new().for_stderr().bold(), - inline_selections: true, + if Term::stdout().features().wants_emoji() { + ColorfulTheme { + defaults_style: Style::new().for_stderr().cyan(), + prompt_style: Style::new().for_stderr().bold(), + prompt_prefix: style("?".to_string()).for_stderr().yellow(), + prompt_suffix: style("›".to_string()).for_stderr().black().bright(), + success_prefix: style("✔".to_string()).for_stderr().green(), + success_suffix: style("·".to_string()).for_stderr().black().bright(), + error_prefix: style("✘".to_string()).for_stderr().red(), + error_style: Style::new().for_stderr().red(), + hint_style: Style::new().for_stderr().black().bright(), + values_style: Style::new().for_stderr().green(), + active_item_style: Style::new().for_stderr().cyan(), + inactive_item_style: Style::new().for_stderr(), + active_item_prefix: style("❯".to_string()).for_stderr().green(), + inactive_item_prefix: style(" ".to_string()).for_stderr(), + checked_item_prefix: style("✔".to_string()).for_stderr().green(), + unchecked_item_prefix: style("✔".to_string()).for_stderr().black(), + picked_item_prefix: style("❯".to_string()).for_stderr().green(), + unpicked_item_prefix: style(" ".to_string()).for_stderr(), + #[cfg(feature = "fuzzy-select")] + fuzzy_cursor_style: Style::new().for_stderr().black().on_white(), + #[cfg(feature = "fuzzy-select")] + fuzzy_match_highlight_style: Style::new().for_stderr().bold(), + inline_selections: true, + } + } else { + ColorfulTheme { + defaults_style: Style::new().for_stderr().cyan(), + prompt_style: Style::new().for_stderr().bold(), + prompt_prefix: style("?".to_string()).for_stderr().yellow(), + prompt_suffix: style("›".to_string()).for_stderr().black().bright(), + success_prefix: style("√".to_string()).for_stderr().green(), + success_suffix: style("·".to_string()).for_stderr().black().bright(), + error_prefix: style("×".to_string()).for_stderr().red(), + error_style: Style::new().for_stderr().red(), + hint_style: Style::new().for_stderr().black().bright(), + values_style: Style::new().for_stderr().green(), + active_item_style: Style::new().for_stderr().cyan(), + inactive_item_style: Style::new().for_stderr(), + active_item_prefix: style(">".to_string()).for_stderr().green(), + inactive_item_prefix: style(" ".to_string()).for_stderr(), + checked_item_prefix: style("√".to_string()).for_stderr().green(), + unchecked_item_prefix: style("√".to_string()).for_stderr().black(), + picked_item_prefix: style(">".to_string()).for_stderr().green(), + unpicked_item_prefix: style(" ".to_string()).for_stderr(), + #[cfg(feature = "fuzzy-select")] + fuzzy_cursor_style: Style::new().for_stderr().black().on_white(), + #[cfg(feature = "fuzzy-select")] + fuzzy_match_highlight_style: Style::new().for_stderr().bold(), + inline_selections: true, + } } } } From e09174dd6d0adf38762a16dfd53aa300315413c7 Mon Sep 17 00:00:00 2001 From: Robin Bernon Date: Thu, 3 Nov 2022 12:22:38 +0000 Subject: [PATCH 3/4] allow clippy::type_complexity --- src/prompts/input.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/prompts/input.rs b/src/prompts/input.rs index 72a71c77..eebed21f 100644 --- a/src/prompts/input.rs +++ b/src/prompts/input.rs @@ -46,6 +46,7 @@ pub struct Input<'a, T> { initial_text: Option, theme: &'a dyn Theme, permit_empty: bool, + #[allow(clippy::type_complexity)] validator: Option Option + 'a>>, #[cfg(feature = "history")] history: Option<&'a mut dyn History>, @@ -72,7 +73,10 @@ impl Input<'_, T> { } /// Changes the prompt text to the post completion text after input is complete - pub fn with_post_completion_text>(&mut self, post_completion_text: S) -> &mut Self { + pub fn with_post_completion_text>( + &mut self, + post_completion_text: S, + ) -> &mut Self { self.post_completion_text = Some(post_completion_text.into()); self } From 01b8bd9b63f31d4664ea03a0d54caaa2dc03c6c2 Mon Sep 17 00:00:00 2001 From: Robin Bernon Date: Thu, 3 Nov 2022 12:25:33 +0000 Subject: [PATCH 4/4] cargo fmt check fix --- src/prompts/fuzzy_select.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prompts/fuzzy_select.rs b/src/prompts/fuzzy_select.rs index 59331b90..83535a96 100644 --- a/src/prompts/fuzzy_select.rs +++ b/src/prompts/fuzzy_select.rs @@ -89,7 +89,7 @@ impl FuzzySelect<'_> { self } - /// Sets the search text that a fuzzy search starts with. + /// Sets the search text that a fuzzy search starts with. pub fn with_initial_text>(&mut self, initial_text: S) -> &mut Self { self.initial_text = initial_text.into(); self @@ -164,7 +164,7 @@ impl FuzzySelect<'_> { /// Like `interact` but allows a specific terminal to be set. fn _interact_on(&self, term: &Term, allow_quit: bool) -> io::Result> { - // Place cursor at the end of the search term + // Place cursor at the end of the search term let mut position = self.initial_text.len(); let mut search_term = self.initial_text.to_owned();