Skip to content
9 changes: 8 additions & 1 deletion crates/forge_main/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2829,10 +2829,17 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
}
});

// Check if nerd fonts should be used (NERD_FONT or USE_NERD_FONT set to "1")
let use_nerd_font = std::env::var("NERD_FONT")
.or_else(|_| std::env::var("USE_NERD_FONT"))
.map(|val| val == "1")
.unwrap_or(true); // Default to true

let rprompt = ZshRPrompt::default()
.agent(std::env::var("_FORGE_ACTIVE_AGENT").ok().map(AgentId::new))
.model(model_id)
.token_count(conversation.and_then(|conversation| conversation.token_count()));
.token_count(conversation.and_then(|conversation| conversation.token_count()))
.use_nerd_font(use_nerd_font);

Some(rprompt.to_string())
}
Expand Down
56 changes: 47 additions & 9 deletions crates/forge_main/src/zsh/rprompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@ use crate::utils::humanize_number;
/// Formats shell prompt information with appropriate colors:
/// - Inactive state (no tokens): dimmed colors
/// - Active state (has tokens): bright white/cyan colors
#[derive(Default, Setters)]
#[derive(Setters)]
pub struct ZshRPrompt {
agent: Option<AgentId>,
model: Option<ModelId>,
token_count: Option<TokenCount>,
/// Controls whether to render nerd font symbols. Defaults to `true`.
#[setters(into)]
use_nerd_font: bool,
}

impl Default for ZshRPrompt {
fn default() -> Self {
Self {
agent: None,
model: None,
token_count: None,
use_nerd_font: true,
}
}
}

