fix(interactive): Fix syntax display with proper colors and alignment
Fixed all interactive menu display issues: 1. Fixed Right Justification: - Recalculated widths to prevent clipping - Proper spacing calculation: TERM_WIDTH - CMD - DESC - SYNTAX - Minimum space enforcement (at least 2 spaces) - Syntax now always visible and right-aligned 2. Added Color Separation: - Bright cyan for command name (\033[0;36m) - White/default for description (clean, readable) - Dim cyan for syntax (\033[2;36m) - Clear visual hierarchy 3. Fixed Spacing: - Space after colon: 'cmd: description' - Dynamic spacing based on terminal width - Proper padding calculation 4. Color Coordination: - Command name: Bright cyan (matches command selection) - Syntax: Dim cyan (distinct but coordinated) - Description: Default color (doesn't distract) 5. Extraction Fix: - Strip ANSI color codes from selection - Robust command name parsing Display Format: ls: List directory contents ls [OPTION]... [FILE]... ^cyan ^white description ^spaces ^dim cyan syntax Benefits: - No more clipped syntax - Clear visual distinction between elements - Professional, coordinated color scheme - Terminal-width aware (adapts to screen size) - Maintains fzf search functionality User Request: 'split between explanation and syntax helps a lot, but right justification not working causing syntax to not appear, also want space between command: and text, separate colors, and color coordinate syntax with command name'
This commit is contained in:
+38
-10
@@ -932,10 +932,19 @@ if [ "$INTERACTIVE" = true ]; then
|
|||||||
# Format commands for display: description on left, syntax on right
|
# Format commands for display: description on left, syntax on right
|
||||||
# Get terminal width for proper alignment
|
# Get terminal width for proper alignment
|
||||||
TERM_WIDTH=$(tput cols 2>/dev/null || echo 120)
|
TERM_WIDTH=$(tput cols 2>/dev/null || echo 120)
|
||||||
SYNTAX_WIDTH=50
|
|
||||||
DESC_WIDTH=$((TERM_WIDTH - SYNTAX_WIDTH - 5))
|
|
||||||
|
|
||||||
# Format each command with right-aligned syntax
|
# Calculate widths (leave room for colors and spacing)
|
||||||
|
MAX_CMD_WIDTH=15
|
||||||
|
SYNTAX_WIDTH=45
|
||||||
|
DESC_WIDTH=$((TERM_WIDTH - MAX_CMD_WIDTH - SYNTAX_WIDTH - 10))
|
||||||
|
|
||||||
|
# Ensure minimum widths
|
||||||
|
if [ $DESC_WIDTH -lt 30 ]; then
|
||||||
|
DESC_WIDTH=30
|
||||||
|
SYNTAX_WIDTH=$((TERM_WIDTH - MAX_CMD_WIDTH - DESC_WIDTH - 10))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Format each command with colors and right-aligned syntax
|
||||||
FORMATTED_COMMANDS=()
|
FORMATTED_COMMANDS=()
|
||||||
for cmd in "${COMMANDS[@]}"; do
|
for cmd in "${COMMANDS[@]}"; do
|
||||||
CMD_NAME=${cmd%%:*}
|
CMD_NAME=${cmd%%:*}
|
||||||
@@ -950,7 +959,7 @@ if [ "$INTERACTIVE" = true ]; then
|
|||||||
SYNTAX_PART="$CMD_NAME [options]"
|
SYNTAX_PART="$CMD_NAME [options]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Truncate if too long
|
# Truncate if too long (accounting for actual content, not color codes)
|
||||||
if [ ${#DESC_PART} -gt $DESC_WIDTH ]; then
|
if [ ${#DESC_PART} -gt $DESC_WIDTH ]; then
|
||||||
DESC_PART="${DESC_PART:0:$((DESC_WIDTH-3))}..."
|
DESC_PART="${DESC_PART:0:$((DESC_WIDTH-3))}..."
|
||||||
fi
|
fi
|
||||||
@@ -958,23 +967,42 @@ if [ "$INTERACTIVE" = true ]; then
|
|||||||
SYNTAX_PART="${SYNTAX_PART:0:$((SYNTAX_WIDTH-3))}..."
|
SYNTAX_PART="${SYNTAX_PART:0:$((SYNTAX_WIDTH-3))}..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Format with padding
|
# Calculate padding for right-alignment of syntax
|
||||||
printf -v formatted_line "%-${DESC_WIDTH}s %${SYNTAX_WIDTH}s" "$CMD_NAME:$DESC_PART" "$SYNTAX_PART"
|
# Total visible length = cmd_name + ": " + desc + spaces + syntax
|
||||||
|
CMD_LEN=${#CMD_NAME}
|
||||||
|
DESC_LEN=${#DESC_PART}
|
||||||
|
SYNTAX_LEN=${#SYNTAX_PART}
|
||||||
|
NEEDED_SPACES=$((TERM_WIDTH - CMD_LEN - 2 - DESC_LEN - SYNTAX_LEN - 5))
|
||||||
|
|
||||||
|
# Ensure at least 2 spaces
|
||||||
|
if [ $NEEDED_SPACES -lt 2 ]; then
|
||||||
|
NEEDED_SPACES=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create spacing string
|
||||||
|
SPACES=$(printf '%*s' "$NEEDED_SPACES" '')
|
||||||
|
|
||||||
|
# Format with colors:
|
||||||
|
# - Cyan for command name
|
||||||
|
# - White for description
|
||||||
|
# - Dim cyan for syntax
|
||||||
|
formatted_line="\033[0;36m${CMD_NAME}\033[0m: ${DESC_PART}${SPACES}\033[2;36m${SYNTAX_PART}\033[0m"
|
||||||
|
|
||||||
FORMATTED_COMMANDS+=("$formatted_line")
|
FORMATTED_COMMANDS+=("$formatted_line")
|
||||||
done
|
done
|
||||||
|
|
||||||
# Show in fzf with formatted display
|
# Show in fzf with formatted display
|
||||||
SELECTED=$(printf "%s\n" "${FORMATTED_COMMANDS[@]}" | fzf \
|
SELECTED=$(printf "%b\n" "${FORMATTED_COMMANDS[@]}" | fzf \
|
||||||
--height 60% \
|
--height 60% \
|
||||||
--border \
|
--border \
|
||||||
--header "Select a command (description | syntax)" \
|
--header "Select a command (cyan: command | description | dim: syntax)" \
|
||||||
--prompt "🔍 Search: " \
|
--prompt "🔍 Search: " \
|
||||||
--preview-window=hidden \
|
--preview-window=hidden \
|
||||||
--ansi)
|
--ansi)
|
||||||
|
|
||||||
if [ -n "$SELECTED" ]; then
|
if [ -n "$SELECTED" ]; then
|
||||||
# Extract command name from selection
|
# Extract command name from selection (strip color codes)
|
||||||
CMD=$(echo "$SELECTED" | awk -F: '{print $1}')
|
CMD=$(echo "$SELECTED" | sed 's/\x1b\[[0-9;]*m//g' | awk -F: '{print $1}' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
|
||||||
|
|
||||||
# Find the original command entry to get full details
|
# Find the original command entry to get full details
|
||||||
for cmd in "${COMMANDS[@]}"; do
|
for cmd in "${COMMANDS[@]}"; do
|
||||||
|
|||||||
Reference in New Issue
Block a user