Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(agent-tui): hard-code the jan logo to brand yellow #FEC928 (#9237)

Akarshan Biswased97a4707f65
diff --git a/src-tauri/jan-cli/src/main.rs b/src-tauri/jan-cli/src/main.rs
index f7a777790..d54c81a82 100644
--- a/src-tauri/jan-cli/src/main.rs
+++ b/src-tauri/jan-cli/src/main.rs
@@ -5,7 +5,6 @@
//! Build with: cd src-tauri/jan-cli && cargo build --no-default-features --features cli
use clap::{Args, CommandFactory, FromArgMatches, Parser, Subcommand};
-use console::Style;
// Import the library crate so we can access core modules.
// The lib target is named "app_lib" (see [lib] section in Cargo.toml).
@@ -713,12 +712,20 @@ enum McpCommands {
// ── ASCII logo ─────────────────────────────────────────────────────────────
-/// Build a left-aligned, bright-yellow ASCII logo for the help header.
+/// Build a left-aligned ASCII logo in the brand yellow for the help header.
+/// console 0.15 has no truecolor `Color`, so the SGR is written by hand and
+/// gated on the same `colors_enabled` check `console::Style` uses.
fn make_logo() -> String {
- let yellow = Style::new().yellow().bold();
+ use app_lib::core::cli::brand;
+ let sgr = brand::logo_sgr();
+ let color = console::colors_enabled();
let mut out = vec![String::new(), String::new()];
- for l in app_lib::core::cli::brand::LOGO {
- out.push(format!(" {}", yellow.apply_to(l)));
+ for l in brand::LOGO {
+ if color {
+ out.push(format!(" \x1b[1;{sgr}m{l}\x1b[0m"));
+ } else {
+ out.push(format!(" {l}"));
+ }
}
out.join("\n")
}
diff --git a/src-tauri/src/core/cli/brand.rs b/src-tauri/src/core/cli/brand.rs
index b53ecf6df..dbb161b84 100644
--- a/src-tauri/src/core/cli/brand.rs
+++ b/src-tauri/src/core/cli/brand.rs
@@ -14,6 +14,18 @@ pub const LOGO: [&str; 6] = [
pub const LOGO_WIDTH: u16 = 25;
+/// Brand yellow `#FEC928` for the wordmark. Hard-coded truecolor rather than
+/// the terminal's palette yellow, whose shade varies by theme.
+pub const LOGO_RGB: (u8, u8, u8) = (0xFE, 0xC9, 0x28);
+
+/// SGR parameters for the wordmark colour outside the TUI, fitted to the
+/// terminal's colour depth like the splash, so a 256- or 16-colour terminal
+/// gets its nearest palette colour rather than an RGB code it may misrender.
+pub fn logo_sgr() -> String {
+ let (r, g, b) = LOGO_RGB;
+ super::tui::fg_sgr(ratatui::style::Color::Rgb(r, g, b))
+}
+
/// The hand-wave mark as a single glyph, for the header's leading column where
/// the block art has no room. No VS16: the emoji is already presentation-default
/// and the extra selector makes some terminals advance a column ratatui has not
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rs
index f886f3bfb..623df02a1 100644
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@ -38,6 +38,7 @@ mod highlight;
mod markdown;
mod motion;
mod theme;
+pub(super) use theme::fg_sgr;
mod vibe_setting;
use markdown::{
@@ -1782,7 +1783,8 @@ const BANNER_HINTS: &[(&str, &str)] = &[
];
fn banner_lines(banner: &Banner, width: u16) -> Vec<Line<'static>> {
- let accent = Style::new().yellow().bold();
+ let (r, g, b) = brand::LOGO_RGB;
+ let accent = Style::new().fg(theme::Theme::current().fit(Color::Rgb(r, g, b))).bold();
let label = Style::new().dark_gray();
let dim = Style::new().dim();
let indent = " ".repeat(BANNER_INDENT as usize);
@@ -45999,6 +46001,30 @@ mod tests {
);
}
+ /// The wordmark is brand `#FEC928` on truecolor and fitted to the palette
+ /// elsewhere, so a 256- or 16-colour terminal never receives RGB codes.
+ #[test]
+ fn banner_wordmark_is_brand_yellow_fitted_to_depth() {
+ use super::theme::{with_theme, ColorDepth, Theme};
+ use ratatui::style::Color;
+ let (r, g, b) = brand::LOGO_RGB;
+ let wordmark_fg = || {
+ let mut app = test_app();
+ app.push_banner("--safe", true);
+ app.transcript
+ .rows
+ .iter()
+ .flat_map(|row| row.lines(90))
+ .find(|l| l.spans.iter().any(|s| s.content.contains(brand::LOGO[0].trim())))
+ .and_then(|l| l.style.fg.or(l.spans[0].style.fg))
+ };
+ for depth in [ColorDepth::Truecolor, ColorDepth::Ansi256, ColorDepth::Ansi16] {
+ let theme = Theme { light: false, depth };
+ let fg = with_theme(theme, wordmark_fg);
+ assert_eq!(fg, Some(theme.fit(Color::Rgb(r, g, b))), "{depth:?}");
+ }
+ }
+
/// The splash opens on the wordmark alone. The hand-wave block art that used
/// to sit beside it spent 15 rows of a fresh screen on decoration and forced
/// a 61-column floor before the splash would render at all.
diff --git a/src-tauri/src/core/cli/tui/theme.rs b/src-tauri/src/core/cli/tui/theme.rs
index 1374b82e1..6feb96be6 100644
--- a/src-tauri/src/core/cli/tui/theme.rs
+++ b/src-tauri/src/core/cli/tui/theme.rs
@@ -419,6 +419,27 @@ fn rgb_to_ansi16(r: u8, g: u8, b: u8) -> Color {
.unwrap_or(Color::Reset)
}
+/// SGR parameters selecting `color` as the foreground, fitted to the depth the
+/// environment reports. For output printed outside the TUI (`jan --help`),
+/// which never runs `resolve_and_apply` and so reads the depth directly.
+pub(crate) fn fg_sgr(color: Color) -> String {
+ fg_sgr_at(detect_depth(), color)
+}
+
+fn fg_sgr_at(depth: ColorDepth, color: Color) -> String {
+ let fitted = Theme { light: false, depth }.fit(color);
+ match fitted {
+ Color::Rgb(r, g, b) => format!("38;2;{r};{g};{b}"),
+ Color::Indexed(i) => format!("38;5;{i}"),
+ named => match ANSI16.iter().position(|(c, _)| *c == named) {
+ // ANSI16 is in SGR order: 30-37, then the bright 90-97.
+ Some(i @ 0..=7) => format!("{}", 30 + i),
+ Some(i) => format!("{}", 90 + i - 8),
+ None => "39".to_string(),
+ },
+ }
+}
+
/// Decide light vs dark from the config value, deferring to `detect` only when
/// the value is auto/unset (or an unrecognized string). An explicit choice never
/// runs detection. Pure -- `detect` is passed in -- so the precedence is tested
@@ -547,6 +568,17 @@ fn query_osc11_is_light() -> Option<bool> {
mod tests {
use super::*;
+ /// `jan --help` never sends a 256- or 16-colour terminal an RGB code: the
+ /// brand yellow lands on the xterm index or named colour `fit` picks.
+ #[test]
+ fn fg_sgr_fits_the_colour_to_the_depth() {
+ let brand = Color::Rgb(0xFE, 0xC9, 0x28);
+ assert_eq!(fg_sgr_at(ColorDepth::Truecolor, brand), "38;2;254;201;40");
+ assert_eq!(fg_sgr_at(ColorDepth::Ansi256, brand), "38;5;220");
+ assert_eq!(fg_sgr_at(ColorDepth::Ansi16, brand), "33");
+ assert_eq!(fg_sgr_at(ColorDepth::Ansi16, Color::LightYellow), "93");
+ }
+
#[test]
fn luminance_splits_at_the_midpoint() {
assert!(luminance_is_light(255, 255, 255), "white is light");