const AGENT_SYMBOL: &str = "\u{f167a}";
Expand All @@ -33,10 +47,14 @@ impl Display for ZshRPrompt {

// Add agent
let agent_id = self.agent.clone().unwrap_or_default();
let agent_id = format!(
"{AGENT_SYMBOL} {}",
let agent_id = if self.use_nerd_font {
format!(
"{AGENT_SYMBOL} {}",
agent_id.to_string().to_case(Case::UpperSnake)
)
} else {
agent_id.to_string().to_case(Case::UpperSnake)
);
};
let styled = if active {
agent_id.zsh().bold().fg(ZshColor::WHITE)
} else {
Expand All @@ -60,7 +78,11 @@ impl Display for ZshRPrompt {

// Add model
if let Some(ref model_id) = self.model {
let model_id = format!("{MODEL_SYMBOL} {}", model_id);
let model_id = if self.use_nerd_font {
format!("{MODEL_SYMBOL} {}", model_id)
} else {
model_id.to_string()
};
let styled = if active {
model_id.zsh().fg(ZshColor::CYAN)
} else {
Expand All @@ -74,8 +96,6 @@ impl Display for ZshRPrompt {

#[cfg(test)]
mod tests {
use insta::assert_snapshot;

use super::*;

#[test]
Expand All @@ -85,7 +105,9 @@ mod tests {
.agent(Some(AgentId::new("forge")))
.model(Some(ModelId::new("gpt-4")))
.to_string();
assert_snapshot!(actual);

let expected = " %B%F{240}\u{f167a} FORGE%f%b %F{240}\u{ec19} gpt-4%f";
assert_eq!(actual, expected);
}

#[test]
Expand All @@ -96,6 +118,22 @@ mod tests {
.model(Some(ModelId::new("gpt-4")))
.token_count(Some(TokenCount::Actual(1500)))
.to_string();
assert_snapshot!(actual);

let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %F{134}\u{ec19} gpt-4%f";
assert_eq!(actual, expected);
}

#[test]
fn test_rprompt_without_nerdfonts() {
// Test with nerdfonts disabled
let actual = ZshRPrompt::default()
.agent(Some(AgentId::new("forge")))
.model(Some(ModelId::new("gpt-4")))
.token_count(Some(TokenCount::Actual(1500)))
.use_nerd_font(false)
.to_string();

let expected = " %B%F{15}FORGE%f%b %B%F{15}1.5k%f%b %F{134}gpt-4%f";
assert_eq!(actual, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ else
typeset -h _FORGE_CAT_CMD="cat"
fi
typeset -h _FORGE_COMMANDS=""
export _FORGE_CONVERSATION_ID
export _FORGE_ACTIVE_AGENT
function _forge_action_default() {
local user_action="$1"
local input_text="$2"
Expand Down

This file was deleted.

This file was deleted.

76 changes: 47 additions & 29 deletions shell-plugin/doctor.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,6 @@ fi
# 2. Check if forge is installed and in PATH
print_section "Forge Installation"

# Check FORGE_BIN environment variable
if [[ -n "$FORGE_BIN" ]]; then
if [[ ! -e "$FORGE_BIN" ]]; then
print_result fail "FORGE_BIN path does not exist: ${FORGE_BIN}"
elif [[ ! -f "$FORGE_BIN" ]]; then
print_result fail "FORGE_BIN is not a file: ${FORGE_BIN}"
elif [[ ! -x "$FORGE_BIN" ]]; then
print_result fail "FORGE_BIN is not executable: ${FORGE_BIN}"
else
print_result pass "FORGE_BIN: ${FORGE_BIN}"
fi
else
print_result warn "FORGE_BIN not set" "export FORGE_BIN=\$(which forge)"
fi

# Check if forge is in PATH
if command -v forge &> /dev/null; then
local forge_path=$(command -v forge)
Expand All @@ -136,7 +121,7 @@ if command -v forge &> /dev/null; then
print_result info "${forge_path}"
fi
else
print_result fail "Forge binary not found in PATH" "Install from: https://github.com/your-org/forge"
print_result fail "Forge binary not found in PATH" "Installation: npm i -g forgecode@latest"
fi

# 3. Check shell plugin
Expand All @@ -148,7 +133,7 @@ if [[ -n "$_FORGE_PLUGIN_LOADED" ]]; then
else
print_result fail "Forge plugin not loaded"
print_result instruction "Add to your ~/.zshrc:"
print_result code "eval \"\$(\$FORGE_BIN zsh plugin)\""
print_result code "eval \"\$(forge zsh plugin)\""
fi


Expand Down Expand Up @@ -191,13 +176,13 @@ if [[ -n "$_FORGE_THEME_LOADED" ]]; then
elif (( $+functions[p10k] )); then
print_result info "Powerlevel10k detected (not using Forge theme)"
elif [[ -n "$ZSH_THEME" ]]; then
print_result warn "Using theme: ${ZSH_THEME}"
print_result fail "Using theme: ${ZSH_THEME}"
print_result instruction "To use Forge theme, add to ~/.zshrc:"
print_result code "eval \"\$(\$FORGE_BIN zsh theme)\""
print_result code "eval \"\$(forge zsh theme)\""
else
print_result warn "No theme loaded"
print_result fail "No theme loaded"
print_result instruction "To use Forge theme, add to ~/.zshrc:"
print_result code "eval \"\$(\$FORGE_BIN zsh theme)\""
print_result code "eval \"\$(forge zsh theme)\""
fi

# 5. Check dependencies
Expand Down Expand Up @@ -295,15 +280,48 @@ else
fi

# Check font and Nerd Font support
# Show actual icons used in Forge theme
echo ""
echo "$(bold "Font Check [Manual Verification Required]")"
print_section "Nerd Font"

# Check if Nerd Font is enabled via environment variables
if [[ -n "$NERD_FONT" ]]; then
if [[ "$NERD_FONT" == "1" || "$NERD_FONT" == "true" ]]; then
print_result pass "NERD_FONT: enabled"
else
print_result fail "NERD_FONT: disabled (${NERD_FONT})"
print_result instruction "Enable Nerd Font by setting:"
print_result code "export NERD_FONT=1"
fi
elif [[ -n "$USE_NERD_FONT" ]]; then
if [[ "$USE_NERD_FONT" == "1" || "$USE_NERD_FONT" == "true" ]]; then
print_result pass "USE_NERD_FONT: enabled"
else
print_result fail "USE_NERD_FONT: disabled (${USE_NERD_FONT})"
print_result instruction "Enable Nerd Font by setting:"
print_result code "export NERD_FONT=1"
fi
else
print_result pass "Nerd Font: enabled (default)"
print_result info "Forge will auto-detect based on terminal capabilities"
fi

# Show actual icons used in Forge theme for manual verification (skip if explicitly disabled)
local nerd_font_disabled=false
if [[ -n "$NERD_FONT" && "$NERD_FONT" != "1" && "$NERD_FONT" != "true" ]]; then
nerd_font_disabled=true
elif [[ -n "$USE_NERD_FONT" && "$USE_NERD_FONT" != "1" && "$USE_NERD_FONT" != "true" ]]; then
nerd_font_disabled=true
fi

if [[ "$nerd_font_disabled" == "false" ]]; then
echo ""
echo "$(bold "Visual Check [Manual Verification Required]")"
echo " $(bold "󱙺 FORGE 33.0k") $(cyan " tonic-1.0")"
echo ""
echo " Forge uses Nerd Fonts to enrich cli experience, can you see all the icons clearly without any overlap?"
echo " If you see boxes (□) or question marks (?), install a Nerd Font from:"
echo " $(dim "https://www.nerdfonts.com/")"
echo ""
echo ""
echo " Forge uses Nerd Fonts to enrich cli experience, can you see all the icons clearly without any overlap?"
echo " If you see boxes (□) or question marks (?), install a Nerd Font from:"
echo " $(dim "https://www.nerdfonts.com/")"
echo ""
fi

# Summary
echo ""
Expand Down
4 changes: 4 additions & 0 deletions shell-plugin/lib/config.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ fi

# Commands cache - loaded lazily on first use
typeset -h _FORGE_COMMANDS=""

# Export variables for the forge child process
export _FORGE_CONVERSATION_ID
export _FORGE_ACTIVE_AGENT
Loading