fix(ui): Fix ASCII banner colors and add syntax display to explain mode

## Fixes

### 1. ASCII Banner Colors Fixed
- Changed from heredoc to echo -e statements
- ANSI escape codes now render properly
- Cyan and yellow colors display correctly
- No more literal escape codes showing

Before:
[0;36m
    ____             __       ____
(escape codes displayed as text)

After:
Properly colored cyan ASCII art with yellow tagline

### 2. Enhanced Explain Mode with Syntax
- Added SYNOPSIS/SYNTAX section before description
- Extracts syntax from man pages automatically
- Shows command usage patterns clearly
- Works for regular commands and shell builtins
- Multiple fallbacks for robustness:
  1. Man page SYNOPSIS section
  2. Command --help usage line
  3. Generic fallback pattern

Example output:
SYNTAX:
  grep [OPTION...] PATTERNS [FILE...]
  grep [OPTION...] -e PATTERNS ... [FILE...]

Description: Search for text pattern in files recursively

## Testing
-  Banner colors display correctly
-  Syntax shows for tar, grep, find
-  Works with shell builtins (cd, echo)
-  Fallback patterns work when man page incomplete
-  No breaking changes to existing functionality

Closes: UI color display issue
Closes: Syntax display request
This commit is contained in:
2025-10-28 00:39:02 -07:00
parent bdf3026069
commit f152c9647c
+39 -11
View File
@@ -17,17 +17,15 @@ NC='\033[0m' # No Color
# ASCII Banner # ASCII Banner
show_banner() { show_banner() {
cat << "EOF" echo -e "${CYAN}"
[0;36m echo " ____ __ ____ __ __"
____ __ ____ __ __ echo " / __ )____ ______/ /_ / __ )__ ______/ /___/ /_ __"
/ __ )____ ______/ /_ / __ )__ ______/ /___/ /_ __ echo " / __ / __ \`/ ___/ __ \\ / __ / / / / __ / __ / / / /"
/ __ / __ `/ ___/ __ \ / __ / / / / __ / __ / / / / echo " / /_/ / /_/ (__ ) / / / / /_/ / /_/ / /_/ / /_/ / /_/ /"
/ /_/ / /_/ (__ ) / / / / /_/ / /_/ / /_/ / /_/ / /_/ / echo "/_____/\\__,_/____/_/ /_/ /_____/\\__,_/\\__,_/\\__,_/\\__, /"
/_____/\__,_/____/_/ /_/ /_____/\__,_/\__,_/\__,_/\__, / echo " /____/"
/____/ echo -e "${YELLOW} Your Intelligent CLI Assistant for Bash${NC}"
[0;33m Your Intelligent CLI Assistant for Bash echo ""
[0m
EOF
} }
show_help() { show_help() {
@@ -406,6 +404,36 @@ mode_explain() {
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}" echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo "" echo ""
# Get syntax from man page SYNOPSIS section
if command -v "$base_cmd" &> /dev/null || type "$base_cmd" 2>/dev/null | grep -q "shell builtin"; then
echo -e "${CYAN}${BOLD}SYNTAX:${NC}"
if type "$base_cmd" 2>/dev/null | grep -q "shell builtin"; then
# For builtins, get the first line of help
local syntax=$(help "$base_cmd" 2>/dev/null | head -1 | sed 's/^[[:space:]]*//')
if [ -n "$syntax" ]; then
echo -e " ${GREEN}$syntax${NC}"
else
echo -e " ${GREEN}$base_cmd [options]${NC}"
fi
else
# For regular commands, extract SYNOPSIS section from man page
local synopsis=$(man "$base_cmd" 2>/dev/null | col -b | sed -n '/^SYNOPSIS/,/^DESCRIPTION/p' | head -15 | tail -n +2 | head -n -1 | sed 's/^[[:space:]]*/ /')
if [ -n "$synopsis" ]; then
echo -e "${GREEN}$synopsis${NC}"
else
# Fallback: try to get usage from command itself
local usage=$("$base_cmd" --help 2>&1 | grep -i "usage" | head -1 | sed 's/^[Uu]sage: / /')
if [ -n "$usage" ]; then
echo -e " ${GREEN}$usage${NC}"
else
echo -e " ${GREEN}$base_cmd [options]${NC}"
fi
fi
fi
echo ""
fi
# Try to find in database # Try to find in database
local found_in_db=false local found_in_db=false
if check_jq && check_database; then if check_jq && check_database; then