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

Making default color scheme compatible for windows terminal displays #222

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/prompts/fuzzy_select.rs
Expand Up @@ -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<S: Into<String>>(&mut self, initial_text: S) -> &mut Self {
self.initial_text = initial_text.into();
self
Expand Down Expand Up @@ -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<Option<usize>> {
// 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();

Expand Down
6 changes: 5 additions & 1 deletion src/prompts/input.rs
Expand Up @@ -46,6 +46,7 @@ pub struct Input<'a, T> {
initial_text: Option<String>,
theme: &'a dyn Theme,
permit_empty: bool,
#[allow(clippy::type_complexity)]
validator: Option<Box<dyn FnMut(&T) -> Option<String> + 'a>>,
#[cfg(feature = "history")]
history: Option<&'a mut dyn History<T>>,
Expand All @@ -72,7 +73,10 @@ impl<T> Input<'_, T> {
}

/// Changes the prompt text to the post completion text after input is complete
pub fn with_post_completion_text<S: Into<String>>(&mut self, post_completion_text: S) -> &mut Self {
pub fn with_post_completion_text<S: Into<String>>(
&mut self,
post_completion_text: S,
) -> &mut Self {
self.post_completion_text = Some(post_completion_text.into());
self
}
Expand Down
76 changes: 52 additions & 24 deletions src/theme.rs
Expand Up @@ -318,30 +318,58 @@ pub struct ColorfulTheme {

impl Default for ColorfulTheme {
fn default() -> ColorfulTheme {
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,
if Term::stdout().features().wants_emoji() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can store this in a variable and use it in emoji lines instead of this big if condition block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry do you mind clarifying what you mean here? I dont understand. Do you want a variable for the term features?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let has_emoji = Term::stderr().features().wants_emoji();

// later
ColorfulTheme {
  error_prefix: style((if has_emoji { "✘" } else { "×" }).to_string()).for_stderr().red(),
}

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,
}
}
}
}
Expand Down