Skip to content
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
28 changes: 20 additions & 8 deletions cli/src/command_surface.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use std::fmt::Write;

use crate::{cli_schema, services};
use services::style::{banner_with_gradient, command_name, heading};
use services::style::{banner_link, banner_with_gradient, command_name, heading};

const SCE_BANNER_LINES: &[&str] = &[
r" ______ ______ ________ ",
r".' ____ \ .' ___ ||_ __ | ",
r"| (___ \_|/ .' \_| | |_ \_| ",
r" _.____`. | | | _| _ ",
r"| \____) |\ `.___.'\ _| |__/ | ",
r" \______.' `.____ .'|________| ",
"███████╗ ██████╗███████╗",
"██╔════╝██╔════╝██╔════╝",
"███████╗██║ █████╗",
"╚════██║██║ ██╔══╝",
"███████║╚██████╗███████╗",
"╚══════╝ ╚═════╝╚══════╝",
];
const SCE_BANNER_VISIT_PREFIX: &str = "Visit ";
const SCE_BANNER_VISIT_LINK_TEXT: &str = "sce.crocoder.dev";
const SCE_BANNER_VISIT_LINK_URL: &str = "https://sce.crocoder.dev";
const SCE_BANNER_VISIT_SUFFIX: &str = " to learn more.";

const HELP_COMMAND_NAME: &str = "help";
const HELP_COMMAND_PURPOSE: &str = "Show help for the current CLI surface";
Expand Down Expand Up @@ -130,10 +134,18 @@ fn push_section(out: &mut String, section: &str) {
out.push_str(section);
}

fn sce_banner() -> String {
format!(
"{}\n{SCE_BANNER_VISIT_PREFIX}{}{SCE_BANNER_VISIT_SUFFIX}",
banner_with_gradient(SCE_BANNER_LINES),
banner_link(SCE_BANNER_VISIT_LINK_TEXT, SCE_BANNER_VISIT_LINK_URL)
)
}

pub fn help_text() -> String {
let mut output = String::new();

push_section(&mut output, &banner_with_gradient(SCE_BANNER_LINES));
push_section(&mut output, &sce_banner());
push_blank_line(&mut output);
push_blank_line(&mut output);

Expand Down
30 changes: 30 additions & 0 deletions cli/src/services/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ fn is_help_placeholder(token: &str) -> bool {
.any(|ch| ch.is_ascii_uppercase() || matches!(ch, '<' | '>' | '[' | ']'))
}

#[must_use]
pub fn banner_link(text: &str, url: &str) -> String {
banner_link_with_color_policy(text, url, supports_color())
}

#[must_use]
pub(crate) fn banner_link_with_color_policy(text: &str, url: &str, color_enabled: bool) -> String {
style_if(text, color_enabled, |s| {
format!("\x1b]8;;{url}\x1b\\{}\x1b]8;;\x1b\\", s.cyan().underline())
})
}

/// Gradient color endpoints for the ASCII art banner.
/// Right side: cyan (0, 255, 255), Left side: magenta (255, 0, 255).
const GRADIENT_COLOR_RIGHT: (u8, u8, u8) = (0, 255, 255);
Expand Down Expand Up @@ -359,6 +371,24 @@ mod tests {
assert!(styled.contains("SCE-ERR-RUNTIME"));
}

#[test]
fn banner_link_wraps_cyan_underlined_text_in_hyperlink_when_color_enabled() {
let styled =
banner_link_with_color_policy("sce.crocoder.dev", "https://sce.crocoder.dev", true);
assert_eq!(
styled,
"\x1b]8;;https://sce.crocoder.dev\x1b\\\x1b[4m\x1b[36msce.crocoder.dev\x1b[39m\x1b[0m\x1b]8;;\x1b\\"
);
}

#[test]
fn banner_link_is_plain_when_color_disabled() {
assert_eq!(
banner_link_with_color_policy("sce.crocoder.dev", "https://sce.crocoder.dev", false),
"sce.crocoder.dev"
);
}

#[test]
fn error_code_is_plain_when_color_disabled() {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion context/cli/cli-command-surface.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions context/cli/styling-service.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading