Skip to content

Commit 7abe0ff

Browse files
Merge pull request #152 from StartAutomating/IrregularANSI
Irregular ansi
2 parents 6f2cca6 + dacc420 commit 7abe0ff

19 files changed

+204
-65
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
## 0.7.3:
1+
## 0.7.4:
2+
* ANSI Improvements:
3+
* Regenerated ?<ANSI_Color> (Fixes #150)
4+
* Added ?<ANSI_Cursor> (Fixes #151)
5+
---
6+
7+
## 0.7.3:
28
* ANSI Improvements:
39
* Fixed ?<ANSI_Style> (Fixes #143)
410
* ?<ANSI_4BitColor> now supports bright ranges (Fixes #145)

Irregular.psd1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.7.3'
2+
ModuleVersion = '0.7.4'
33
RootModule = 'Irregular.psm1'
44
Description = 'Regular Expressions made Strangely Simple'
55
FormatsToProcess = 'Irregular.format.ps1xml'
@@ -14,6 +14,12 @@
1414
LicenseURI = 'https://github.com/StartAutomating/Irregular/blob/master/LICENSE'
1515
IconURI = 'https://github.com/StartAutomating/Irregular/blob/master/Assets/Irregular_600_Square.png'
1616
ReleaseNotes = @'
17+
## 0.7.4:
18+
* ANSI Improvements:
19+
* Regenerated ?<ANSI_Color> (Fixes #150)
20+
* Added ?<ANSI_Cursor> (Fixes #151)
21+
---
22+
1723
## 0.7.3:
1824
* ANSI Improvements:
1925
* Fixed ?<ANSI_Style> (Fixes #143)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h2>Regular Expressions made Strangely Simple</h2>
44
<h3>A PowerShell module that helps you understand, use, and build Regular Expressions.</h3>
55
<h4>
6-
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.3'>v 0.7.3 </a>
6+
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.4'>v 0.7.4 </a>
77
</h4>
88
<a href='https://www.powershellgallery.com/packages/Irregular/'>
99
<img src='https://img.shields.io/powershellgallery/dt/Irregular' />
@@ -32,7 +32,7 @@ Once you understand some basics of that syntax, regular expressions become a lot
3232
3. A Regex can have comments! ( # Like this in .NET ( or like (?#this comment) in ECMAScript ) ).
3333
4. You don't have to do it all in one expression!
3434

35-
Irregular comes with 130 useful [named expressions](SavedPatterns.md), and lets you create more.
35+
Irregular comes with 131 useful [named expressions](SavedPatterns.md), and lets you create more.
3636

3737
To see the expressions that ship with Irregular, run:
3838

RegEx/ANSI/Color.regex.txt

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
11
# Matches an ANSI color
22
(?>
33
(?<ANSI_24BitColor>
4-
(?-i)\e # An Escape
5-
\[ # Followed by a bracket
6-
38;2;(?<Color>(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Red is the first 0-255 value
7-
;(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Green is the second 0-255 value
8-
;(?<Blue>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Blue is the third 0-255 value
4+
(?-i)\e # An Escape
5+
\[ # Followed by a bracket
6+
(?>
7+
(?<IsForegroundColor>38) |
8+
(?<IsBackgroundColor>48) |
9+
(?<IsUnderlineColor>58));2;(?<Color>(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Red is the first 0-255 value
10+
;(?<Green>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Green is the second 0-255 value
11+
;(?<Blue>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Blue is the third 0-255 value
912
m)
1013
)
1114
|
1215
(?<ANSI_8BitColor>
13-
(?-i)\e # An Escape
14-
\[ # Followed by a bracket
15-
38;5;(?<Color>(?>
16-
(?<StandardColor>[0-7]) # 0 -7 are standard colors
16+
(?-i)\e # An Escape
17+
\[ # Followed by a bracket
18+
(?>
19+
(?<IsForegroundColor>38) |
20+
(?<IsBackgroundColor>48) |
21+
(?<IsUnderlineColor>58));5;(?<Color>(?>
22+
(?<StandardColor>[0-7]) # 0 -7 are standard colors
1723
m |
18-
(?<BrightColor>(?>[8-9]|1[0-5])) # 8-15 are bright colors
24+
(?<BrightColor>(?>[8-9]|1[0-5])) # 8-15 are bright colors
1925
m |
20-
(?<CubeColor>(?>[0-2][0-3][0-1]|[0-1]\d\d|\d{1,2})) # 16-231 are cubed colors
26+
(?<CubeColor>(?>[0-2][0-3][0-1]|[0-1]\d\d|\d{1,2})) # 16-231 are cubed colors
2127
m |
22-
(?<GrayscaleColor>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # 232-255 are grayscales
28+
(?<GrayscaleColor>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # 232-255 are grayscales
2329
m))
2430
)
2531
|
2632
(?<ANSI_4BitColor>
27-
\e # An Escape
28-
\[ # Followed by a bracket
29-
(?<Color>(?<IsBright>1)?\;?(?<ForegroundColor>3[0-7])?(?(ForegroundColor)(m)|((?<BackgroundColor>4[0-7])m)))
33+
\e # An Escape
34+
\[ # Followed by a bracket
35+
(?<Color>(?>
36+
(?<IsBright>1)?\;{0,1}(?<IsForegroundColor>3) |
37+
(?<IsBright>(?<IsForegroundColor>9)) |
38+
(?<IsBright>1)?\;{0,1}(?<IsBackgroundColor>4) |
39+
(?<IsBright>(?<IsBackgroundColor>10)))(?<ColorNumber>[0-7])m)
3040
)
3141
|
3242
(?<ANSI_DefaultColor>
33-
(?-i)\e # An Escape
34-
\[ # Followed by a bracket
43+
(?-i)\e # An Escape
44+
\[ # Followed by a bracket
3545
(?<Color>(?>
36-
(?<DefaultForeground>39) # 39 Represents the default foreground color
46+
(?<DefaultForeground>39) # 39 Represents the default foreground color
3747
m |
38-
(?<DefaultForeground>49) # 49 Represents the default background color
48+
(?<DefaultForeground>49) # 49 Represents the default background color
3949
m))
4050
)
4151
)

RegEx/ANSI/Cursor.regex.source.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
2+
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
3+
4+
New-RegEx -Description "Matches an ANSI cursor control" |
5+
New-RegEx -CharacterClass Escape |
6+
New-RegEx -LiteralCharacter '[' |
7+
New-RegEx -Atomic -Or @(
8+
New-RegEx -Pattern '6n' -Name 'DeviceStatusReport' -Comment '6n will request the cursor position'
9+
New-RegEx -Pattern (
10+
New-RegEx -Name Row -Pattern '\d+' |
11+
New-RegEx -LiteralCharacter ';' |
12+
New-RegEx -Name Column -Pattern '\d+' |
13+
New-RegEx -Pattern 'R'
14+
) -Comment "A Device Status Report will return CursorPosition in the form <row>;<column> R" -Name CursorPosition
15+
New-RegEx -Name CursorUp -Comment "Cursor Up is a digit followed by A" -Pattern (
16+
New-RegEx -Name RowCount -Pattern '\d+' |
17+
New-RegEx -Pattern 'A'
18+
)
19+
New-RegEx -Name CursorDown -Comment "Cursor Down is a digit followed by B" -Pattern (
20+
New-RegEx -Name RowCount -Pattern '\d+' |
21+
New-RegEx -Pattern 'B'
22+
)
23+
New-RegEx -Name CursorForward -Comment "Cursor Forward is a digit followed by C" -Pattern (
24+
New-RegEx -Name ColumnCount -Pattern '\d+' |
25+
New-RegEx -Pattern 'C'
26+
)
27+
New-RegEx -Name CursorBack -Comment "Cursor Back is a digit followed by D" -Pattern (
28+
New-RegEx -Name ColumnCount -Pattern '\d+' |
29+
New-RegEx -Pattern 'D'
30+
)
31+
New-RegEx -Name CursorNextLine -Comment "Cursor Next Line is a digit followed by E" -Pattern (
32+
New-RegEx -Name LineCount -Pattern '\d+' |
33+
New-RegEx -Pattern 'E'
34+
)
35+
New-RegEx -Name CursorNextLine -Comment "Cursor Next Line is a digit followed by F" -Pattern (
36+
New-RegEx -Name LineCount -Pattern '\d+' |
37+
New-RegEx -Pattern 'F'
38+
)
39+
New-RegEx -Name CursorAbsolute -Comment "Cursor Absolute Position is a digit followed by G" -Pattern (
40+
New-RegEx -Name AbsolutePosition -Pattern '\d+' |
41+
New-RegEx -Pattern 'G'
42+
)
43+
New-RegEx -Name CursorPosition -Comment "Cursor Positions are two optional digits, separated by semicolon, ending with H" -Pattern (
44+
New-RegEx -Name Row -Pattern '\d{0,}' |
45+
New-RegEx -LiteralCharacter ';' |
46+
New-RegEx -Name Column -Pattern '\d{0,}' |
47+
New-RegEx -LiteralCharacter 'H'
48+
)
49+
New-RegEx -Name ScrollUp -Comment "Scroll Up is a digit followed by S" -Pattern (
50+
New-RegEx -Name PageCount -Pattern '\d+' |
51+
New-RegEx -Pattern 'S'
52+
)
53+
New-RegEx -Name ScrollDown -Comment "Scroll Down is a digit followed by T" -Pattern (
54+
New-RegEx -Name PageCount -Pattern '\d+' |
55+
New-RegEx -Pattern 'T'
56+
)
57+
New-RegEx -Name CursorHide -Comment 'Cursors can be hidden with 25h' (
58+
New-RegEx -Pattern '25h'
59+
)
60+
New-RegEx -Name CursorShow -Comment 'Cursors can be hidden with 25l' (
61+
New-RegEx -Pattern '25l'
62+
)
63+
) |
64+
Set-Content -Path (Join-Path $myRoot $myName) -PassThru

RegEx/ANSI/Cursor.regex.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Matches an ANSI cursor control
2+
\e\[(?>
3+
(?<DeviceStatusReport>6n) # 6n will request the cursor position
4+
|
5+
(?<CursorPosition>(?<Row>\d+)\;(?<Column>\d+)R) # A Device Status Report will return CursorPosition in the form <row>;<column> R
6+
|
7+
(?<CursorUp>(?<RowCount>\d+)A) # Cursor Up is a digit followed by A
8+
|
9+
(?<CursorDown>(?<RowCount>\d+)B) # Cursor Down is a digit followed by B
10+
|
11+
(?<CursorForward>(?<ColumnCount>\d+)C) # Cursor Forward is a digit followed by C
12+
|
13+
(?<CursorBack>(?<ColumnCount>\d+)D) # Cursor Back is a digit followed by D
14+
|
15+
(?<CursorNextLine>(?<LineCount>\d+)E) # Cursor Next Line is a digit followed by E
16+
|
17+
(?<CursorNextLine>(?<LineCount>\d+)F) # Cursor Next Line is a digit followed by F
18+
|
19+
(?<CursorAbsolute>(?<AbsolutePosition>\d+)G) # Cursor Absolute Position is a digit followed by G
20+
|
21+
(?<CursorPosition>(?<Row>\d{0,})\;(?<Column>\d{0,})H) # Cursor Positions are two optional digits, separated by semicolon, ending with H
22+
|
23+
(?<ScrollUp>(?<PageCount>\d+)S) # Scroll Up is a digit followed by S
24+
|
25+
(?<ScrollDown>(?<PageCount>\d+)T) # Scroll Down is a digit followed by T
26+
|
27+
(?<CursorHide>25h) # Cursors can be hidden with 25h
28+
|
29+
(?<CursorShow>25l) # Cursors can be hidden with 25l
30+
)

RegEx/ANSI/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Note: Using these regular expressions in the terminal may result in awkward out
1212
|[?<ANSI_Bold>](Bold.regex.txt) |Matches an ANSI Bold Start or End |[source](Bold.regex.source.ps1) |
1313
|[?<ANSI_Code>](Code.regex.txt) |Matches an ANSI escape code |[source](Code.regex.source.ps1) |
1414
|[?<ANSI_Color>](Color.regex.txt) |Matches an ANSI color |[source](Color.regex.source.ps1) |
15+
|[?<ANSI_Cursor>](Cursor.regex.txt) |Matches an ANSI cursor control |[source](Cursor.regex.source.ps1) |
1516
|[?<ANSI_DefaultColor>](DefaultColor.regex.txt) |Matches an ANSI 24-bit color |[source](DefaultColor.regex.source.ps1) |
1617
|[?<ANSI_Faint>](Faint.regex.txt) |Matches an ANSI Faint (aka dim) Start or End |[source](Faint.regex.source.ps1) |
1718
|[?<ANSI_Hide>](Hide.regex.txt) |Matches ANSI Hide (aka conceal) Start or End |[source](Hide.regex.source.ps1) |

SavedPatterns.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### Irregular Patterns
2-
Irregular includes 130 regular expressions
2+
Irregular includes 131 regular expressions
33
|Name|Description|IsGenerator|
44
|:---|:----------|:----------|
55
|[ANSI_24BitColor](/RegEx/ANSI/24BitColor.regex.txt)|Matches an ANSI 24-bit color|False|
@@ -9,6 +9,7 @@ Irregular includes 130 regular expressions
99
|[ANSI_Bold](/RegEx/ANSI/Bold.regex.txt)|Matches an ANSI Bold Start or End|False|
1010
|[ANSI_Code](/RegEx/ANSI/Code.regex.txt)|Matches an ANSI escape code|False|
1111
|[ANSI_Color](/RegEx/ANSI/Color.regex.txt)|Matches an ANSI color|False|
12+
|[ANSI_Cursor](/RegEx/ANSI/Cursor.regex.txt)|Matches an ANSI cursor control|False|
1213
|[ANSI_DefaultColor](/RegEx/ANSI/DefaultColor.regex.txt)|Matches an ANSI 24-bit color|False|
1314
|[ANSI_Faint](/RegEx/ANSI/Faint.regex.txt)|Matches an ANSI Faint (aka dim) Start or End|False|
1415
|[ANSI_Hide](/RegEx/ANSI/Hide.regex.txt)|Matches ANSI Hide (aka conceal) Start or End|False|

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.7.4:
2+
* ANSI Improvements:
3+
* Regenerated ?<ANSI_Color> (Fixes #150)
4+
* Added ?<ANSI_Cursor> (Fixes #151)
5+
---
6+
17
## 0.7.3:
28
* ANSI Improvements:
39
* Fixed ?<ANSI_Style> (Fixes #143)

docs/Export-RegEx.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ If the command sets a ```[ConfirmImpact("Medium")]``` which is lower than ```$co
135135
---
136136
### Syntax
137137
```PowerShell
138-
Export-RegEx [[-Name] &lt;String[]&gt;] [[-Path] &lt;String&gt;] [[-As] &lt;String&gt;] [[-Noun] &lt;String&gt;] [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]
138+
Export-RegEx [[-Name] <String[]>] [[-Path] <String>] [[-As] <String>] [[-Noun] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
139139
```
140140
---
141141
### Notes

0 commit comments

Comments
 (0)