Add color code bug prevention: cecho helper + coding guidelines
PREVENTION STRATEGY for "echo without -e" bug:
1. NEW HELPER FUNCTION - cecho()
- Added to lib/common-functions.sh (lines 100-115)
- Wrapper around echo -e for colored output
- Clear documentation with examples
- Usage: cecho "${BOLD}Text${NC}" instead of echo -e
2. COMPREHENSIVE CODING GUIDELINES
- Created CODING_GUIDELINES.md
- Documents the echo -e color bug with examples
- Prevention rules and quick reference table
- Search command to find potential issues
- Pre-commit checklist for developers
- Performance guidelines (subprocess elimination)
3. DOCUMENTATION INCLUDES:
- Why the bug happens (escape sequences not interpreted)
- How to identify it (grep pattern)
- How to fix it (echo -e or cecho)
- When to use each approach
- Historical context (commit 7053b3b)
BENEFITS:
- Future developers can reference guidelines
- cecho() provides cleaner, safer API
- Search pattern helps audit existing code
- Reduces recurring "This happens a lot" issues
USER FEEDBACK ADDRESSED:
User: "This happens a lot with you. is there a way for us to avoid this in the future?"
Answer: Yes - cecho() helper + guidelines document + search pattern
This commit is contained in:
@@ -97,6 +97,23 @@ print_header() {
|
||||
echo -e "${CYAN}${BOLD}$1${NC}"
|
||||
}
|
||||
|
||||
#############################################################################
|
||||
# Color Echo Helper - ALWAYS use this when printing colored text
|
||||
#
|
||||
# PROBLEM: Using 'echo' without -e flag doesn't interpret escape sequences
|
||||
# BAD: echo " ${BOLD}1${NC} - Menu option" → Shows: \033[1m1\033[0m
|
||||
# GOOD: cecho " ${BOLD}1${NC} - Menu option" → Shows: 1 (bold)
|
||||
#
|
||||
# USAGE:
|
||||
# cecho "Normal text with ${RED}colored${NC} parts"
|
||||
# cecho "${BOLD}Bold text${NC}"
|
||||
#
|
||||
# WHY: Prevents common bug where color codes show as literal text
|
||||
#############################################################################
|
||||
cecho() {
|
||||
echo -e "$@"
|
||||
}
|
||||
|
||||
# Wait for user input
|
||||
press_enter() {
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user