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

misc: set color scheme #773

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ git commit -m "<type>[optional scope]: <description>"
# An example:
git commit -m "feat: add xxx to the pixi.toml"
```

## Color decisions in the ui code
We use the `console::style` function to colorize the output of the ui.
```rust
use console::style;
println!("{} {}", style("Hello").green(), style("world").red());
```

To sync the colors of the different parts of the ui, we use the following rules:
- `style("environment").magenta()`: The environment name
- `style("feature").cyan()`: The feature name
- `style("task").blue()`: The task name

These styles are put in the `consts` module or are a `.fancy_display()` on the names. If you want to add a new generic color, please add it there.
63 changes: 25 additions & 38 deletions src/cli/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{fmt::Display, fs, path::PathBuf};

use chrono::{DateTime, Local};
use clap::Parser;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::{GenericVirtualPackage, Platform};
use rattler_virtual_packages::VirtualPackage;
Expand All @@ -11,7 +12,8 @@ use serde_with::DisplayFromStr;
use tokio::task::spawn_blocking;

use crate::progress::await_in_progress;
use crate::{config, Project};
use crate::task::TaskName;
use crate::{config, EnvironmentName, FeatureName, Project};

static WIDTH: usize = 18;

Expand Down Expand Up @@ -41,14 +43,14 @@ pub struct ProjectInfo {

#[derive(Serialize)]
pub struct EnvironmentInfo {
name: String,
features: Vec<String>,
name: EnvironmentName,
features: Vec<FeatureName>,
solve_group: Option<String>,
environment_size: Option<String>,
dependencies: Vec<String>,
pypi_dependencies: Vec<String>,
platforms: Vec<Platform>,
tasks: Vec<String>,
tasks: Vec<TaskName>,
channels: Vec<String>,
// prefix: Option<PathBuf>, add when PR 674 is merged
}
Expand All @@ -58,14 +60,18 @@ impl Display for EnvironmentInfo {
let bold = console::Style::new().bold();
writeln!(
f,
"{}",
console::style(self.name.clone()).bold().blue().underlined()
"{:>WIDTH$}: {}",
bold.apply_to("Environment"),
self.name.fancy_display().bold()
)?;
writeln!(
f,
"{:>WIDTH$}: {}",
bold.apply_to("Features"),
self.features.join(", ")
self.features
.iter()
.map(|feature| feature.fancy_display())
.format(", ")
)?;
if let Some(solve_group) = &self.solve_group {
writeln!(
Expand All @@ -80,12 +86,7 @@ impl Display for EnvironmentInfo {
writeln!(f, "{:>WIDTH$}: {}", bold.apply_to("Environment size"), size)?;
}
if !self.channels.is_empty() {
let channels_list = self
.channels
.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(", ");
let channels_list = self.channels.iter().map(|c| c.to_string()).format(", ");
writeln!(
f,
"{:>WIDTH$}: {}",
Expand All @@ -100,12 +101,7 @@ impl Display for EnvironmentInfo {
self.dependencies.len()
)?;
if !self.dependencies.is_empty() {
let dependencies_list = self
.dependencies
.iter()
.map(|d| d.to_string())
.collect::<Vec<_>>()
.join(", ");
let dependencies_list = self.dependencies.iter().map(|d| d.to_string()).format(", ");
writeln!(
f,
"{:>WIDTH$}: {}",
Expand All @@ -119,8 +115,7 @@ impl Display for EnvironmentInfo {
.pypi_dependencies
.iter()
.map(|d| d.to_string())
.collect::<Vec<_>>()
.join(", ");
.format(", ");
writeln!(
f,
"{:>WIDTH$}: {}",
Expand All @@ -130,12 +125,7 @@ impl Display for EnvironmentInfo {
}

if !self.platforms.is_empty() {
let platform_list = self
.platforms
.iter()
.map(|p| p.to_string())
.collect::<Vec<_>>()
.join(", ");
let platform_list = self.platforms.iter().map(|p| p.to_string()).format(", ");
writeln!(
f,
"{:>WIDTH$}: {}",
Expand All @@ -144,12 +134,7 @@ impl Display for EnvironmentInfo {
)?;
}
if !self.tasks.is_empty() {
let tasks_list = self
.tasks
.iter()
.map(|t| t.to_string())
.collect::<Vec<_>>()
.join(", ");
let tasks_list = self.tasks.iter().map(|t| t.fancy_display()).format(", ");
writeln!(f, "{:>WIDTH$}: {}", bold.apply_to("Tasks"), tasks_list)?;
}
Ok(())
Expand All @@ -171,7 +156,6 @@ pub struct Info {
}
impl Display for Info {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let blue = console::Style::new().blue();
let bold = console::Style::new().bold();
let cache_dir = match &self.cache_dir {
Some(path) => path.to_string_lossy().to_string(),
Expand All @@ -182,7 +166,7 @@ impl Display for Info {
f,
"{:>WIDTH$}: {}",
bold.apply_to("Pixi version"),
blue.apply_to(&self.version)
console::style(&self.version).green()
)?;
writeln!(
f,
Expand Down Expand Up @@ -310,12 +294,15 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let tasks = env
.tasks(None, true)
.ok()
.map(|t| t.into_keys().map(|k| k.to_string()).collect())
.map(|t| t.into_keys().cloned().collect())
.unwrap_or_default();

EnvironmentInfo {
name: env.name().as_str().to_string(),
features: env.features(true).map(|f| f.name.to_string()).collect(),
name: env.name().clone(),
features: env
.features(true)
.map(|feature| feature.name.clone())
.collect(),
solve_group: env.manifest().solve_group.clone(),
environment_size: None,
dependencies: env
Expand Down
4 changes: 2 additions & 2 deletions src/cli/project/channel/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub fn execute(project: Project, args: Args) -> miette::Result<()> {
.map(|e| {
println!(
"{} {}",
console::style("Environment:").bold().blue(),
console::style(e.name()).bold()
console::style("Environment:").bold().bright(),
e.name().fancy_display()
);
e.channels()
})
Expand Down
63 changes: 35 additions & 28 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::activation::get_environment_variables;
use crate::project::errors::UnsupportedPlatformError;
use crate::task::{
AmbiguousTask, ExecutableTask, FailedToParseShellScript, InvalidWorkingDirectory,
SearchEnvironments, TaskAndEnvironment, TaskGraph,
SearchEnvironments, TaskAndEnvironment, TaskGraph, TaskName,
};
use crate::{Project, UpdateLockFileOptions};

Expand Down Expand Up @@ -113,9 +113,11 @@ pub async fn execute(args: Args) -> miette::Result<()> {
"{}{}{}{}{}",
console::Emoji("✨ ", ""),
console::style("Pixi task (").bold(),
console::style(executable_task.run_environment.name())
.bold()
.cyan(),
executable_task
.run_environment
.name()
.fancy_display()
.bold(),
console::style("): ").bold(),
executable_task.display_command(),
);
Expand Down Expand Up @@ -153,26 +155,26 @@ pub async fn execute(args: Args) -> miette::Result<()> {

/// Called when a command was not found.
fn command_not_found<'p>(project: &'p Project, explicit_environment: Option<Environment<'p>>) {
let available_tasks: HashSet<String> = if let Some(explicit_environment) = explicit_environment
{
explicit_environment
.tasks(Some(Platform::current()), true)
.into_iter()
.flat_map(|tasks| tasks.into_keys())
.map(ToOwned::to_owned)
.collect()
} else {
project
.environments()
.into_iter()
.flat_map(|env| {
env.tasks(Some(Platform::current()), true)
.into_iter()
.flat_map(|tasks| tasks.into_keys())
.map(ToOwned::to_owned)
})
.collect()
};
let available_tasks: HashSet<TaskName> =
if let Some(explicit_environment) = explicit_environment {
explicit_environment
.tasks(Some(Platform::current()), true)
.into_iter()
.flat_map(|tasks| tasks.into_keys())
.map(ToOwned::to_owned)
.collect()
} else {
project
.environments()
.into_iter()
.flat_map(|env| {
env.tasks(Some(Platform::current()), true)
.into_iter()
.flat_map(|tasks| tasks.into_keys())
.map(ToOwned::to_owned)
})
.collect()
};

if !available_tasks.is_empty() {
eprintln!(
Expand All @@ -181,7 +183,7 @@ fn command_not_found<'p>(project: &'p Project, explicit_environment: Option<Envi
.into_iter()
.sorted()
.format_with("\n", |name, f| {
f(&format_args!("\t{}", console::style(name).bold()))
f(&format_args!("\t{}", name.fancy_display().bold()))
})
);
}
Expand Down Expand Up @@ -271,12 +273,17 @@ fn disambiguate_task_interactive<'p>(
.iter()
.map(|(env, _)| env.name())
.collect_vec();
dialoguer::Select::with_theme(&ColorfulTheme::default())
let theme = ColorfulTheme {
active_item_style: console::Style::new().for_stderr().magenta(),
..ColorfulTheme::default()
};

dialoguer::Select::with_theme(&theme)
.with_prompt(format!(
"The task '{}' {}can be run in multiple environments.\n\nPlease select an environment to run the task in:",
problem.task_name,
problem.task_name.fancy_display(),
if let Some(dependency) = &problem.depended_on_by {
format!("(depended on by '{}') ", dependency.0)
format!("(depended on by '{}') ", dependency.0.fancy_display())
} else {
String::new()
}
Expand Down
Loading
Loading