diff --git a/Cargo.lock b/Cargo.lock index bad988d29d..7d8ed4889e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,16 +358,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" -[[package]] -name = "colored" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" -dependencies = [ - "lazy_static", - "windows-sys 0.48.0", -] - [[package]] name = "component-tests_rust" version = "0.9.999" @@ -420,27 +410,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - [[package]] name = "either" version = "1.13.0" @@ -580,17 +549,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "getrandom" version = "0.4.2" @@ -1335,9 +1293,7 @@ dependencies = [ "better-panic", "cargo_metadata", "clap", - "colored", "dialoguer", - "dirs", "enum-iterator", "human-panic", "iceoryx2", @@ -1345,6 +1301,7 @@ dependencies = [ "iceoryx2-bb-elementary", "iceoryx2-bb-loggers", "iceoryx2-bb-posix", + "iceoryx2-bb-print", "iceoryx2-bb-system-types", "iceoryx2-bb-testing", "iceoryx2-cal", @@ -1750,16 +1707,6 @@ dependencies = [ "windows-link 0.2.1", ] -[[package]] -name = "libredox" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" -dependencies = [ - "bitflags", - "libc", -] - [[package]] name = "libtest-mimic" version = "0.8.2" @@ -1891,12 +1838,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -2023,17 +1964,6 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" -[[package]] -name = "redox_users" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" -dependencies = [ - "getrandom 0.2.15", - "libredox", - "thiserror 1.0.64", -] - [[package]] name = "regex" version = "1.11.0" @@ -2481,7 +2411,7 @@ version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" dependencies = [ - "getrandom 0.4.2", + "getrandom", ] [[package]] @@ -2490,12 +2420,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasip2" version = "1.0.3+wasi-0.2.9" diff --git a/Cargo.toml b/Cargo.toml index 9e81d19738..c2d2b93ac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -205,7 +205,6 @@ cc = { version = "1.0.98" } clap = { version = "4.6.1", features = ["derive"] } enum-iterator = { version = "2.1.0" } better-panic = { version = "0.3.0" } -colored = { version = "2.1" } # NOTE: keep in sync with MODULE.bazel and Iceoryx2Flatbuffers.cmake flatbuffers = { version = "25.12.19", default-features = false } generic-tests = { version = "0.1.2" } @@ -229,7 +228,6 @@ tempfile = { version = "3.12.0" } tiny-fn = { version = "0.1.6" } toml = { version = "0.9.8", default-features = false, features = ["serde", "parse", "display"] } tracing = { version = "0.1.40" } -dirs = { version = "5.0" } dialoguer = { version = "0.8.0" } windows-sys = { version = "0.48.0", features = [ "Win32_Security", diff --git a/doc/release-notes/iceoryx2-unreleased.md b/doc/release-notes/iceoryx2-unreleased.md index df97eaf12c..b9678e9b32 100644 --- a/doc/release-notes/iceoryx2-unreleased.md +++ b/doc/release-notes/iceoryx2-unreleased.md @@ -77,6 +77,7 @@ * [#1845](https://github.com/eclipse-iceoryx/iceoryx2/issues/1845) Reduce imports for usage of the `semantic_string` macro * [#1853](https://github.com/eclipse-iceoryx/iceoryx2/issues/1853) Improve error message in static asserts * [#1891](https://github.com/eclipse-iceoryx/iceoryx2/issues/1891) Rename the tunnel to gateway and move its crates from `iceoryx2-services/` to a top-level `iceoryx2-gateway/` directory +* [#1931](https://github.com/eclipse-iceoryx/iceoryx2/issues/1931) Use ANSI escape sequences in iceoryx2-cli ### Workflow diff --git a/iceoryx2-bb/print/src/lib.rs b/iceoryx2-bb/print/src/lib.rs index 457e703db7..2c739536d6 100644 --- a/iceoryx2-bb/print/src/lib.rs +++ b/iceoryx2-bb/print/src/lib.rs @@ -17,6 +17,29 @@ pub use iceoryx2_pal_print::IsTerminal; +// keep this in sync with iceoryx2-pal/print/lib.rs +pub use iceoryx2_pal_print::RESET; + +// Styles +pub use iceoryx2_pal_print::BOLD; +pub use iceoryx2_pal_print::DIM; +pub use iceoryx2_pal_print::ITALIC; +pub use iceoryx2_pal_print::UNDERLINE; + +// Standard colors +pub use iceoryx2_pal_print::BLUE; +pub use iceoryx2_pal_print::GREEN; +pub use iceoryx2_pal_print::RED; +pub use iceoryx2_pal_print::WHITE; +pub use iceoryx2_pal_print::YELLOW; + +// Bright colors +pub use iceoryx2_pal_print::BRIGHT_BLUE; +pub use iceoryx2_pal_print::BRIGHT_GREEN; +pub use iceoryx2_pal_print::BRIGHT_RED; +pub use iceoryx2_pal_print::BRIGHT_WHITE; +pub use iceoryx2_pal_print::BRIGHT_YELLOW; + pub use iceoryx2_pal_print::stderr; pub use iceoryx2_pal_print::stdout; diff --git a/iceoryx2-cli/BUILD.bazel b/iceoryx2-cli/BUILD.bazel index eb0dc9689a..cf484b8d78 100644 --- a/iceoryx2-cli/BUILD.bazel +++ b/iceoryx2-cli/BUILD.bazel @@ -32,11 +32,11 @@ rust_library( "//iceoryx2:iceoryx2", "//iceoryx2-log/log:iceoryx2-log", "//iceoryx2-bb/loggers:iceoryx2-bb-loggers", + "//iceoryx2-bb/print:iceoryx2-bb-print", "//iceoryx2-pal/posix:iceoryx2-pal-posix", "@crate_index//:anyhow", "@crate_index//:cargo_metadata", "@crate_index//:clap", - "@crate_index//:colored", "@crate_index//:serde", "@crate_index//:yaml_serde", "@crate_index//:serde_json", @@ -58,10 +58,10 @@ rust_binary( "//iceoryx2:iceoryx2", "//iceoryx2-log/log:iceoryx2-log", "//iceoryx2-bb/loggers:iceoryx2-bb-loggers", + "//iceoryx2-bb/print:iceoryx2-bb-print", "@crate_index//:anyhow", "@crate_index//:better-panic", "@crate_index//:clap", - "@crate_index//:colored", "@crate_index//:human-panic", ], ) @@ -128,12 +128,12 @@ rust_binary( "//iceoryx2-bb/elementary:iceoryx2-bb-elementary", "//iceoryx2-log/log:iceoryx2-log", "//iceoryx2-bb/loggers:iceoryx2-bb-loggers", + "//iceoryx2-bb/print:iceoryx2-bb-print", "//iceoryx2-bb/posix:iceoryx2-bb-posix", "//iceoryx2-bb/system-types:iceoryx2-bb-system-types", "@crate_index//:anyhow", "@crate_index//:better-panic", "@crate_index//:clap", - "@crate_index//:colored", "@crate_index//:dialoguer", "@crate_index//:enum-iterator", "@crate_index//:human-panic", diff --git a/iceoryx2-cli/Cargo.toml b/iceoryx2-cli/Cargo.toml index 6e1b0543d5..2508edf4cd 100644 --- a/iceoryx2-cli/Cargo.toml +++ b/iceoryx2-cli/Cargo.toml @@ -14,6 +14,12 @@ version = { workspace = true } [package.metadata] default-run = "iox2" +[features] +default = [] +std = [ + "iceoryx2-bb-print/std", +] + [[bin]] name = "iox2" path = "iox2/src/main.rs" @@ -45,6 +51,7 @@ iceoryx2-services-discovery = { workspace = true, features = ["std"] } iceoryx2 = { workspace = true, features = ["std"] } iceoryx2-cal = { workspace = true, features = ["std"] } iceoryx2-bb-loggers = { workspace = true, features = ["std", "console"] } +iceoryx2-bb-print = { workspace = true } iceoryx2-bb-posix = { workspace = true, features = ["std"] } iceoryx2-bb-system-types = { workspace = true, features = ["std"] } iceoryx2-bb-container = { workspace = true, features = ["std"] } @@ -55,7 +62,6 @@ anyhow = { workspace = true } better-panic = { workspace = true } cargo_metadata = { workspace = true } clap = { workspace = true } -colored = { workspace = true } enum-iterator = { workspace = true } human-panic = { workspace = true } serde = { workspace = true } @@ -63,7 +69,6 @@ yaml_serde = { workspace = true } serde_json = { workspace = true } ron = { workspace = true } toml = { workspace = true } -dirs = { workspace = true } dialoguer = { workspace = true } [dev-dependencies] diff --git a/iceoryx2-cli/iox2-config/src/command/explain.rs b/iceoryx2-cli/iox2-config/src/command/explain.rs index 4c5fe3dae1..c313aaa0f2 100644 --- a/iceoryx2-cli/iox2-config/src/command/explain.rs +++ b/iceoryx2-cli/iox2-config/src/command/explain.rs @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use anyhow::Result; -use colored::Colorize; +use iceoryx2_bb_print::*; use iceoryx2::config::Config; @@ -604,19 +604,19 @@ pub(crate) fn describe_schema(config: &Config) -> Vec
{ pub fn explain() -> Result<()> { let schema = describe_schema(&Config::default()); for section in schema { - println!("\n{}", format!("== {} ==", section.name).bright_green()); + println!("\n{GREEN}== {} =={RESET}", section.name); for entry in section.fields { println!( - "-> {} [{}]", - entry.key.bright_blue(), - entry.value_type.bright_red() + "-> {BRIGHT_BLUE}{} {BRIGHT_WHITE}[{BRIGHT_RED}{}{BRIGHT_WHITE}]{RESET}", + entry.key, entry.value_type ); println!( - " {}", - format!("(Default value: {})", entry.default_value.bright_white()).bright_yellow() + " {BRIGHT_YELLOW}(Default value: {BRIGHT_WHITE}{}{BRIGHT_YELLOW}){RESET}", + entry.default_value ); - println!(" {}", entry.description.italic()); + + println!(" {ITALIC}{}{RESET}", entry.description); } } diff --git a/iceoryx2-cli/iox2-config/src/command/mod.rs b/iceoryx2-cli/iox2-config/src/command/mod.rs index 8bdf8561f1..dbd84a5229 100644 --- a/iceoryx2-cli/iox2-config/src/command/mod.rs +++ b/iceoryx2-cli/iox2-config/src/command/mod.rs @@ -18,30 +18,23 @@ pub(crate) use explain::*; pub(crate) use generate::*; pub(crate) use show::*; -use colored::Colorize; use enum_iterator::all; use iceoryx2_bb_posix::system_configuration::*; +use iceoryx2_bb_print::*; use std::panic::catch_unwind; /// Prints the whole system configuration with all limits, features and /// details to the console. pub(crate) fn print_system_configuration() { - println!( - "{}", - "posix system configuration".underline().bright_green() - ); + println!("{UNDERLINE}{BRIGHT_GREEN}posix system configuration{RESET}"); println!(); - println!(" {}", "system info".underline().bright_green()); + println!(" {UNDERLINE}{BRIGHT_GREEN}system info{RESET}"); all::().for_each(|i| { - println!( - " {:<50} {}", - format!("{i:?}").white(), - format!("{}", i.value()).bright_blue(), - ); + println!(" {WHITE}{i:?} {BRIGHT_BLUE}{}{RESET}", i.value()); }); println!(); - println!(" {}", "limit".underline().bright_green()); + println!(" {UNDERLINE}{BRIGHT_GREEN}limit{RESET}"); for i in all::().collect::>() { let limit = i.value(); let limit = if limit == 0 { @@ -49,39 +42,31 @@ pub(crate) fn print_system_configuration() { } else { limit.to_string() }; - println!(" {:<50} {}", format!("{i:?}").white(), limit.bright_blue(),); + println!(" {WHITE}{i:?} {BRIGHT_BLUE}{}{RESET}", limit,); } println!(); - println!(" {}", "options".underline().bright_green()); + println!(" {UNDERLINE}{BRIGHT_GREEN}options{RESET}"); for i in all::().collect::>() { if i.is_available() { - println!( - " {:<50} {}", - format!("{i:?}").white(), - format!("{}", i.is_available()).bright_blue() - ); + println!(" {WHITE}{i:?} {BRIGHT_BLUE}{}{RESET}", i.is_available()); } else { - println!(" {:<50} {}", format!("{:?}", i), i.is_available(),); + println!(" {WHITE}{i:?} {BRIGHT_RED}{}{RESET}", i.is_available(),); } } println!(); - println!(" {}", "features".underline().bright_green()); + println!(" {UNDERLINE}{BRIGHT_GREEN}features{RESET}"); for i in all::().collect::>() { if i.is_available() { - println!( - " {:<50} {}", - format!("{i:?}").white(), - format!("{}", i.is_available()).bright_blue(), - ); + println!(" {WHITE}{i:?} {BRIGHT_BLUE}{}{RESET}", i.is_available()); } else { - println!(" {:<50} {}", format!("{:?}", i), i.is_available(),); + println!(" {WHITE}{i:?} {BRIGHT_RED}{}{RESET}", i.is_available()); } } println!(); - println!(" {}", "process resource limits".underline().bright_green()); + println!(" {UNDERLINE}{BRIGHT_GREEN}process resource limits{RESET}"); for i in all::().collect::>() { let soft_limit_result = catch_unwind(|| i.soft_limit()); let hard_limit_result = catch_unwind(|| i.hard_limit()); @@ -89,17 +74,16 @@ pub(crate) fn print_system_configuration() { match (soft_limit_result, hard_limit_result) { (Ok(soft), Ok(hard)) => { println!( - " {:<43} soft: {:<24} hard: {}", - format!("{i:?}").white(), - format!("{soft}").bright_blue(), - format!("{hard}").bright_blue() + " {WHITE}{:<43} soft: {BRIGHT_BLUE}{:<24} {WHITE}hard: {BRIGHT_BLUE}{}{RESET}", + format!("{i:?}"), + soft, + hard, ); } (Err(e), _) | (_, Err(e)) => { println!( - " {:<43} Error: {}", - format!("{i:?}").white(), - format!("Unable to acquire limit due to: {e:?}").red() + " {WHITE}{:<43} Error: {RED}Unable to acquire limit due to: {e:?}{RESET}", + format!("{i:?}"), ); } } diff --git a/iceoryx2-cli/iox2-config/src/commands.rs b/iceoryx2-cli/iox2-config/src/commands.rs deleted file mode 100644 index f589a49c09..0000000000 --- a/iceoryx2-cli/iox2-config/src/commands.rs +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright (c) 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache Software License 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license -// which is available at https://opensource.org/licenses/MIT. -// -// SPDX-License-Identifier: Apache-2.0 OR MIT - -use anyhow::Result; -use colored::Colorize; -use dialoguer::Confirm; -use enum_iterator::all; -use iceoryx2::config::Config; -use iceoryx2_bb_posix::directory::Directory; -use iceoryx2_bb_posix::file::Permission; -use iceoryx2_bb_posix::system_configuration::*; -use iceoryx2_bb_posix::*; -use iceoryx2_bb_system_types::file_path::FilePath; -use iceoryx2_bb_system_types::path::Path; -use std::panic::catch_unwind; - -use iceoryx2_cli::config_descriptions::get_sections; - -/// Prints the whole system configuration with all limits, features and details to the console. -pub fn print_system_configuration() { - println!( - "{}", - "posix system configuration".underline().bright_green() - ); - println!(); - println!(" {}", "system info".underline().bright_green()); - all::().for_each(|i| { - println!( - " {:<50} {}", - format!("{i:?}").white(), - format!("{}", i.value()).bright_blue(), - ); - }); - - println!(); - println!(" {}", "limit".underline().bright_green()); - for i in all::().collect::>() { - let limit = i.value(); - let limit = if limit == 0 { - "[ unlimited ]".to_string() - } else { - limit.to_string() - }; - println!(" {:<50} {}", format!("{i:?}").white(), limit.bright_blue(),); - } - - println!(); - println!(" {}", "options".underline().bright_green()); - for i in all::().collect::>() { - if i.is_available() { - println!( - " {:<50} {}", - format!("{i:?}").white(), - format!("{}", i.is_available()).bright_blue() - ); - } else { - println!(" {:<50} {}", format!("{:?}", i), i.is_available(),); - } - } - - println!(); - println!(" {}", "features".underline().bright_green()); - for i in all::().collect::>() { - if i.is_available() { - println!( - " {:<50} {}", - format!("{i:?}").white(), - format!("{}", i.is_available()).bright_blue(), - ); - } else { - println!(" {:<50} {}", format!("{:?}", i), i.is_available(),); - } - } - - println!(); - println!(" {}", "process resource limits".underline().bright_green()); - for i in all::().collect::>() { - let soft_limit_result = catch_unwind(|| i.soft_limit()); - let hard_limit_result = catch_unwind(|| i.hard_limit()); - - match (soft_limit_result, hard_limit_result) { - (Ok(soft), Ok(hard)) => { - println!( - " {:<43} soft: {:<24} hard: {}", - format!("{i:?}").white(), - format!("{soft}").bright_blue(), - format!("{hard}").bright_blue() - ); - } - (Err(e), _) | (_, Err(e)) => { - println!( - " {:<43} Error: {}", - format!("{i:?}").white(), - format!("Unable to acquire limit due to: {e:?}").red() - ); - } - } - } -} - -pub fn show_system_config() -> Result<()> { - print_system_configuration(); - - Ok(()) -} - -pub fn show_current_config() -> Result<()> { - let config = Config::global_config(); - let toml_config = toml::to_string_pretty(&config)?; - println!("{toml_config}"); - - Ok(()) -} - -pub fn generate_global() -> Result<()> { - let mut global_config_path = GLOBAL_CONFIG_PATH; - global_config_path.add_path_entry(&iceoryx2::config::Config::relative_config_path())?; - let filepath = FilePath::from_path_and_file( - &global_config_path, - &iceoryx2::config::Config::default_config_file_name(), - ) - .unwrap(); - - generate(global_config_path, filepath) -} - -pub fn generate_local() -> Result<()> { - let user = iceoryx2_bb_posix::user::User::from_self().unwrap(); - let mut user_config_path = match user.details() { - Some(details) => *details.config_dir(), - None => { - return Err(anyhow::anyhow!( - "User config directory not available on this platform!" - )); - } - }; - user_config_path.add_path_entry(&iceoryx2::config::Config::relative_config_path())?; - let filepath = FilePath::from_path_and_file( - &user_config_path, - &iceoryx2::config::Config::default_config_file_name(), - ) - .unwrap(); - - generate(user_config_path, filepath) -} - -fn generate(config_dir: Path, filepath: FilePath) -> Result<()> { - if let Ok(exists) = file::File::does_exist(&filepath) { - if exists { - let proceed = Confirm::new() - .with_prompt("Configuration file already exists. Do you want to overwrite it?") - .default(false) - .interact()?; - - if !proceed { - println!("Operation cancelled. Configuration file was not overwritten."); - return Ok(()); - } - } else if let Ok(false) = Directory::does_exist(&config_dir) { - Directory::create( - &config_dir, - file::Permission::OWNER_ALL - | Permission::GROUP_READ_EXEC - | Permission::OTHERS_READ_EXEC, - ) - .map_err(|e| anyhow::anyhow!("{:?}", e))?; - } - } - - let toml_string = toml::to_string_pretty(&Config::default())?; - - let mut file = file::FileBuilder::new(&filepath) - .creation_mode(file::CreationMode::PurgeAndCreate) - .permission( - file::Permission::OWNER_WRITE - | file::Permission::OWNER_READ - | file::Permission::GROUP_READ - | file::Permission::OTHERS_READ, - ) - .create() - .map_err(|e| anyhow::anyhow!("{:?}", e))?; - - file.write(toml_string.as_bytes()) - .expect("Failed to write to file"); - - println!("Default configuration is generated at {filepath}"); - - Ok(()) -} - -pub fn print_config_description() -> Result<()> { - let sections = get_sections(); - for section in sections { - println!("\n{}", format!("== {} ==", section.name).bright_green()); - - for entry in section.entries { - println!( - "-> {} [{}]", - entry.key.bright_blue(), - entry.value_type.bright_red() - ); - println!( - " {}", - format!("(Default value: {})", entry.default_value.bright_white()).bright_yellow() - ); - println!(" {}", entry.description.italic()); - } - } - - Ok(()) -} diff --git a/iceoryx2-cli/iox2-gateway/src/command/list.rs b/iceoryx2-cli/iox2-gateway/src/command/list.rs index 6a59407d20..365ef95c29 100644 --- a/iceoryx2-cli/iox2-gateway/src/command/list.rs +++ b/iceoryx2-cli/iox2-gateway/src/command/list.rs @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use anyhow::Result; -use colored::*; +use iceoryx2_bb_print::*; use iceoryx2_cli::command::ExternalCommandFinder; use iceoryx2_cli::command::HostEnvironment; @@ -22,16 +22,16 @@ pub(crate) fn list() -> Result<()> { let commands = ExternalCommandFinder::::commands_with_prefix(COMMAND_PREFIX)?; if commands.is_empty() { - println!("{}", "No gateway backends found.".yellow().bold()); + println!("{YELLOW}{BOLD}No gateway backends found.{RESET}"); println!(); println!("Install a backend to get started, e.g.:"); println!(" cargo install iceoryx2-integrations-zenoh-gateway-cli"); return Ok(()); } - println!("{}", "Discovered Commands:".bright_green().bold()); + println!("{BRIGHT_GREEN}{BOLD}Discovered Commands:{RESET}"); for command in commands { - println!(" {}", command.name.bold()); + println!(" {BOLD}{}{RESET}", command.name); } Ok(()) diff --git a/iceoryx2-cli/lib/src/cli.rs b/iceoryx2-cli/lib/src/cli.rs index 8ff1ee660f..146760cfa3 100644 --- a/iceoryx2-cli/lib/src/cli.rs +++ b/iceoryx2-cli/lib/src/cli.rs @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: Apache-2.0 OR MIT -use colored::*; +use iceoryx2_bb_print::*; #[derive(Default)] pub struct HelpTemplate { @@ -43,8 +43,7 @@ impl HelpTemplate { pub fn build(self) -> String { let mut template = format!( "{{about}}\n\n\ - {} {{usage}}\n\n", - "Usage:".bright_green().bold(), + {GREEN}{BOLD}Usage: {{usage}}{RESET}\n\n" ); if self.has_positionals { @@ -52,25 +51,22 @@ impl HelpTemplate { } template.push_str(&format!( - "{}\n\ - {{options}}", - "Options:".bright_green().bold(), + "{BRIGHT_GREEN}{BOLD}Options:{RESET}\n\ + {BOLD}{{options}}{RESET}", )); if self.has_subcommands { template.push_str(&format!( "\n\n\ - {}\n\ - {{subcommands}}", - "Commands:".bright_green().bold(), + {BRIGHT_GREEN}{BOLD}Commands:{RESET}\n\ + {BOLD}{{subcommands}}{RESET}" )); if self.show_external_command_hint { template.push_str(&format!( "\n\ - {}{}", - " ... ".bold(), - "See external installed commands with --list", + {BOLD}{}{RESET}{}", + " ... ", "See external installed commands with --list", )); } } diff --git a/iceoryx2-cli/lib/src/command.rs b/iceoryx2-cli/lib/src/command.rs index 506edb4f34..dda8b62581 100644 --- a/iceoryx2-cli/lib/src/command.rs +++ b/iceoryx2-cli/lib/src/command.rs @@ -12,7 +12,7 @@ use anyhow::{Context, Result, anyhow}; use cargo_metadata::MetadataCommand; -use colored::*; +use iceoryx2_bb_print::*; use std::env; use std::fs; use std::path::Path; @@ -248,9 +248,9 @@ pub fn execute( pub fn list(prefix: &str) -> Result<()> { let commands = ExternalCommandFinder::::commands_with_prefix(prefix)?; - println!("{}", "Discovered Commands:".bright_green().bold()); + println!("{BRIGHT_GREEN}{BOLD}Discovered Commands:{RESET}"); for command in commands { - println!(" {}", command.name.bold()); + println!("{BOLD} {}{RESET}", command.name); } Ok(()) @@ -261,16 +261,16 @@ pub fn paths(prefix: &str) -> Result<()> { .context("Failed to list search paths")?; if !search_paths.build.is_empty() { - println!("{}", "Build Paths:".bright_green().bold()); + println!("{BRIGHT_GREEN}{BOLD}Build Paths:{RESET}",); for dir in &search_paths.build { - println!(" {}", dir.display().to_string().bold()); + println!("{BOLD} {}{RESET}", dir.display()); } println!(); } if !search_paths.install.is_empty() { - println!("{}", "Install Paths:".bright_green().bold()); + println!("{BRIGHT_GREEN}{BOLD}Install Paths:{RESET}"); for dir in &search_paths.install { - println!(" {}", dir.display().to_string().bold()); + println!("{BOLD} {}{RESET}", dir.display(),); } } diff --git a/iceoryx2-pal/print/src/lib.rs b/iceoryx2-pal/print/src/lib.rs index b4a56a3137..eb9311d280 100644 --- a/iceoryx2-pal/print/src/lib.rs +++ b/iceoryx2-pal/print/src/lib.rs @@ -19,6 +19,29 @@ pub mod writer; pub use writer::*; +// keep this in sync with iceoryx2-bb/print/src/lib.rs +pub const RESET: &str = "\x1b[0m"; + +// Styles +pub const BOLD: &str = "\x1b[1m"; +pub const DIM: &str = "\x1b[2m"; +pub const ITALIC: &str = "\x1b[3m"; +pub const UNDERLINE: &str = "\x1b[4m"; + +// Standard colors +pub const RED: &str = "\x1b[31m"; +pub const GREEN: &str = "\x1b[32m"; +pub const YELLOW: &str = "\x1b[33m"; +pub const BLUE: &str = "\x1b[34m"; +pub const WHITE: &str = "\x1b[37m"; + +// Bright colors +pub const BRIGHT_RED: &str = "\x1b[91m"; +pub const BRIGHT_GREEN: &str = "\x1b[92m"; +pub const BRIGHT_YELLOW: &str = "\x1b[93m"; +pub const BRIGHT_BLUE: &str = "\x1b[94m"; +pub const BRIGHT_WHITE: &str = "\x1b[97m"; + pub trait IsTerminal { fn is_terminal(&self) -> bool; } diff --git a/integrations/ros2/Cargo.lock b/integrations/ros2/Cargo.lock index 65bc2177a2..25260fd383 100644 --- a/integrations/ros2/Cargo.lock +++ b/integrations/ros2/Cargo.lock @@ -294,16 +294,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" -[[package]] -name = "colored" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" -dependencies = [ - "lazy_static", - "windows-sys 0.48.0", -] - [[package]] name = "console" version = "0.14.1" @@ -372,27 +362,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - [[package]] name = "either" version = "1.16.0" @@ -497,17 +466,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "getrandom" version = "0.4.3" @@ -773,9 +731,7 @@ dependencies = [ "better-panic", "cargo_metadata", "clap", - "colored", "dialoguer", - "dirs", "enum-iterator", "human-panic", "iceoryx2", @@ -783,6 +739,7 @@ dependencies = [ "iceoryx2-bb-elementary", "iceoryx2-bb-loggers", "iceoryx2-bb-posix", + "iceoryx2-bb-print", "iceoryx2-bb-system-types", "iceoryx2-cal", "iceoryx2-log", @@ -1004,15 +961,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "libredox" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c943259e342f1e06ff2da7a83eabdfe7f92ce10262688dbf1895ff0b3e6e4652" -dependencies = [ - "libc", -] - [[package]] name = "libtest-mimic" version = "0.8.2" @@ -1123,12 +1071,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "os_str_bytes" version = "6.6.1" @@ -1214,17 +1156,6 @@ dependencies = [ "widestring", ] -[[package]] -name = "redox_users" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" -dependencies = [ - "getrandom 0.2.17", - "libredox", - "thiserror 1.0.69", -] - [[package]] name = "regex" version = "1.12.4" @@ -1453,7 +1384,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom", "once_cell", "rustix", "windows-sys 0.61.2", @@ -1604,7 +1535,7 @@ version = "1.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf3923a6f5c4c6382e0b653c4117f48d631ea17f38ed86e2a828e6f7412f5239" dependencies = [ - "getrandom 0.4.3", + "getrandom", ] [[package]] @@ -1613,12 +1544,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - [[package]] name = "widestring" version = "1.2.1" diff --git a/integrations/zenoh/Cargo.lock b/integrations/zenoh/Cargo.lock index 50ca6b9bbb..f8823bbe4b 100644 --- a/integrations/zenoh/Cargo.lock +++ b/integrations/zenoh/Cargo.lock @@ -465,16 +465,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" -[[package]] -name = "colored" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" -dependencies = [ - "lazy_static", - "windows-sys 0.59.0", -] - [[package]] name = "combine" version = "4.6.7" @@ -755,34 +745,13 @@ dependencies = [ "subtle", ] -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys 0.4.1", -] - [[package]] name = "dirs" version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" dependencies = [ - "dirs-sys 0.5.0", -] - -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users 0.4.6", - "windows-sys 0.48.0", + "dirs-sys", ] [[package]] @@ -793,7 +762,7 @@ checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" dependencies = [ "libc", "option-ext", - "redox_users 0.5.2", + "redox_users", "windows-sys 0.59.0", ] @@ -1533,9 +1502,7 @@ dependencies = [ "better-panic", "cargo_metadata", "clap", - "colored", "dialoguer", - "dirs 5.0.1", "enum-iterator", "human-panic", "iceoryx2", @@ -1543,6 +1510,7 @@ dependencies = [ "iceoryx2-bb-elementary", "iceoryx2-bb-loggers", "iceoryx2-bb-posix", + "iceoryx2-bb-print", "iceoryx2-bb-system-types", "iceoryx2-cal", "iceoryx2-log", @@ -2765,17 +2733,6 @@ dependencies = [ "yasna", ] -[[package]] -name = "redox_users" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" -dependencies = [ - "getrandom 0.2.17", - "libredox", - "thiserror 1.0.69", -] - [[package]] name = "redox_users" version = "0.5.2" @@ -3318,7 +3275,7 @@ version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32824fab5e16e6c4d86dc1ba84489390419a39f97699852b66480bb87d297ed8" dependencies = [ - "dirs 6.0.0", + "dirs", ] [[package]]