Skip to content

Commit 5853372

Browse files
committed
✨ [feat] Enhance color script capabilities
Adds new color scripts and improves documentation. - ✨ [feat] Adds two new color scripts: - Kevin Woods: Implements a color scheme with red lines, white 'O's, and yellow 'T' and 'M' characters, leveraging ANSI escape codes for terminal coloring. 🎨 - Amiga Classic: Generates ASCII art rendered with a rotating set of Amiga-inspired colors. 🔄 - 📝 [docs] Introduces a comprehensive guide for creating color ASCII art in PowerShell, detailing common pitfalls and best practices. 💡 - - Provides solutions for variable delimiter issues, backtick escape sequences, and dollar sign escaping. ✍️ - - Emphasizes the importance of the `$reset` variable for consistent color transitions. 🌈 - - Recommends `Write-Host` over Here-Strings for complex ASCII art. 🖼️ - - Includes debugging tips for alignment issues and character counting. 🐛 - 🧹 [chore] Updates the module manifest (`.psd1`) to reflect the new version and release notes, mentioning enhancements to the caching system. 📦 - - Changes the module version from `2025.10.09.2330` to `2025.10.10.0103`. 🔢 - - Updates the generation date in the manifest. 📅 Signed-off-by: Nick2bad4u <20943337+Nick2bad4u@users.noreply.github.com>
1 parent 7dc33f9 commit 5853372

5 files changed

Lines changed: 544 additions & 3 deletions

File tree

ANSI-COLOR-GUIDE.md

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
# PowerShell ANSI Color Script Guide
2+
3+
## Critical Rules for Coloring ASCII Art in PowerShell
4+
5+
### 1. **Variable Delimiter Issues**
6+
7+
**Problem:** When using `${variable}` syntax followed by a letter, PowerShell tries to interpret the letter as part of the variable name.
8+
9+
```powershell
10+
# ❌ WRONG - PowerShell thinks variable is ${gray}P
11+
"${gray}P" # Outputs nothing because ${gray}P doesn't exist
12+
13+
# ✅ CORRECT - Use $reset between color changes
14+
"${reset}${gray}P" # Outputs gray "P"
15+
```
16+
17+
**Solution:** Always insert `$reset` between any color variable and following text that starts with a letter.
18+
19+
### 2. **Backtick Escape Sequences**
20+
21+
**Problem:** Backticks (`` ` ``) before certain letters create escape sequences:
22+
- `` `b `` = backspace
23+
- `` `d `` = (not defined but causes issues)
24+
- `` `t `` = tab
25+
- `` `n `` = newline
26+
- `` `r `` = carriage return
27+
28+
```powershell
29+
# ❌ WRONG - The `b gets escaped
30+
"${white}`[${brightred}`bug${white}`]"
31+
# Output: "[ug]" - the 'b' disappears!
32+
33+
# ✅ CORRECT - Use reset to separate
34+
"${white}[$reset${brightred}bug$reset${white}]"
35+
```
36+
37+
### 3. **Dollar Sign Escaping**
38+
39+
**Problem:** Dollar signs ($) need to be escaped with backticks, but this creates alignment issues.
40+
41+
```powershell
42+
# ❌ WRONG - Literal $ interpreted as variable
43+
"$$$$$" # PowerShell tries to evaluate variables
44+
45+
# ✅ CORRECT - Escape each dollar sign
46+
"`$`$`$`$`$" # Outputs: $$$$$
47+
```
48+
49+
### 4. **Mixing Color Variables and Literal Text**
50+
51+
**Problem:** When transitioning between colors and literal characters, variable expansion can break.
52+
53+
```powershell
54+
# ❌ WRONG - ${gray}P becomes one variable name
55+
"$red`$`$`$${gray}P^*"
56+
57+
# ✅ CORRECT - Insert reset between transitions
58+
"$red`$`$`$$reset${gray}P^*"
59+
```
60+
61+
### 5. **Here-String vs Write-Host Lines**
62+
63+
**Here-String Issues:**
64+
- Variable interpolation happens all at once
65+
- Harder to debug specific lines
66+
- Can have unexpected escape sequence interactions
67+
68+
**Write-Host Line-by-Line:**
69+
- Each line is independent
70+
- Easier to debug
71+
- Better control over color transitions
72+
- **RECOMMENDED for complex ASCII art**
73+
74+
```powershell
75+
# ❌ Problematic Here-String
76+
Write-Host @"
77+
${gray}Text${red}`$`$`$${gray}More
78+
"@
79+
80+
# ✅ Better approach - Individual lines
81+
Write-Host "${gray}Text$reset$red`$`$`$$reset${gray}More$reset"
82+
```
83+
84+
### 6. **The Reset Pattern**
85+
86+
**Always follow this pattern for color transitions:**
87+
88+
```powershell
89+
# Pattern: [color][content]$reset[next-color][content]$reset
90+
91+
Write-Host "$red`$`$`$$reset${gray}P^*^T$reset$red`$`$$reset"
92+
```
93+
94+
This ensures:
95+
- No variable name collisions
96+
- Clean color boundaries
97+
- Predictable output
98+
99+
### 7. **Special Characters That Need Backticks**
100+
101+
Characters that need escaping in double-quoted strings:
102+
- `` ` `` (backtick itself) - ``` `` ```
103+
- `$` (dollar) - `` `$ ``
104+
- `"` (quote) - `` `" ``
105+
- Newlines/tabs if you DON'T want them - `` `n ``, `` `t ``
106+
107+
**IMPORTANT - Backslash is NOT an escape character in PowerShell:**
108+
109+
Unlike many other languages, backslash (`\`) is a literal character in PowerShell, NOT an escape character. The backtick (`` ` ``) is PowerShell's escape character.
110+
111+
```powershell
112+
# ✅ CORRECT - Backslash is literal, no escaping needed
113+
Write-Host "C:\Users\Name" # Outputs: C:\Users\Name
114+
Write-Host "\.period" # Outputs: \.period
115+
Write-Host "\-dash" # Outputs: \-dash
116+
117+
# ❌ WRONG - Don't escape backslash with backtick
118+
Write-Host "C:\`Users\`Name" # Unnecessary escaping
119+
Write-Host "\`.period" # Outputs backtick, not what you want
120+
Write-Host "\`-dash" # Outputs backtick, not what you want
121+
122+
# ✅ CORRECT - Only escape backticks and dollars
123+
Write-Host "``backtick" # Outputs: `backtick
124+
Write-Host "`$dollar" # Outputs: $dollar
125+
```
126+
127+
**Common Pattern Mistakes:**
128+
- `\`` - This is backslash + escaped-backtick (outputs: \`)
129+
- `\.` - This is just backslash + period (outputs: \.)
130+
- `\-` - This is just backslash + dash (outputs: \-)
131+
132+
**When working with ASCII art containing backslashes:**
133+
- Use `\\` to output a single backslash (PowerShell string literal, not escaping)
134+
- Use `\` followed by any character that's not special
135+
- Never use `` \` `` unless you specifically want backslash-backtick output
136+
137+
**CRITICAL - Backtick Escaping in Strings:**
138+
139+
When the original ASCII art contains a literal backtick character (`` ` ``), you MUST escape it with another backtick in PowerShell double-quoted strings:
140+
141+
```powershell
142+
# Original ASCII has: `*TP*
143+
# ❌ WRONG - Creates escape sequence issues
144+
Write-Host "\`*TP*" # May cause parser errors
145+
146+
# ❌ WRONG - Backslash-backtick is NOT the same as double-backtick
147+
Write-Host "\``*TP*" # This is backslash + escaped-backtick - WRONG!
148+
149+
# ✅ CORRECT - Double backtick for literal backtick
150+
Write-Host "``*TP*" # Outputs: `*TP*
151+
```
152+
153+
**Common Mistakes with Backslash-Backtick (`\```):**
154+
155+
The pattern `\``` appears to work but causes subtle parser errors:
156+
- `\``` means: backslash + backtick-escape-for-backtick
157+
- This creates ambiguous parsing situations
158+
- Can cause "Unexpected token" errors at seemingly random positions
159+
160+
**Always use double-backtick (``` `` ```) for literal backticks, never `\```**
161+
162+
```powershell
163+
# ❌ WRONG - All of these use incorrect \` pattern
164+
Write-Host "${gray}P* ${white}\`*'${gray} _._ \`T$reset"
165+
166+
# ✅ CORRECT - Use `` for literal backticks
167+
Write-Host "${gray}P* ${white}``*'${gray} _._ ``T$reset"
168+
```
169+
170+
### 8. **Color Variable Definition**
171+
172+
Use RGB ANSI codes for best compatibility:
173+
174+
```powershell
175+
$esc = [char]27
176+
177+
# Basic format: ESC[38;2;R;G;Bm
178+
$red = "$esc[38;2;238;0;0m"
179+
$gray = "$esc[38;2;140;140;140m"
180+
$white = "$esc[38;2;220;220;220m"
181+
182+
# Bold
183+
$boldon = "$esc[1m"
184+
185+
# Always include reset
186+
$reset = "$esc[0m"
187+
```
188+
189+
### 9. **Debugging Alignment Issues**
190+
191+
If output is misaligned:
192+
193+
1. **Check for escape sequence bugs** - Look for backtick before b, d, t, n, r
194+
2. **Verify dollar escaping** - Each $ should be `` `$ ``
195+
3. **Test color boundaries** - Add $reset between color changes
196+
4. **Count visible characters** - ANSI codes don't count toward width
197+
5. **Test line by line** - Comment out lines to isolate the problem
198+
6. **Compare character-by-character** - Count $ symbols, spaces, and special characters against original
199+
7. **Watch for incorrect backslash escaping** - Don't use `` \` `` when you mean `\.` or `\-`
200+
201+
**Character Counting Tips:**
202+
- Count each literal `$` in the original ASCII (each becomes `` `$ `` in code)
203+
- Verify spaces match exactly
204+
- Check that backslashes are literal `\`, not escaped with backtick
205+
- Ensure color codes don't accidentally consume following characters
206+
207+
### 10. **Best Practices Template**
208+
209+
```powershell
210+
# Check cache first for instant output
211+
if (. "$PSScriptRoot\..\ColorScriptCache.ps1") { return }
212+
213+
$esc = [char]27
214+
215+
# Define all colors
216+
$red = "$esc[38;2;238;0;0m"
217+
$gray = "$esc[38;2;140;140;140m"
218+
$white = "$esc[38;2;220;220;220m"
219+
$boldon = "$esc[1m"
220+
$reset = "$esc[0m"
221+
222+
# Use Write-Host per line
223+
Write-Host ""
224+
Write-Host "$boldon${red}Title$reset"
225+
Write-Host "${gray}Text $reset$red`$`$`$$reset${gray} More$reset"
226+
Write-Host ""
227+
```
228+
229+
## Complete Example
230+
231+
```powershell
232+
# RedHat Bug - Proper Implementation
233+
$esc = [char]27
234+
$red = "$esc[38;2;238;0;0m"
235+
$gray = "$esc[38;2;140;140;140m"
236+
$white = "$esc[38;2;220;220;220m"
237+
$reset = "$esc[0m"
238+
239+
# Notice the $reset between each color transition
240+
Write-Host "${gray} .sd$red`$`$`$`$`$`$`$$reset${gray}P^*^T${reset}$red`$`$`$$reset${gray}P^*"*^T${reset}$red`$`$`$`$$reset${gray}bs.$reset"
241+
```
242+
243+
## Quick Reference
244+
245+
| Issue | Wrong | Right |
246+
|-------|-------|-------|
247+
| Letter after color | `${gray}P` | `$reset${gray}P` |
248+
| Backtick + letter | ``` ${white}`bug ``` | `$reset${white}bug` |
249+
| Dollar signs | `$$$` | `` `$`$`$ `` |
250+
| Color transitions | `$red$$$${gray}P` | `$red`$`$`$$reset${gray}P` |
251+
| Complex strings | Here-string | Write-Host lines |
252+
| Backslash escaping | `` \`. `` or `` \`- `` | `\.` or `\-` |
253+
| Missing dollars | Count mismatch | Count each $ in original |
254+
255+
## Testing Checklist
256+
257+
- [ ] Run script and verify alignment matches original
258+
- [ ] Check for missing characters (especially b, d, t after backticks)
259+
- [ ] Verify all dollar signs display correctly
260+
- [ ] Confirm colors appear as intended
261+
- [ ] Test with cache disabled
262+
- [ ] Compare output character-by-character with original ASCII
263+
- [ ] Count $ symbols in each line matches original exactly
264+
- [ ] Verify backslashes are literal (not escaped with backtick)
265+
- [ ] Check that color transitions use $reset properly
266+
- [ ] Ensure no accidental escape sequences (`` `b ``, `` `d ``, `` `n ``, `` `r ``, `` `t ``)
267+
268+
---
269+
270+
**Remember:** When in doubt, add more `$reset` markers. They don't add visible characters but ensure clean color transitions.

ColorScripts-Enhanced/ColorScripts-Enhanced.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#
44
# Generated by: Nick
55
#
6-
# Generated on: 10/9/2025
6+
# Generated on: 10/10/2025
77
#
88

99
@{
1010
# Script module or binary module file associated with this manifest.
1111
RootModule = 'ColorScripts-Enhanced.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2025.10.09.2330'
14+
ModuleVersion = '2025.10.10.0103'
1515

1616
# Supported PSEditions
1717
CompatiblePSEditions = @('Desktop', 'Core')
@@ -124,7 +124,7 @@
124124

125125
# ReleaseNotes of this module
126126
ReleaseNotes = @'
127-
Version 2025.10.09.2330:
127+
Version 2025.10.10.0103:
128128
- Enhanced caching system with OS-wide cache in AppData
129129
- 6-19x performance improvement
130130
- Cache stored in centralized location
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Amiga Classic ASCII
2+
# Check cache first for instant output
3+
if (. "$PSScriptRoot\..\ColorScriptCache.ps1") { return }
4+
5+
$art = @'
6+
___..-.---.---.--..___
7+
_..-- `.`. `. `. `. --.._
8+
/ ___________\ \ \______ \
9+
| |.-----------`. `. `.---.| |
10+
|`. |' \`. \ \ \ '| |
11+
|`. |' \ `-._ `. `. `.'| |
12+
/| |' `-._o)\ /(o\ \ \| |\
13+
.' | |' `. .' '. `. `. `. | `.
14+
/ .| |' `. (_.==._) \ \ \ |. \ _.--.
15+
.' .' | |' _.-======-._ `. `. `. `. `. _.-_.-'\\
16+
/ / | |' .' |_||_| `. \ \ \ \ \ .'_.' ||
17+
/ .' |`. |' /_.-'========`-._\ `. `-._`._`. \(.__ :|
18+
( ' |`. |'.______________________.'\ _.) ` )`-._`-._/ /
19+
\\ | '.------------------------.'`-._-' // `-._.'
20+
_\\_ \ | AMIGA O O O O * * `.`.| ' //
21+
(_ _) '-._|________________________|_.-'| _//_
22+
/ / /`-._ |`-._ / / / | (_ _)
23+
.' \ |`-._ `-._ `-._`-._/ / / | \ \
24+
/ `. | `-._ `-._ `-._|/ / | / `.
25+
/ / / /. ) | `-._ `-._ `-._ / / .' \
26+
| | | \ \|/ | `-._`-._ `-._ `-._ / /. ( .\ \ \ \
27+
\ \ \ \/ | `-._`-._`-._ `-._ `-._/ / \ \|/ / | | |
28+
`.\_\/ `-._ `-._`-._`-._ `-._/| /| \ \/ / / /
29+
/ `-._ `-._`-._`-._ || / | \ \/_/.'
30+
.' `-._ `-._`-._ || / | \
31+
/ / . `-._ `-._ || / | \
32+
'\ / / `-._ ||/'._.' \
33+
\`. .' / `-._|/ \
34+
`.`-._.' .' \ .'
35+
`-.__\/ `\ .' '
36+
\`. _.' .'
37+
`.`-._.-' _.'
38+
`-.__.-'
39+
'@
40+
41+
# Split art into lines and color each line cyclically with Amiga-inspired colors
42+
$lines = $art -split "`n"
43+
$colors = @("Blue", "White", "Cyan", "Yellow", "Magenta", "Green", "Red")
44+
for ($i = 0; $i -lt $lines.Count; $i++) {
45+
Write-Host $lines[$i] -ForegroundColor $colors[$i % $colors.Count]
46+
}

0 commit comments

Comments
 (0)