├── .gitignore ├── AnsiColorOut.sln ├── AnsiColorOut.sln.DotSettings ├── AnsiColorOut ├── AnsiColorOut.cs ├── AnsiColorOut.csproj ├── AnsiColorOut.psd1 ├── AnsiColorOut.psm1 ├── AnsiColorOutTest.ps1 ├── Cmdlets.cs ├── ColorMatcher.cs ├── ColorMatcherManager.cs ├── Console.cs ├── FileSystemInfoExtensions.cs ├── FileSystemInfoMatch.cs ├── Interfaces.cs ├── ProcessMatch.cs ├── Properties │ └── AssemblyInfo.cs ├── SampleProfile.ps1 ├── TypeExtensions.cs ├── formats │ ├── FileSystemInfo.format.ps1xml │ └── Process.format.ps1xml ├── help │ └── en-US │ │ └── Bozho.PowerShell.AnsiColorOut.dll-Help.xml ├── packages.config └── types │ └── FileSystemInfo.type.ps1xml ├── CHANGELOG.md ├── README.md ├── license.txt ├── scripts └── ansicolorout.msbuild.xml └── tools └── nuget.exe /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | builds/ 25 | build/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # DNX 46 | project.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opendb 82 | *.opensdf 83 | *.sdf 84 | *.cachefile 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # NuGet Packages 149 | *.nupkg 150 | # The packages folder can be ignored because of Package Restore 151 | **/packages/* 152 | # except build/, which is used as an MSBuild target. 153 | !**/packages/build/ 154 | # Uncomment if necessary however generally it will be regenerated when needed 155 | #!**/packages/repositories.config 156 | # NuGet v3's project.json files produces more ignoreable files 157 | *.nuget.props 158 | *.nuget.targets 159 | 160 | # Microsoft Azure Build Output 161 | csx/ 162 | *.build.csdef 163 | 164 | # Microsoft Azure Emulator 165 | ecf/ 166 | rcf/ 167 | 168 | # Windows Store app package directories and files 169 | AppPackages/ 170 | BundleArtifacts/ 171 | Package.StoreAssociation.xml 172 | _pkginfo.txt 173 | 174 | # Visual Studio cache files 175 | # files ending in .cache can be ignored 176 | *.[Cc]ache 177 | # but keep track of directories ending in .cache 178 | !*.[Cc]ache/ 179 | 180 | # Others 181 | ClientBin/ 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # Since there are multiple workflows, uncomment next line to ignore bower_components 192 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 193 | #bower_components/ 194 | 195 | # RIA/Silverlight projects 196 | Generated_Code/ 197 | 198 | # Backup & report files from converting an old project file 199 | # to a newer Visual Studio version. Backup files are not needed, 200 | # because we have git ;-) 201 | _UpgradeReport_Files/ 202 | Backup*/ 203 | UpgradeLog*.XML 204 | UpgradeLog*.htm 205 | 206 | # SQL Server files 207 | *.mdf 208 | *.ldf 209 | 210 | # Business Intelligence projects 211 | *.rdl.data 212 | *.bim.layout 213 | *.bim_*.settings 214 | 215 | # Microsoft Fakes 216 | FakesAssemblies/ 217 | 218 | # GhostDoc plugin setting file 219 | *.GhostDoc.xml 220 | 221 | # Node.js Tools for Visual Studio 222 | .ntvs_analysis.dat 223 | 224 | # Visual Studio 6 build log 225 | *.plg 226 | 227 | # Visual Studio 6 workspace options file 228 | *.opt 229 | 230 | # Visual Studio LightSwitch build output 231 | **/*.HTMLClient/GeneratedArtifacts 232 | **/*.DesktopClient/GeneratedArtifacts 233 | **/*.DesktopClient/ModelManifest.xml 234 | **/*.Server/GeneratedArtifacts 235 | **/*.Server/ModelManifest.xml 236 | _Pvt_Extensions 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | paket-files/ 241 | 242 | # FAKE - F# Make 243 | .fake/ 244 | 245 | # JetBrains Rider 246 | .idea/ 247 | *.sln.iml 248 | 249 | 250 | AnsiColorOut.zip 251 | -------------------------------------------------------------------------------- /AnsiColorOut.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnsiColorOut", "AnsiColorOut\AnsiColorOut.csproj", "{86074F90-6CBE-43CF-A9DA-5289F1BBEBB0}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FB25295A-3B2A-4DE9-87EE-234034B10CE6}" 9 | ProjectSection(SolutionItems) = preProject 10 | .gitignore = .gitignore 11 | CHANGELOG.md = CHANGELOG.md 12 | license.txt = license.txt 13 | README.md = README.md 14 | EndProjectSection 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{2F338FB0-7079-4795-BBEB-C26D6CE8EC7E}" 17 | ProjectSection(SolutionItems) = preProject 18 | scripts\ansicolorout.msbuild.xml = scripts\ansicolorout.msbuild.xml 19 | EndProjectSection 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Release|Any CPU = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {86074F90-6CBE-43CF-A9DA-5289F1BBEBB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {86074F90-6CBE-43CF-A9DA-5289F1BBEBB0}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {86074F90-6CBE-43CF-A9DA-5289F1BBEBB0}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {86074F90-6CBE-43CF-A9DA-5289F1BBEBB0}.Release|Any CPU.Build.0 = Release|Any CPU 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /AnsiColorOut.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | True 4 | True 5 | C60+,FF60+,IE11+,S9+ 6 | Symplectic.Foundation 7 | True 8 | True 9 | True 10 | ExplicitlyExcluded 11 | ExplicitlyExcluded 12 | DO_NOT_SHOW 13 | DO_NOT_SHOW 14 | DO_NOT_SHOW 15 | DO_NOT_SHOW 16 | SUGGESTION 17 | WARNING 18 | DO_NOT_SHOW 19 | DO_NOT_SHOW 20 | USE_TABS_ONLY 21 | Implicit 22 | END_OF_LINE 23 | END_OF_LINE 24 | END_OF_LINE 25 | END_OF_LINE 26 | TOGETHER_SAME_LINE 27 | ONLY_FOR_MULTILINE 28 | ONLY_FOR_MULTILINE 29 | ONLY_FOR_MULTILINE 30 | ONLY_FOR_MULTILINE 31 | ONLY_FOR_MULTILINE 32 | ONLY_FOR_MULTILINE 33 | END_OF_LINE 34 | END_OF_LINE 35 | END_OF_LINE 36 | False 37 | True 38 | True 39 | False 40 | False 41 | False 42 | False 43 | False 44 | False 45 | False 46 | False 47 | False 48 | False 49 | END_OF_LINE 50 | False 51 | CHOP_ALWAYS 52 | CHOP_ALWAYS 53 | NEXT_LINE 54 | SEPARATE_LINES 55 | SEPARATE_LINES 56 | True 57 | True 58 | True 59 | OUTSIDE_AND_INSIDE 60 | 1 61 | 1 62 | True 63 | True 64 | True 65 | True 66 | SingleQuoted 67 | True 68 | True 69 | False 70 | False 71 | CHOP_ALWAYS 72 | True 73 | True 74 | True 75 | True 76 | False 77 | OnDifferentLines 78 | False 79 | <?xml version="1.0" encoding="utf-8" ?> 80 | 81 | <!-- 82 | I. Overall 83 | 84 | I.1 Each pattern can have <Match>....</Match> element. For the given type declaration, the pattern with the match, evaluated to 'true' with the largest weight, will be used 85 | I.2 Each pattern consists of the sequence of <Entry>...</Entry> elements. Type member declarations are distributed between entries 86 | I.3 If pattern has RemoveAllRegions="true" attribute, then all regions will be cleared prior to reordering. Otherwise, only auto-generated regions will be cleared 87 | I.4 The contents of each entry is sorted by given keys (First key is primary, next key is secondary, etc). Then the declarations are grouped and en-regioned by given property 88 | 89 | II. Available match operands 90 | 91 | Each operand may have Weight="..." attribute. This weight will be added to the match weight if the operand is evaluated to 'true'. 92 | The default weight is 1 93 | 94 | II.1 Boolean functions: 95 | II.1.1 <And>....</And> 96 | II.1.2 <Or>....</Or> 97 | II.1.3 <Not>....</Not> 98 | 99 | II.2 Operands 100 | II.2.1 <Kind Is="..."/>. Kinds are: class, struct, interface, enum, delegate, type, constructor, destructor, property, indexer, method, operator, field, constant, event, member 101 | II.2.2 <Name Is="..." [IgnoreCase="true/false"] />. The 'Is' attribute contains regular expression 102 | II.2.3 <HasAttribute CLRName="..." [Inherit="true/false"] />. The 'CLRName' attribute contains regular expression 103 | II.2.4 <Access Is="..."/>. The 'Is' values are: public, protected, internal, protected internal, private 104 | II.2.5 <Static/> 105 | II.2.6 <Abstract/> 106 | II.2.7 <Virtual/> 107 | II.2.8 <Override/> 108 | II.2.9 <Sealed/> 109 | II.2.10 <Readonly/> 110 | II.2.11 <ImplementsInterface CLRName="..."/>. The 'CLRName' attribute contains regular expression 111 | II.2.12 <HandlesEvent /> 112 | --> 113 | 114 | <Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns"> 115 | 116 | <!--Do not reorder COM interfaces and structs marked by StructLayout attribute--> 117 | <Pattern> 118 | <Match> 119 | <Or Weight="100"> 120 | <And> 121 | <Kind Is="interface"/> 122 | <Or> 123 | <HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/> 124 | <HasAttribute CLRName="System.Runtime.InteropServices.ComImport"/> 125 | </Or> 126 | </And> 127 | <HasAttribute CLRName="System.Runtime.InteropServices.StructLayoutAttribute"/> 128 | </Or> 129 | </Match> 130 | </Pattern> 131 | 132 | <!--Special formatting of NUnit test fixture--> 133 | <Pattern RemoveAllRegions="true"> 134 | <Match> 135 | <And Weight="100"> 136 | <Kind Is="class"/> 137 | <HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/> 138 | </And> 139 | </Match> 140 | 141 | <!--Setup/Teardow--> 142 | <Entry> 143 | <Match> 144 | <And> 145 | <Kind Is="method"/> 146 | <Or> 147 | <HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/> 148 | <HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/> 149 | <HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/> 150 | <HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/> 151 | </Or> 152 | </And> 153 | </Match> 154 | <Group Region="Setup/Teardown"/> 155 | </Entry> 156 | 157 | <!--All other members--> 158 | <Entry/> 159 | 160 | <!--Test methods--> 161 | <Entry> 162 | <Match> 163 | <And Weight="100"> 164 | <Kind Is="method"/> 165 | <HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/> 166 | </And> 167 | </Match> 168 | <Sort> 169 | <Name/> 170 | </Sort> 171 | </Entry> 172 | </Pattern> 173 | 174 | <!--Default pattern--> 175 | <Pattern RemoveAllRegions="true"> 176 | 177 | <!--public delegate--> 178 | <Entry> 179 | <Match> 180 | <And Weight="100"> 181 | <Access Is="public"/> 182 | <Kind Is="delegate"/> 183 | </And> 184 | </Match> 185 | <Sort> 186 | <Name/> 187 | </Sort> 188 | <Group Region="Delegates"/> 189 | </Entry> 190 | 191 | <!--public enum--> 192 | <Entry> 193 | <Match> 194 | <And Weight="100"> 195 | <Access Is="public"/> 196 | <Kind Is="enum"/> 197 | </And> 198 | </Match> 199 | <Sort> 200 | <Name/> 201 | </Sort> 202 | <Group> 203 | <Name Region="${Name} enum"/> 204 | </Group> 205 | </Entry> 206 | 207 | <!--static fields and constants--> 208 | <Entry> 209 | <Match> 210 | <Or> 211 | <Kind Is="constant"/> 212 | <And> 213 | <Kind Is="field"/> 214 | <Static/> 215 | </And> 216 | </Or> 217 | </Match> 218 | <Sort> 219 | <Kind Order="constant field"/> 220 | </Sort> 221 | </Entry> 222 | 223 | <!--instance fields--> 224 | <Entry> 225 | <Match> 226 | <And> 227 | <Kind Is="field"/> 228 | <Not> 229 | <Static/> 230 | </Not> 231 | </And> 232 | </Match> 233 | <Sort> 234 | <Readonly/> 235 | <Name/> 236 | </Sort> 237 | </Entry> 238 | 239 | <!--Constructors. Place static one first--> 240 | <Entry> 241 | <Match> 242 | <Kind Is="constructor"/> 243 | </Match> 244 | <Sort> 245 | <Static/> 246 | </Sort> 247 | </Entry> 248 | 249 | <!--properties, indexers--> 250 | <Entry> 251 | <Match> 252 | <Or> 253 | <Kind Is="property"/> 254 | <Kind Is="indexer"/> 255 | </Or> 256 | </Match> 257 | </Entry> 258 | 259 | <!--interface implementations--> 260 | <Entry> 261 | <Match> 262 | <And Weight="100"> 263 | <Kind Is="member"/> 264 | <ImplementsInterface/> 265 | </And> 266 | </Match> 267 | <Sort> 268 | <ImplementsInterface Immediate="true"/> 269 | </Sort> 270 | <Group> 271 | <ImplementsInterface Immediate="true" Region="${ImplementsInterface} Members"/> 272 | </Group> 273 | </Entry> 274 | 275 | <!--all other members--> 276 | <Entry> 277 | <Match> 278 | <Kind Is="method"/> 279 | </Match> 280 | <Sort> 281 | <Access Order="public protected internal private" /> 282 | <Name/> 283 | </Sort> 284 | </Entry> 285 | 286 | <!--nested types--> 287 | <Entry> 288 | <Match> 289 | <Kind Is="type"/> 290 | </Match> 291 | <Sort> 292 | <Name/> 293 | </Sort> 294 | <Group> 295 | <Name Region="Nested type: ${Name}"/> 296 | </Group> 297 | </Entry> 298 | </Pattern> 299 | 300 | </Patterns> 301 | 302 | UseExplicitType 303 | UseExplicitType 304 | UseExplicitType 305 | CR 306 | EN 307 | HR 308 | ID 309 | JP 310 | LF 311 | MB 312 | MD 313 | OA 314 | QA 315 | RA 316 | RAQA 317 | RM 318 | UI 319 | $object$_On$event$ 320 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 321 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 322 | <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> 323 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 324 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 325 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 326 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 327 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 328 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 329 | <Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb"><ExtraRule Prefix="z" Suffix="" Style="AaBb" /><ExtraRule Prefix="t" Suffix="" Style="AaBb" /></Policy> 330 | <Policy Inspect="True" Prefix="s" Suffix="" Style="AaBb"><ExtraRule Prefix="z" Suffix="" Style="AaBb" /></Policy> 331 | <Policy Inspect="True" Prefix="s" Suffix="" Style="AaBb"><ExtraRule Prefix="z" Suffix="" Style="AaBb" /></Policy> 332 | <Policy Inspect="False" Prefix="" Suffix="" Style="AaBb" /> 333 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 334 | <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> 335 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 336 | <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="ProtectedInternal, Internal, Public" Description="Fields (not private or protected)"><ElementKinds><Kind Name="FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> 337 | <Policy><Descriptor Staticness="Instance" AccessRightKinds="Protected" Description="Instance fields (protected)"><ElementKinds><Kind Name="FIELD" /><Kind Name="CLASS" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb" /></Policy> 338 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 339 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 340 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 341 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 342 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 343 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 344 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 345 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 346 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 347 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 348 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 349 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 350 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 351 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 352 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 353 | <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> 354 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 355 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 356 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 357 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 358 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 359 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 360 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 361 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 362 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 363 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 364 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 365 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 366 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 367 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 368 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 369 | <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> 370 | $object$_On$event$ 371 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 372 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 373 | <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> 374 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 375 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 376 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 377 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 378 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 379 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 380 | <Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb" /> 381 | <Policy Inspect="True" Prefix="s" Suffix="" Style="AaBb" /> 382 | <Policy Inspect="True" Prefix="s" Suffix="" Style="AaBb" /> 383 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 384 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 385 | <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> 386 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 387 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 388 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 389 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 390 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 391 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> 392 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 393 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> 394 | True 395 | True 396 | True 397 | True 398 | True 399 | True 400 | True 401 | True 402 | True 403 | This constructor returns an empty Guid (00000000-0000-0000-0000-000000000000) 404 | True 405 | CSHARP 406 | Replace with a randomly generated non-empty Guid 407 | Guid.NewGuid() 408 | new Guid() 409 | ERROR 410 | True 411 | This constructor returns an empty Guid (00000000-0000-0000-0000-000000000000) 412 | True 413 | CSHARP 414 | Use the read only instance Guid.Empty instead 415 | Guid.Empty 416 | new Guid() 417 | ERROR 418 | True 419 | You probably want a URL to this pageInfo 420 | True 421 | CSHARP 422 | Use the redirect URL instead of the PageInfo 423 | new JProperty($string$, $pageInfo$.GetRedirectUrl(false)) 424 | new JProperty($string$, $pageInfo$) 425 | ERROR 426 | True 427 | False 428 | Symplectic.Elements.Website.Application.PageInfo 429 | ExpressionPlaceholder 430 | True 431 | True 432 | System.String 433 | ExpressionPlaceholder 434 | True 435 | Use GetNullableDateTimeLocal 436 | True 437 | CSHARP 438 | Use GetNullableDateTimeLocal 439 | $reader$.GetNullableDateTimeLocal($index$) 440 | $reader$.IsDBNull($index$) ? (DateTime?)null : $reader$.GetDateTimeLocal($index$) 441 | SUGGESTION 442 | True 443 | 1 444 | 1 445 | ArgumentPlaceholder 446 | True 447 | False 448 | System.Data.Common.DbDataReader 449 | ExpressionPlaceholder 450 | True 451 | Unnecessary SpecifyKind 452 | True 453 | CSHARP 454 | Remove SpecifyKind 455 | $reader$.GetDateTimeLocal($index$) 456 | DateTime.SpecifyKind($reader$.GetDateTimeLocal($index$), DateTimeKind.Local) 457 | SUGGESTION 458 | True 459 | 1 460 | 1 461 | ArgumentPlaceholder 462 | True 463 | False 464 | System.Data.Common.DbDataReader 465 | ExpressionPlaceholder 466 | True 467 | You probably want a URL to this pageInfo. 468 | True 469 | CSHARP 470 | Use the redirect URL instead of the PageInfo. 471 | new XAttribute($string$, $pageInfo$.GetRedirectUrl(false)) 472 | new XAttribute($string$, $pageInfo$) 473 | ERROR 474 | True 475 | False 476 | Symplectic.Elements.Website.Application.PageInfo 477 | ExpressionPlaceholder 478 | True 479 | True 480 | System.String 481 | ExpressionPlaceholder 482 | True 483 | Possible unexpected inheritance behaviour 484 | True 485 | CSHARP 486 | Use Attribute.GetCustomAttributes 487 | Attribute.GetCustomAttributes($mi$, $args$) 488 | $mi$.GetCustomAttributes($args$) 489 | ERROR 490 | True 491 | -1 492 | -1 493 | ArgumentPlaceholder 494 | True 495 | False 496 | System.Reflection.MemberInfo 497 | ExpressionPlaceholder 498 | True 499 | You probably want a URL to this pageInfo. 500 | True 501 | CSHARP 502 | Use the redirect URL instead of the PageInfo. 503 | new XElement($string$, $pageInfo$.GetRedirectUrl(false)) 504 | new XElement($string$, $pageInfo$) 505 | ERROR 506 | True 507 | False 508 | Symplectic.Elements.Website.Application.PageInfo 509 | ExpressionPlaceholder 510 | True 511 | True 512 | System.String 513 | ExpressionPlaceholder 514 | True 515 | Passing an update instruction rather than the value it contains. 516 | True 517 | CSHARP 518 | Use the Update's value instead. 519 | $command$.Parameters.AddWithValue($str$, $update$.Value) 520 | $command$.Parameters.AddWithValue($str$, $update$) 521 | ERROR 522 | True 523 | True 524 | System.Data.SqlClient.SqlCommand 525 | ExpressionPlaceholder 526 | True 527 | True 528 | System.String 529 | ExpressionPlaceholder 530 | True 531 | True 532 | Symplectic.Foundation.Update<T> 533 | ExpressionPlaceholder 534 | True 535 | Likely unintended omission of DateTime.Kind assignment. 536 | True 537 | CSHARP 538 | Use GetDateTimeLocal 539 | $reader$.GetDateTimeLocal($index$) 540 | $reader$.GetDateTime($index$) 541 | ERROR 542 | True 543 | 1 544 | 1 545 | ArgumentPlaceholder 546 | True 547 | False 548 | System.Data.Common.DbDataReader 549 | ExpressionPlaceholder 550 | True 551 | Red 552 | True 553 | CodeReview 554 | (?<=\W|^)(?<TAG>CODEREVIEW)(\W|$)(.*) 555 | Normal -------------------------------------------------------------------------------- /AnsiColorOut/AnsiColorOut.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.IO; 7 | using System.Collections; 8 | using System.Diagnostics; 9 | using System.Reflection; 10 | 11 | namespace Bozho.PowerShell { 12 | 13 | public class AnsiColorOut { 14 | 15 | const string HashtableColor = "Color"; 16 | const string HashtableMatch = "Match"; 17 | 18 | /// 19 | /// A lazily initialized FilSystemInfo color matcher. Used for better performance, 20 | /// to avoid calling into MatchManager for every GetFileInfoAnsiColor call. 21 | /// 22 | static readonly Lazy sFileInfoColorMatcher; 23 | 24 | /// 25 | /// A lazily initialized System.Diagnostics.Process color matcher. Used for better 26 | /// performance, to avoid calling into MatchManager for every GetFileInfoAnsiColor call. 27 | /// 28 | static readonly Lazy sProcessColorMatcher; 29 | 30 | 31 | /// 32 | /// Foreground ANSI color escape strings. 33 | /// 34 | static readonly Dictionary sForegroundAnsiColors; 35 | 36 | /// 37 | /// Background ANSI color escape strings. 38 | /// 39 | static readonly Dictionary sBackgroundAnsiColors; 40 | 41 | #region ctor 42 | 43 | static AnsiColorOut() { 44 | 45 | sFileInfoColorMatcher = new Lazy(() => MatcherManager.GetMatcher(typeof(FileSystemInfo))); 46 | 47 | sProcessColorMatcher = new Lazy(() => MatcherManager.GetMatcher(typeof(Process))); 48 | 49 | sForegroundAnsiColors = new Dictionary { 50 | { ConsoleColor.DarkGray, "\x1B[1;30m" }, 51 | { ConsoleColor.Black, "\x1B[0;30m" }, 52 | 53 | { ConsoleColor.Red, "\x1B[1;31m" }, 54 | { ConsoleColor.DarkRed, "\x1B[0;31m" }, 55 | 56 | { ConsoleColor.Green, "\x1B[1;32m" }, 57 | { ConsoleColor.DarkGreen, "\x1B[0;32m" }, 58 | 59 | { ConsoleColor.Yellow, "\x1B[1;33m" }, 60 | { ConsoleColor.DarkYellow, "\x1B[0;33m" }, 61 | 62 | { ConsoleColor.Blue, "\x1B[1;34m" }, 63 | { ConsoleColor.DarkBlue, "\x1B[0;34m" }, 64 | 65 | { ConsoleColor.Magenta, "\x1B[1;35m" }, 66 | { ConsoleColor.DarkMagenta, "\x1B[0;35m" }, 67 | 68 | { ConsoleColor.Cyan, "\x1B[1;36m" }, 69 | { ConsoleColor.DarkCyan, "\x1B[0;36m" }, 70 | 71 | { ConsoleColor.White, "\x1B[1;37m" }, 72 | { ConsoleColor.Gray, "\x1B[0;37m" }, 73 | 74 | }; 75 | 76 | sBackgroundAnsiColors = new Dictionary { 77 | { ConsoleColor.DarkGray, "\x1B[1;40m" }, 78 | { ConsoleColor.Black, "\x1B[0;40m" }, 79 | 80 | { ConsoleColor.Red, "\x1B[1;41m" }, 81 | { ConsoleColor.DarkRed, "\x1B[0;41m" }, 82 | 83 | { ConsoleColor.Green, "\x1B[1;42m" }, 84 | { ConsoleColor.DarkGreen, "\x1B[0;42m" }, 85 | 86 | { ConsoleColor.Yellow, "\x1B[1;43m" }, 87 | { ConsoleColor.DarkYellow, "\x1B[0;43m" }, 88 | 89 | { ConsoleColor.Blue, "\x1B[1;44m" }, 90 | { ConsoleColor.DarkBlue, "\x1B[0;44m" }, 91 | 92 | { ConsoleColor.Magenta, "\x1B[1;45m" }, 93 | { ConsoleColor.DarkMagenta, "\x1B[0;45m" }, 94 | 95 | { ConsoleColor.Cyan, "\x1B[1;46m" }, 96 | { ConsoleColor.DarkCyan, "\x1B[0;46m" }, 97 | 98 | { ConsoleColor.White, "\x1B[1;47m" }, 99 | { ConsoleColor.Gray, "\x1B[0;47m" }, 100 | 101 | }; 102 | 103 | ForegroundColorReset = "\x1B[39m"; 104 | BackgroundColorReset = "\x1B[49m"; 105 | ColorReset = "\x1B[0m"; 106 | } 107 | 108 | #endregion ctor 109 | 110 | 111 | #region public members 112 | 113 | public static string GetAnsiString(object target) { 114 | IColorMatcher colorMatcher; 115 | if(!MatcherManager.TryGetMatcher(target.GetType(), out colorMatcher)) return ColorReset; 116 | 117 | IColorMatch match = colorMatcher.GetMatch(target); 118 | return match == null ? ColorReset : sForegroundAnsiColors[match.ForegroundColor]; 119 | } 120 | 121 | public static string GetFileInfoAnsiString(FileSystemInfo target) { 122 | IColorMatch match = sFileInfoColorMatcher.Value.GetMatch(target); 123 | return match == null ? ColorReset : sForegroundAnsiColors[match.ForegroundColor]; 124 | } 125 | 126 | public static string GetProcessAnsiString(Process target) { 127 | IColorMatch match = sProcessColorMatcher.Value.GetMatch(target); 128 | return match == null ? ColorReset : sForegroundAnsiColors[match.ForegroundColor]; 129 | } 130 | 131 | public static string GetForegroundAnsiColor(ConsoleColor color) { return sForegroundAnsiColors[color]; } 132 | 133 | public static string GetBackgroundAnsiColor(ConsoleColor color) { return sBackgroundAnsiColors[color]; } 134 | 135 | 136 | /// 137 | /// Global matcher manager. 138 | /// 139 | public static IColorMatcherManager MatcherManager { get; set; } 140 | 141 | /// 142 | /// Foreground color reset ANSI escape sequence. 143 | /// 144 | public static string ForegroundColorReset { get; } 145 | 146 | /// 147 | /// Background color reset ANSI escape sequence. 148 | /// 149 | public static string BackgroundColorReset { get; } 150 | 151 | /// 152 | /// Color reset ANSI escape sequence 153 | /// 154 | public static string ColorReset { get; } 155 | 156 | #endregion public members 157 | 158 | 159 | #region cmdlet support methods 160 | 161 | internal static void SetMatcherColors(Hashtable[] matcherColors) { 162 | IColorMatcher matcher = (IColorMatcher)MatcherManager.GetMatcher(typeof(T)); 163 | 164 | var matches = from matcherColor in matcherColors 165 | let foregroundColor = (ConsoleColor)matcherColor[HashtableColor] 166 | let match = matcherColor[HashtableMatch] 167 | select matcher.CreateMatch(foregroundColor, match); 168 | 169 | matcher.SetMatches(matches); 170 | } 171 | 172 | internal static Hashtable[] GetMatchColors() { 173 | IColorMatcher matcher = (IColorMatcher)MatcherManager.GetMatcher(typeof(T)); 174 | 175 | return (from match in matcher.GetMatches() 176 | select new Hashtable { 177 | [HashtableColor] = match.ForegroundColor, 178 | [HashtableMatch] = match.GetMatchData() 179 | }).ToArray(); 180 | } 181 | 182 | #endregion cmdlet support methods 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /AnsiColorOut/AnsiColorOut.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {86074F90-6CBE-43CF-A9DA-5289F1BBEBB0} 8 | Library 9 | Properties 10 | Bozho.PowerShell 11 | Bozho.PowerShell.AnsiColorOut 12 | v4.5.2 13 | 512 14 | 15 | 16 | 17 | 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | false 28 | bin\Debug\Bozho.PowerShell.AnsiColorOut.XML 29 | 1591 30 | 31 | 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | false 39 | bin\Release\Bozho.PowerShell.AnsiColorOut.XML 40 | 1591 41 | 42 | 43 | 44 | 45 | 46 | False 47 | C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Designer 75 | 76 | 77 | Designer 78 | 79 | 80 | Designer 81 | 82 | 83 | 84 | 85 | 86 | 87 | copy $(ProjectDir)AnsiColorOut.psd1 $(TargetDir) 88 | copy $(ProjectDir)AnsiColorOut.psm1 $(TargetDir) 89 | robocopy.exe $(ProjectDir)formats $(TargetDir)formats /E /NP /NJH 90 | robocopy.exe $(ProjectDir)types $(TargetDir)types /E /NP /NJH 91 | copy $(ProjectDir)SampleProfile.ps1 $(TargetDir) 92 | 93 | mkdir $(TargetDir)en-US 94 | move $(TargetDir)$(TargetFileName)-Help.xml $(TargetDir)en-US 95 | 96 | 97 | 98 | 99 | 100 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 101 | 102 | 103 | 104 | 105 | 106 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /AnsiColorOut/AnsiColorOut.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | RootModule = 'AnsiColorOut.psm1' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '0.2.0.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'C455F558-E09A-417E-9009-80A31AC17BFC' 11 | 12 | # Author of this module 13 | Author = 'Marko Bozikovic ' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Bozho' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2016-2017. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'ANSI color escape sequences for console output.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '5.0' 26 | 27 | # Name of the Windows PowerShell host required by this module 28 | # PowerShellHostName = '' 29 | 30 | # Minimum version of the Windows PowerShell host required by this module 31 | # PowerShellHostVersion = '' 32 | 33 | # Minimum version of Microsoft .NET Framework required by this module 34 | # DotNetFrameworkVersion = '' 35 | 36 | # Minimum version of the common language runtime (CLR) required by this module 37 | # CLRVersion = '' 38 | 39 | # Processor architecture (None, X86, Amd64) required by this module 40 | # ProcessorArchitecture = '' 41 | 42 | # Modules that must be imported into the global environment prior to importing this module 43 | #RequiredModules = @() 44 | 45 | # Assemblies that must be loaded prior to importing this module 46 | # RequiredAssemblies = @() 47 | 48 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 49 | # ScriptsToProcess = @() 50 | 51 | # Type files (.ps1xml) to be loaded when importing this module 52 | # TypesToProcess = @() 53 | 54 | # Format files (.ps1xml) to be loaded when importing this module 55 | # FormatsToProcess = @() 56 | 57 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 58 | NestedModules = @("Bozho.PowerShell.AnsiColorOut.dll") 59 | 60 | # Functions to export from this module 61 | FunctionsToExport = @( 62 | ) 63 | 64 | # Cmdlets to export from this module 65 | CmdletsToExport = "*" 66 | 67 | # Variables to export from this module 68 | #VariablesToExport = '*' 69 | 70 | # Aliases to export from this module 71 | #AliasesToExport = '*' 72 | 73 | # List of all modules packaged with this module 74 | #ModuleList = @() 75 | 76 | # List of all files packaged with this module 77 | # FileList = @() 78 | 79 | # Private data to pass to the module specified in RootModule/ModuleToProcess 80 | # PrivateData = '' 81 | 82 | # HelpInfo URI of this module 83 | # HelpInfoURI = '' 84 | 85 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 86 | # DefaultCommandPrefix = '' 87 | 88 | } 89 | 90 | -------------------------------------------------------------------------------- /AnsiColorOut/AnsiColorOut.psm1: -------------------------------------------------------------------------------- 1 | # set accelerators 2 | $accel = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators') 3 | $accel::Add("AnsiColorOut", [Bozho.PowerShell.AnsiColorOut]) 4 | 5 | $matcherManager = New-Object Bozho.PowerShell.ColorMatcherManager 6 | $matcherManager.RegisterMatchers([Bozho.PowerShell.AnsiColorOut].Assembly) 7 | 8 | [Bozho.PowerShell.AnsiColorOut]::MatcherManager = $matcherManager 9 | 10 | # add type extensions and custom formats 11 | Get-ChildItem -Path "$PSScriptRoot\types\*.ps1xml" | % { Update-TypeData -AppendPath $_ } 12 | Get-ChildItem -Path "$PSScriptRoot\formats\*.ps1xml" | % { Update-FormatData -AppendPath $_ } 13 | -------------------------------------------------------------------------------- /AnsiColorOut/AnsiColorOutTest.ps1: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /AnsiColorOut/Cmdlets.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Management.Automation; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Bozho.PowerShell { 11 | 12 | internal static class AnsiColorNouns { 13 | internal const string FileSystemColors = "FileSystemColors"; 14 | internal const string ProcessColors = "ProcessColors"; 15 | internal const string FileInfoAttributePattern = "FileInfoAttributePattern"; 16 | } 17 | 18 | 19 | /// 20 | /// A base class for color matchers' Set-XXXColors cmdlets. 21 | /// 22 | public abstract class SetMatcherColors : PSCmdlet { 23 | [Parameter(Position = 0, Mandatory = true)] 24 | public Hashtable[] Colors { get; set; } 25 | 26 | protected override void EndProcessing() { AnsiColorOut.SetMatcherColors(Colors); } 27 | } 28 | 29 | 30 | /// 31 | /// A base class for color matchers' Get-XXXColors cmdlets. 32 | /// 33 | public abstract class GetMatcherColors : PSCmdlet { 34 | protected override void EndProcessing() { 35 | // The second parameter in WriteObject tells PS to enumerate the array, 36 | // sending one object at a time to the pipeline. 37 | WriteObject(AnsiColorOut.GetMatchColors(), true); 38 | } 39 | } 40 | 41 | 42 | /// 43 | /// Configures color mappings for file and directory output. 44 | /// Use this cmdlet to configure color mappings for file and directory output. 45 | /// The input parameter is an array of hashtables. Each hashtable has two members: 46 | /// Match and Color. 47 | /// Match can be one of the following: 48 | /// * An array of strings, which are matched against extensions 49 | /// * A System.IO.FileAttributes (or a combination), which are matched against file/dir attributes 50 | /// * A regular expression, which is matched against file/dir name(just the name, not the full path) 51 | /// * A script block with a single System.IO.FileSystemInfo parameter returning bool. 52 | /// 53 | /// When using Format-Custom to output files and directories 54 | /// (e.g. using Get-ChildItems | Format-Custom), matching items will have ANSI foreground color codes embedded 55 | /// in output strings. These codes can then be interpreted by ANSI-aware tools, like GNU less or AnsiCon. 56 | /// PowerShell 5 is able to interpret ANSI escape sequences natively. 57 | /// 58 | /// 59 | /// 60 | /// $fileSystemColors = @( 61 | /// # this entry will match directories 62 | /// @{ 63 | /// Match = [System.IO.FileAttributes]::Directory; 64 | /// Color = [System.ConsoleColor]::Gray 65 | /// }, 66 | /// # alternatively, we could've used a script block to match directories 67 | /// @{ 68 | /// Match = { param($f) $f.PSIsContainer }; 69 | /// Color = [System.ConsoleColor]::Gray 70 | /// }, 71 | /// # this entry will match files with extensions log, err or out 72 | /// # (it won't get a chance to match directories, since they'll 73 | /// # all be matched by the first entry) 74 | /// @{ 75 | /// Match = @("log", "err", "out"); 76 | /// Color = [System.ConsoleColor]::DarkGreen 77 | /// }, 78 | /// # this entry will match all files with a leading . in the name 79 | /// @{ 80 | /// Match = [regex] "^\..*"; 81 | /// Color = [System.ConsoleColor]::DarkGray 82 | /// } 83 | /// ) 84 | /// 85 | /// Set-FileSystemColors -Colors $fileSystemColors 86 | /// 87 | /// A simple example demonstrating supported matchers 88 | /// 89 | /// 90 | [Cmdlet(VerbsCommon.Set, AnsiColorNouns.FileSystemColors)] 91 | public class SetFileSystemColors : SetMatcherColors { } 92 | 93 | 94 | /// 95 | /// Gets a copy of currently configured color mappings for file and directory output. 96 | /// This cmdlet will return a copy of currently configured color mappings for file 97 | /// and directory output. 98 | /// 99 | [Cmdlet(VerbsCommon.Get, AnsiColorNouns.FileSystemColors)] 100 | public class GetFileSystemColors : GetMatcherColors { } 101 | 102 | 103 | /// 104 | /// Configures color mappings for process output. 105 | /// Use this cmdlet to configure color mappings for process output. 106 | /// The input parameter is an array of hashtables. Each hashtable has two members: 107 | /// Match and Color. 108 | /// Match can be one of the following: 109 | /// * ProcessPriorityClass (Idle, BelowNormal, Normal, AboveNormal, High, RealTime) 110 | /// 111 | /// When using Format-XXX to output process data (e.g. using Get-Process | Format-XXX), 112 | /// matching items will have ANSI foreground color codes embedded in output strings. These codes can then be 113 | /// interpreted by ANSI-aware tools, like GNU less or AnsiCon. PowerShell 5 is able to interpret ANSI escape 114 | /// sequences natively. 115 | /// 116 | /// 117 | /// 118 | /// $processColors = @( 119 | /// @{ 120 | /// Match = "Idle" 121 | /// Color = [System.ConsoleColor]::DarkMagenta 122 | /// } 123 | /// @{ 124 | /// Match = "BelowNormal" 125 | /// Color = [System.ConsoleColor]::DarkGray 126 | /// } 127 | /// @{ 128 | /// Match = "BelowNormal" 129 | /// Color = [System.ConsoleColor]::DarkCyan 130 | /// } 131 | /// @{ 132 | /// Match = "Normal" 133 | /// Color = [System.ConsoleColor]::White 134 | /// } 135 | /// @{ 136 | /// Match = "AboveNormal" 137 | /// Color = [System.ConsoleColor]::Green 138 | /// } 139 | /// @{ 140 | /// Match = "High" 141 | /// Color = [System.ConsoleColor]::Yellow 142 | /// } 143 | /// @{ 144 | /// Match = "RealTime" 145 | /// Color = [System.ConsoleColor]::Red 146 | /// } 147 | /// ) 148 | /// 149 | /// Set-ProcessColors -Colors $processColors 150 | /// 151 | /// A simple example demonstrating supported matchers 152 | /// 153 | /// 154 | [Cmdlet(VerbsCommon.Set, AnsiColorNouns.ProcessColors)] 155 | public class SetProcessColors : SetMatcherColors { } 156 | 157 | 158 | /// 159 | /// Gets a copy of currently configured color mappings for process output. 160 | /// This cmdlet will return a copy of currently configured color mappings for 161 | /// process output. 162 | /// 163 | [Cmdlet(VerbsCommon.Get, AnsiColorNouns.ProcessColors)] 164 | public class GetProcessColors : GetMatcherColors { } 165 | 166 | 167 | /// 168 | /// Configures attribute string pattern for file and directory custom property, ExtendedMode. 169 | /// Configures attribute string pattern for file and directory custom property, ExtendedMode. It can also be used to reset current pattern to the default one. 170 | /// Currently supported attributes: 171 | /// A - Archive 172 | /// C - Compressed 173 | /// D - Directory 174 | /// E - Encrypted 175 | /// H - Hidden 176 | /// G - IntegrityStream 177 | /// N - Normal 178 | /// B - NoScrubData 179 | /// I - NotContentIndexed 180 | /// O - Offline 181 | /// R - ReadOnly 182 | /// J - ReparsePoint 183 | /// P - SparseFile 184 | /// S - System 185 | /// T - Temporary 186 | /// 187 | /// 188 | /// 189 | /// 190 | /// Set-FileInfoAttributePattern -AttributePattern DARHS 191 | /// 192 | /// Setting a custom parameter to indicated directories, archive, read=only, hidden and system attributes 193 | /// 194 | /// 195 | /// 196 | /// 197 | /// Set-FileInfoAttributePattern -DefaultPattern 198 | /// 199 | /// Setting the default pattern 200 | /// 201 | /// 202 | [Cmdlet(VerbsCommon.Set, AnsiColorNouns.FileInfoAttributePattern)] 203 | public class SetFileInfoAttributePattern : PSCmdlet { 204 | 205 | string mAttributePattern; 206 | 207 | /// 208 | /// Used to specify custom attribute pattern for ExtendedMode property 209 | /// 210 | [Parameter(Position = 0, Mandatory = true)] 211 | public string AttributePattern { 212 | get { return mAttributePattern; } 213 | set { mAttributePattern = value; } 214 | } 215 | 216 | SwitchParameter mDefaultPattern; 217 | 218 | /// 219 | /// Resets the ExtendedMode attribute pattern to the default one. 220 | /// 221 | [Parameter(Position = 1)] 222 | public SwitchParameter DefaultPattern { 223 | get { return mDefaultPattern; } 224 | set { mDefaultPattern = value; } 225 | } 226 | 227 | protected override void EndProcessing() { 228 | FileSystemInfoExtensions.SetFileInfoAttributePattern(this); 229 | } 230 | } 231 | 232 | 233 | /// 234 | /// Returns currently configured attribute string pattern for file and directory custom property, ExtendedMode. 235 | /// Returns currently configured attribute string pattern for file and directory custom property, ExtendedMode. 236 | /// Additionally, if the -ShowAll parameter is used, the cmdled will print out all supported attributes and their names. 237 | /// Currently supported attributes: 238 | /// A - Archive 239 | /// C - Compressed 240 | /// D - Directory 241 | /// E - Encrypted 242 | /// H - Hidden 243 | /// G - IntegrityStream 244 | /// N - Normal 245 | /// B - NoScrubData 246 | /// I - NotContentIndexed 247 | /// O - Offline 248 | /// R - ReadOnly 249 | /// J - ReparsePoint 250 | /// P - SparseFile 251 | /// S - System 252 | /// T - Temporary 253 | /// 254 | /// 255 | [Cmdlet(VerbsCommon.Get, AnsiColorNouns.FileInfoAttributePattern)] 256 | public class GetFileInfoAttributePattern : PSCmdlet { 257 | 258 | SwitchParameter mShowAll; 259 | /// 260 | /// If specified, the cmdled will print out all supported attributes and their names. 261 | /// 262 | [Parameter(Position = 0)] 263 | public SwitchParameter ShowAll { 264 | get { return mShowAll; } 265 | set { mShowAll = value; } 266 | } 267 | protected override void EndProcessing() { 268 | WriteObject(FileSystemInfoExtensions.GetFileInfoAttributePattern(this)); 269 | } 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /AnsiColorOut/ColorMatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Bozho.PowerShell { 6 | 7 | /// 8 | /// Base color matcher class. 9 | /// 10 | /// Target object's type. 11 | public abstract class ColorMatcher : IColorMatcher { 12 | 13 | readonly List> mMatches; 14 | 15 | protected ColorMatcher() { 16 | mMatches = new List>(); 17 | } 18 | 19 | /// 20 | /// Strongly typed GetMatch method. 21 | /// 22 | /// 23 | /// IColorMatch matching the target object. Null if no match was found. 24 | public IColorMatch GetMatch(TTarget target) { return mMatches.FirstOrDefault(c => c.IsMatch(target)); } 25 | 26 | /// 27 | /// Sets matches for the matcher. 28 | /// 29 | public void SetMatches(IEnumerable> matches) { 30 | mMatches.Clear(); 31 | mMatches.AddRange(matches); 32 | } 33 | 34 | /// 35 | /// Retrieves currently registered matches. 36 | /// 37 | /// 38 | public IEnumerable> GetMatches() { return mMatches.AsEnumerable(); } 39 | 40 | /// 41 | /// A factory method for matches. Implementing classes for a target type will 42 | /// create instances of its subclasses based on the colorMatch type (and possibly 43 | /// other conditions) 44 | /// 45 | public abstract IColorMatch CreateMatch(ConsoleColor foregroundColor, object colorMatch); 46 | 47 | /// 48 | /// The method will attempt to find a match matching the target object, using 49 | /// a collection of stored matches (using IColorMatch<TTarget/^>.IsMatch()) 50 | /// 51 | /// Target object for matching 52 | /// Matching IColorMatch, or null if none was found. 53 | IColorMatch IColorMatcher.GetMatch(object target) { return GetMatch((TTarget)target); } 54 | } 55 | } -------------------------------------------------------------------------------- /AnsiColorOut/ColorMatcherManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace Bozho.PowerShell { 7 | 8 | /// 9 | /// Color matcher manager class. 10 | /// 11 | public class ColorMatcherManager : IColorMatcherManager { 12 | 13 | readonly Dictionary mMatchers; 14 | 15 | public ColorMatcherManager() { mMatchers = new Dictionary(); } 16 | 17 | /// 18 | /// The method will register all matchers (classes implementing IColorMatcher<> interface) 19 | /// in the specified assembly using Reflection. 20 | /// 21 | public void RegisterMatchers(Assembly assembly) { 22 | 23 | // get all types implementing IColorMatcher interface 24 | IEnumerable colorMatcherTypes = 25 | from type in assembly.GetTypes() 26 | where !type.IsGenericType && type.IsAssignableToGenericType(typeof(IColorMatcher<>)) 27 | select type; 28 | 29 | foreach(Type colorMatcherType in colorMatcherTypes) { 30 | // for each color matcher, get interface types 31 | IEnumerable colorMatcherInterfaces = 32 | from i in colorMatcherType.GetInterfaces() 33 | where i.IsConstructedGenericType && i.GetGenericTypeDefinition() == typeof(IColorMatcher<>) 34 | select i; 35 | 36 | foreach(Type colorMatcherInterface in colorMatcherInterfaces) { 37 | // for each interface, extract the target type 38 | Type matchingType = colorMatcherInterface.GetGenericArguments().First(); 39 | if(mMatchers.ContainsKey(matchingType)) continue; 40 | 41 | // if the target type is not already registered, create an instance of the matcher and register it. 42 | IColorMatcher matcher = (IColorMatcher)Activator.CreateInstance(colorMatcherType); 43 | mMatchers.Add(matchingType, matcher); 44 | } 45 | } 46 | } 47 | 48 | /// 49 | /// Retrieves a matcher based on the target object type. Throws if type is not found. 50 | /// 51 | public IColorMatcher GetMatcher(Type type) { return mMatchers[type]; } 52 | 53 | /// 54 | /// Tries to retrieve a matcher based on the target type. 55 | /// 56 | public bool TryGetMatcher(Type type, out IColorMatcher matcher) { return mMatchers.TryGetValue(type, out matcher); } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /AnsiColorOut/Console.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Bozho.PowerShell { 5 | /// 6 | /// A Console helper class. 7 | /// 8 | public static class Console { 9 | [DllImport("kernel32.dll")] 10 | public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode); 11 | 12 | [DllImport("kernel32.dll")] 13 | public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int mode); 14 | 15 | [DllImport("kernel32.dll")] 16 | public static extern IntPtr GetStdHandle(int handle); 17 | 18 | public const int STD_INPUT_HANDLE = -10; 19 | public const int STD_OUTPUT_HANDLE = -11; 20 | public const int STD_ERROR_HANDLE = -12; 21 | 22 | [Flags] 23 | public enum ConsoleInputModes : uint { 24 | ENABLE_PROCESSED_INPUT = 0x0001, 25 | ENABLE_LINE_INPUT = 0x0002, 26 | ENABLE_ECHO_INPUT = 0x0004, 27 | ENABLE_WINDOW_INPUT = 0x0008, 28 | ENABLE_MOUSE_INPUT = 0x0010, 29 | ENABLE_INSERT_MODE = 0x0020, 30 | ENABLE_QUICK_EDIT_MODE = 0x0040, 31 | ENABLE_EXTENDED_FLAGS = 0x0080, 32 | ENABLE_AUTO_POSITION = 0x0100, 33 | } 34 | 35 | [Flags] 36 | public enum ConsoleOutputModes : uint { 37 | ENABLE_PROCESSED_OUTPUT = 0x0001, 38 | ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002, 39 | ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004, 40 | DISABLE_NEWLINE_AUTO_RETURN = 0x0008, 41 | ENABLE_LVB_GRID_WORLDWIDE = 0x0010, 42 | } 43 | 44 | /// 45 | /// Cygwin utilities (at the time of this writing) seem to be stripping 46 | /// ENABLE_VIRTUAL_TERMINAL_PROCESSING output handle flag, which disables ANSI 47 | /// sequence processing in PowerShell. 48 | /// 49 | /// The best workaround I came up with was this method that re-adds the flag. 50 | /// 51 | /// You can execute in your custom prompt function, or add it to something like 52 | /// a custom cls function. 53 | /// 54 | public static void EnableVirtualTerminalProcessing() { 55 | int mode; 56 | IntPtr handle = GetStdHandle(STD_OUTPUT_HANDLE); 57 | GetConsoleMode(handle, out mode); 58 | mode |= (int)ConsoleOutputModes.ENABLE_VIRTUAL_TERMINAL_PROCESSING; 59 | SetConsoleMode(handle, mode); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /AnsiColorOut/FileSystemInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Bozho.PowerShell { 10 | 11 | public static class FileSystemInfoExtensions { 12 | 13 | static readonly char[] sDefaultFileAttributePattern; 14 | static char[] sFileAttributePattern; 15 | static readonly Dictionary sFileAttributeChars; 16 | 17 | static FileSystemInfoExtensions() { 18 | sDefaultFileAttributePattern = new char[] { 'D', 'N', 'R', 'H', 'S', 'A', 'E', 'T', 'P', 'C', 'O', 'I', 'J', 'G', 'B' }; 19 | sFileAttributePattern = sDefaultFileAttributePattern; 20 | 21 | sFileAttributeChars = new Dictionary { 22 | { 'A', FileAttributes.Archive }, 23 | { 'C', FileAttributes.Compressed }, 24 | { 'D', FileAttributes.Directory }, 25 | { 'E', FileAttributes.Encrypted }, 26 | { 'H', FileAttributes.Hidden }, 27 | { 'G', FileAttributes.IntegrityStream }, 28 | { 'N', FileAttributes.Normal }, 29 | { 'B', FileAttributes.NoScrubData }, 30 | { 'I', FileAttributes.NotContentIndexed }, 31 | { 'O', FileAttributes.Offline }, 32 | { 'R', FileAttributes.ReadOnly }, 33 | { 'J', FileAttributes.ReparsePoint }, 34 | { 'P', FileAttributes.SparseFile }, 35 | { 'S', FileAttributes.System }, 36 | { 'T', FileAttributes.Temporary } 37 | }; 38 | } 39 | 40 | #region public members 41 | 42 | public static string GetExtendedMode(PSObject fsObject) { 43 | FileSystemInfo fs = (FileSystemInfo)fsObject.BaseObject; 44 | 45 | StringBuilder extendedMode = new StringBuilder(sFileAttributePattern.Length); 46 | 47 | foreach (var attr in sFileAttributePattern) { 48 | if ((fs.Attributes & sFileAttributeChars[attr]) != 0) { 49 | extendedMode.Append(attr); 50 | } 51 | else { 52 | extendedMode.Append('_'); 53 | } 54 | } 55 | return extendedMode.ToString(); 56 | } 57 | 58 | #endregion public members 59 | 60 | 61 | #region cmdlet support methods 62 | 63 | internal static void SetFileInfoAttributePattern(SetFileInfoAttributePattern setFileInfoAttributePattern) { 64 | 65 | if (setFileInfoAttributePattern.DefaultPattern.IsPresent) { 66 | sFileAttributePattern = sDefaultFileAttributePattern; 67 | return; 68 | } 69 | 70 | sFileAttributePattern = (from p in setFileInfoAttributePattern.AttributePattern.ToCharArray() 71 | let attr = Char.ToUpper(p) 72 | where sFileAttributeChars.ContainsKey(attr) 73 | select attr).ToArray(); 74 | } 75 | 76 | 77 | internal static string GetFileInfoAttributePattern(GetFileInfoAttributePattern getFileInfoAttributePattern) { 78 | StringBuilder output = new StringBuilder(); 79 | sFileAttributePattern.Aggregate(output, (sb, c) => sb.Append(c), (sb) => sb); 80 | 81 | if (getFileInfoAttributePattern.ShowAll.IsPresent) { 82 | output.AppendLine().AppendLine(); 83 | 84 | foreach (var fa in sFileAttributeChars) { 85 | output.AppendLine(String.Format("{0} - {1}", fa.Key, fa.Value.ToString())); 86 | } 87 | output.AppendLine(); 88 | } 89 | 90 | return output.ToString(); 91 | } 92 | 93 | #endregion cmdlet support methods 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /AnsiColorOut/FileSystemInfoMatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Management.Automation; 7 | using System.Management.Automation.Language; 8 | using System.Text.RegularExpressions; 9 | 10 | namespace Bozho.PowerShell { 11 | 12 | /// 13 | /// Color matcher for FileSystemInfo targets. 14 | /// 15 | public class FileSystemInfoMatcher : ColorMatcher { 16 | public override IColorMatch CreateMatch(ConsoleColor foregroundColor, object colorMatch) { 17 | Type colorMatchType = colorMatch.GetType(); 18 | 19 | if(colorMatchType.IsArray && (colorMatchType.GetElementType().IsAssignableFrom(typeof(string)))) return new FileExtensionMatch(foregroundColor, ((Array)colorMatch).Cast().ToArray()); 20 | 21 | if(colorMatchType.IsAssignableFrom(typeof(Regex))) return new FileRegexNameMatch(foregroundColor, (Regex)colorMatch); 22 | 23 | if(colorMatchType.IsAssignableFrom(typeof(ScriptBlock))) return new FileScriptMatch(foregroundColor, (ScriptBlock)colorMatch); 24 | 25 | if (colorMatch is FileAttributes) return new FileAttributeMatch(foregroundColor, (FileAttributes)colorMatch); 26 | 27 | throw new ArgumentException("Unsupported file system color match type!", nameof(colorMatch)); 28 | } 29 | } 30 | 31 | 32 | /// 33 | /// A base class for FileSystemInfo target matches. 34 | /// 35 | public abstract class FileSystemInfoMatch : IColorMatch { 36 | 37 | protected FileSystemInfoMatch(ConsoleColor foregroundColor) { ForegroundColor = foregroundColor; } 38 | 39 | public ConsoleColor ForegroundColor { get; } 40 | 41 | public abstract bool IsMatch(FileSystemInfo target); 42 | public abstract object GetMatchData(); 43 | 44 | bool IColorMatch.IsMatch(object target) { return IsMatch((FileSystemInfo)target);} 45 | } 46 | 47 | 48 | /// 49 | /// Output color match that matches on file extensions. 50 | /// 51 | /// Does not match directories. 52 | /// 53 | internal class FileExtensionMatch : FileSystemInfoMatch { 54 | 55 | readonly HashSet mExtensions; 56 | 57 | public FileExtensionMatch(ConsoleColor foregroundColor, IEnumerable extensions) : base(foregroundColor) { 58 | // The benefit of using a hashset is deduplication of entries and fast lookups 59 | mExtensions = new HashSet(from extension in extensions 60 | // FileSystemInfo.Extension includes a leading . if a file has an extension, 61 | // otherwise the Extension is an empty string; format our HashSet accordingly. 62 | let ext = string.IsNullOrEmpty(extension) ? "" : $".{extension}" 63 | select ext); 64 | } 65 | 66 | public override bool IsMatch(FileSystemInfo fs) { 67 | return (fs.Attributes & FileAttributes.Directory) == 0 && mExtensions.Contains(fs.Extension, StringComparer.CurrentCultureIgnoreCase); 68 | } 69 | 70 | public override object GetMatchData() { 71 | // reformat extension strings back to the input format (i.e. remove the leading .) 72 | return mExtensions.Select(ext => string.IsNullOrEmpty(ext) ? "" : ext.Substring(1)).ToArray(); 73 | } 74 | } 75 | 76 | 77 | /// 78 | /// Output color matcher that matches on file/directory attributes. 79 | /// 80 | /// Multiple attributes can be specified by ORing them together. 81 | /// 82 | internal class FileAttributeMatch : FileSystemInfoMatch { 83 | readonly FileAttributes mFileAttributes; 84 | 85 | public FileAttributeMatch(ConsoleColor consoleColor, FileAttributes fileAttributes) : base(consoleColor) { 86 | mFileAttributes = fileAttributes; 87 | } 88 | 89 | public override bool IsMatch(FileSystemInfo fs) { 90 | return (fs.Attributes & mFileAttributes) != 0; 91 | } 92 | 93 | public override object GetMatchData() { 94 | return mFileAttributes; 95 | } 96 | } 97 | 98 | 99 | /// 100 | /// Output color matcher that matches on file/directory name regular expression match. 101 | /// 102 | /// Since regular expressions can be instantiated directly in PS, users are free to specify 103 | /// any regex options when defining the matching expression. 104 | /// 105 | internal class FileRegexNameMatch : FileSystemInfoMatch { 106 | readonly Regex mNameRegex; 107 | 108 | public FileRegexNameMatch(ConsoleColor consoleColor, Regex nameRegex) : base(consoleColor) { 109 | mNameRegex = nameRegex; 110 | } 111 | 112 | public override bool IsMatch(FileSystemInfo fs) { 113 | return mNameRegex.IsMatch(fs.Name); 114 | } 115 | 116 | public override object GetMatchData() { 117 | // clone the regex 118 | return new Regex(mNameRegex.ToString(), mNameRegex.Options); 119 | } 120 | } 121 | 122 | 123 | /// 124 | /// Output color matcher that matches on PS script return bool value. 125 | /// 126 | /// The match script must accept exactly one parameter of FileSystemInfo type and return a single bool value. 127 | /// 128 | internal class FileScriptMatch : FileSystemInfoMatch { 129 | readonly ScriptBlock mMatchScript; 130 | 131 | public FileScriptMatch(ConsoleColor consoleColor, ScriptBlock matchScript) : base(consoleColor) { 132 | ScriptBlockAst scriptBlockAst = (ScriptBlockAst)matchScript.Ast; 133 | if (scriptBlockAst.ParamBlock.Parameters.Count != 1) throw new ArgumentException("Match script blocks must accept exactly one parameter of FileInfo or DirectoryInfo type."); 134 | 135 | mMatchScript = matchScript; 136 | } 137 | 138 | public override bool IsMatch(FileSystemInfo fs) { 139 | Collection result = mMatchScript.Invoke(fs); 140 | if (result.Count != 1 || !(result[0].BaseObject is bool)) throw new ArgumentException("Match scripts must return a single true/false result."); 141 | return (bool)result[0].BaseObject; 142 | } 143 | 144 | public override object GetMatchData() { 145 | // clone the script 146 | return ScriptBlock.Create(mMatchScript.Ast.ToString()); 147 | } 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /AnsiColorOut/Interfaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Bozho.PowerShell { 8 | 9 | /// 10 | /// Base interface for color matches. When trying to match a target object 11 | /// to a color, the module will iterate through a collection of matches for 12 | /// the target object's type and use the first match that returns true. 13 | /// 14 | public interface IColorMatch { 15 | /// 16 | /// The matching method. Implementing classes define a matching condition 17 | /// (e.g. file's extension, name regexp, process' priority). 18 | /// 19 | /// The condition is then use to determine if a target object matches 20 | /// the condition. 21 | /// 22 | /// Target object for matching 23 | /// True if the object matches the condition. False otherwise. 24 | bool IsMatch(object target); 25 | 26 | /// 27 | /// The foreground console color associated with the match. When the module 28 | /// matches a target object, this color will be use to format console output. 29 | /// 30 | ConsoleColor ForegroundColor { get; } 31 | } 32 | 33 | 34 | /// 35 | /// Strongly typed IColorMatch interface. Used internally by matchers. 36 | /// 37 | /// Target object's type. 38 | public interface IColorMatch : IColorMatch { 39 | /// 40 | /// Strongly typed version of IsMatch method. 41 | /// 42 | /// Target object for matching 43 | /// True if the object matches the condition. False otherwise. 44 | bool IsMatch(TTarget target); 45 | 46 | /// 47 | /// Returns a clone of match data (e.g. a list of file extensions used for matching). 48 | /// This method is used by Get-XXXXColors to retrieve current settings. 49 | /// 50 | /// It is important for implementing classes to return a deep clone of the data, 51 | /// in order to prevent modification of reference-typed data. 52 | /// 53 | /// 54 | object GetMatchData(); 55 | } 56 | 57 | 58 | /// 59 | /// Base interface for color matchers. When trying to match a target object 60 | /// to a color, the module will call this method to attempt to find a match for 61 | /// the target object. 62 | /// 63 | public interface IColorMatcher { 64 | /// 65 | /// The method will attempt to find a match matching the target object, using 66 | /// a collection of stored matches (using IColorMatch<TTarget/^>.IsMatch()) 67 | /// 68 | /// Target object for matching 69 | /// Matching IColorMatch, or null if none was found. 70 | IColorMatch GetMatch(object target); 71 | 72 | } 73 | 74 | 75 | /// 76 | /// Strongly type IColorMatcher interface. 77 | /// 78 | /// Target object's type. 79 | public interface IColorMatcher : IColorMatcher { 80 | /// 81 | /// Strongly typed GetMatch method. 82 | /// 83 | /// 84 | /// IColorMatch matching the target object. Null if no match was found. 85 | IColorMatch GetMatch(TTarget target); 86 | 87 | /// 88 | /// Sets matches for the matcher. 89 | /// 90 | void SetMatches(IEnumerable> matches); 91 | 92 | /// 93 | /// Gets the matches. 94 | /// 95 | IEnumerable> GetMatches(); 96 | 97 | /// 98 | /// A factory method for matches. Implementing classes for a target type will 99 | /// create instances of its subclasses based on the colorMatch type (and possibly 100 | /// other conditions) 101 | /// 102 | IColorMatch CreateMatch(ConsoleColor foregroundColor, object colorMatch); 103 | } 104 | 105 | 106 | /// 107 | /// Color matcher manager interface. The manager allows registering matchers, as well as 108 | /// retrieving them based on the target object type. 109 | /// 110 | public interface IColorMatcherManager { 111 | /// 112 | /// Retrieves a matcher based on the target object type. Throws if type is not found. 113 | /// 114 | IColorMatcher GetMatcher(Type type); 115 | 116 | /// 117 | /// Tries to retrieve a matcher based on the target type. 118 | /// 119 | bool TryGetMatcher(Type type, out IColorMatcher matcher); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /AnsiColorOut/ProcessMatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | 6 | namespace Bozho.PowerShell { 7 | 8 | /// 9 | /// Color matcher for System.Diagnostics.Process targets. 10 | /// 11 | public class ProcessMatcher : ColorMatcher { 12 | public override IColorMatch CreateMatch(ConsoleColor foregroundColor, object colorMatch) { 13 | Type colorMatchType = colorMatch.GetType(); 14 | 15 | if (colorMatch is ProcessPriorityClass) return new ProcessPriorityMatch(foregroundColor, (ProcessPriorityClass)colorMatch); 16 | 17 | if (colorMatchType.IsAssignableFrom(typeof(string))) return new ProcessPriorityMatch(foregroundColor, (ProcessPriorityClass)Enum.Parse(typeof(ProcessPriorityClass), (string)colorMatch, true)); 18 | 19 | throw new ArgumentException("Unsupported process color match type!", nameof(colorMatch)); 20 | } 21 | } 22 | 23 | 24 | /// 25 | /// A base class for System.Diagnostics.Process target matches. 26 | /// 27 | public abstract class ProcessMatch : IColorMatch { 28 | protected ProcessMatch(ConsoleColor foregroundColor) { ForegroundColor = foregroundColor; } 29 | 30 | public ConsoleColor ForegroundColor { get; } 31 | 32 | public abstract bool IsMatch(Process target); 33 | public abstract object GetMatchData(); 34 | 35 | bool IColorMatch.IsMatch(object target) { return IsMatch((Process)target);} 36 | } 37 | 38 | 39 | /// 40 | /// Output color match that matches on process priority 41 | /// 42 | internal class ProcessPriorityMatch : ProcessMatch { 43 | 44 | static readonly Dictionary sPriorityMap; 45 | 46 | /// 47 | /// It would appear that Process.PriorityClass property is not always readable. We'll map 48 | /// Process.BasePriority values the best we can and match on those. 49 | /// 50 | static ProcessPriorityMatch() { 51 | sPriorityMap = new Dictionary { 52 | {ProcessPriorityClass.Idle, 4}, 53 | {ProcessPriorityClass.BelowNormal, 6}, 54 | {ProcessPriorityClass.Normal, 8}, 55 | {ProcessPriorityClass.AboveNormal, 10}, 56 | {ProcessPriorityClass.High, 13}, 57 | {ProcessPriorityClass.RealTime, 24} 58 | }; 59 | } 60 | 61 | readonly int mBasePriority; 62 | 63 | public ProcessPriorityMatch(ConsoleColor consoleColor, ProcessPriorityClass priorityClass) : base(consoleColor) { 64 | mBasePriority = sPriorityMap[priorityClass]; 65 | } 66 | 67 | public override bool IsMatch(Process process) { return process.BasePriority == mBasePriority; } 68 | 69 | public override object GetMatchData() { return sPriorityMap.Where(p => p.Value == mBasePriority).Select(p => p.Key).First(); } 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /AnsiColorOut/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AnsiColorOut")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AnsiColorOut")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("86074f90-6cbe-43cf-a9da-5289f1bbebb0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.1.0.0")] 36 | [assembly: AssemblyFileVersion("0.1.0.0")] 37 | -------------------------------------------------------------------------------- /AnsiColorOut/SampleProfile.ps1: -------------------------------------------------------------------------------- 1 | 2 | $fileSystemColors = @( 3 | #@{ 4 | # Match = { param($f) $f.PSIsContainer }; 5 | # Color = [System.ConsoleColor]::Gray 6 | #}, 7 | @{ 8 | Match = [System.IO.FileAttributes]::Directory; 9 | Color = [System.ConsoleColor]::Gray 10 | }, 11 | # archive/compressed 12 | @{ 13 | Match = @("7z", "arj", "bz", "bz2", "cab", "gz", "iso", "lha", "lzh", "lzma", "rar", "tar", "taz", "tgz", "tbz2", "uu", "z", "zip"); 14 | Color = [System.ConsoleColor]::Yellow 15 | }, 16 | # executables/scripts 17 | @{ 18 | Match = @("bat", "btm", "cmd", "com", "cpl", "exe", "lnk", "msi", "pl", "ps1", "psm1", "psd1", "py", "pyw", "vbs", "ws", "wsf"); 19 | Color = [System.ConsoleColor]::Red 20 | }, 21 | # libraries, fonts, data files, etc. 22 | @{ 23 | Match = @("ax", "cpl", "dat", "dll", "drv", "fnt", "fon", "fot", "ttf", "sys", "vxd", "386", "hdl", "fdl", "ldl"); 24 | Color = [System.ConsoleColor]::DarkRed 25 | }, 26 | # source code and related 27 | @{ 28 | Match = @("asm", "bas", "c", "cpp", "cs", "def", "h", "idl", "mak", "pas", "rc"); 29 | Color = [System.ConsoleColor]::Magenta 30 | }, 31 | # text files/documents/help 32 | @{ 33 | Match = @("1st", "ans", "asc", "chm", "csv", "doc", "docx", "hlp", "lst", "man", "md", "me", "pdf", "prn", "ps", "txt", "wri", "xls", "xlsx"); 34 | Color = [System.ConsoleColor]::Blue 35 | }, 36 | # audio files 37 | @{ 38 | Match = @("cda", "flac", "mid", "mod", "mp3", "wav", "ogg", "s3m", "wav", "xm"); 39 | Color = [System.ConsoleColor]::Cyan 40 | }, 41 | # images/video 42 | @{ 43 | Match = @("ani", "asf", "asx", "avi", "bmp", "cur", "dng", "flv", "gif", "hdr", "ico", "iff", "jpeg", "jpg", "lbm", "mkv", "mov", "mp4", "mpeg", "mpg", "orf", "pcd", "pcx", "pic", "png", "raw", "rle", "rm", "tga", "tif", "tiff", "wmv"); 44 | Color = [System.ConsoleColor]::DarkCyan 45 | }, 46 | # "web" files 47 | @{ 48 | Match = @("asax", "asp", "aspx", "htm", "html", "mht", "php", "xml", "xsl"); 49 | Color = [System.ConsoleColor]::DarkYellow 50 | }, 51 | # config and similar files 52 | @{ 53 | Match = @("cfg", "conf", "ctl", "dos", "grp", "ini", "inf", "pif", "reg"); 54 | Color = [System.ConsoleColor]::Green 55 | }, 56 | # log/output files 57 | @{ 58 | Match = @("log", "err", "out"); 59 | Color = [System.ConsoleColor]::DarkGreen 60 | }, 61 | # temporary/intermediate files 62 | @{ 63 | Match = @("bak", "bsc", "exp", "idb", "ilk", "tmp"); 64 | Color = [System.ConsoleColor]::DarkGray 65 | }, 66 | @{ 67 | Match = [regex] "^\..*"; 68 | Color = [System.ConsoleColor]::DarkGray 69 | } 70 | ) 71 | 72 | 73 | Set-FileSystemColors -Colors $fileSystemColors 74 | 75 | 76 | $processColors = @( 77 | @{ 78 | Match = "Idle" 79 | Color = [System.ConsoleColor]::DarkMagenta 80 | } 81 | @{ 82 | Match = "BelowNormal" 83 | Color = [System.ConsoleColor]::DarkCyan 84 | } 85 | @{ 86 | Match = "Normal" 87 | Color = [System.ConsoleColor]::White 88 | } 89 | @{ 90 | Match = "AboveNormal" 91 | Color = [System.ConsoleColor]::Green 92 | } 93 | @{ 94 | Match = "High" 95 | Color = [System.ConsoleColor]::Yellow 96 | } 97 | @{ 98 | Match = "RealTime" 99 | Color = [System.ConsoleColor]::Red 100 | } 101 | ) 102 | 103 | Set-ProcessColors -Colors $processColors 104 | 105 | function d { 106 | 107 | $totalFileSize = 0 108 | $fileCount = 0 109 | $directoryCount = 0 110 | Get-ChildItem @args -Force | 111 | % { 112 | if ($_.PSIsContainer) { 113 | ++$directoryCount 114 | } 115 | else { 116 | ++$fileCount; 117 | $totalFileSize += $_.Length; 118 | } 119 | $_ 120 | } | 121 | Format-Custom -View ansi 122 | #| less -rEX 123 | 124 | Write-Host ([String]::Format("{0,20:N0} bytes in {1} files and {2} dirs`n", $totalFileSize, $fileCount, $directoryCount)) 125 | } 126 | 127 | -------------------------------------------------------------------------------- /AnsiColorOut/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Bozho.PowerShell { 5 | 6 | /// 7 | /// Type type extension methdos. 8 | /// 9 | public static class TypeExtensions { 10 | /// 11 | /// Checks whether a type is assignable to an open generic type. 12 | /// 13 | public static bool IsAssignableToGenericType(this Type type, Type openGenericType) { 14 | if(!openGenericType.IsGenericType) throw new ArgumentException("Not a generic type", nameof(openGenericType)); 15 | while(type != null) { 16 | if(type.IsGenericType && type.GetGenericTypeDefinition() == openGenericType) return true; 17 | if(type.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == openGenericType)) return true; 18 | type = type.BaseType; 19 | } 20 | 21 | return false; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AnsiColorOut/formats/FileSystemInfo.format.ps1xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | FileSystemTypes 6 | 7 | System.IO.DirectoryInfo 8 | System.IO.FileInfo 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | FileSystemTypes-GroupingFormat 17 | 18 | 19 | 20 | 21 | 22 | 4 23 | 24 | 25 | 26 | 27 | $_.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "") 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | ansi 46 | 47 | FileSystemTypes 48 | 49 | 50 | PSParentPath 51 | FileSystemTypes-GroupingFormat 52 | 53 | 54 | 55 | 56 | 57 | 58 | 19 59 | right 60 | 61 | 62 | 63 | 16 64 | right 65 | 66 | 67 | 68 | 15 69 | right 70 | 71 | 72 | 73 | left 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | [String]::Format("{0}{1}", [AnsiColorOut]::GetFileInfoAnsiString($_), $_.LastWriteTime.ToString("G")) 83 | 84 | 85 | 86 | 87 | if($_.Attributes -band [IO.FileAttributes]::ReparsePoint) { 88 | $length = "<JUNCTION> " 89 | } 90 | elseif($_.PSIsContainer) { 91 | $length = "<DIR> " 92 | } 93 | else { 94 | $length = [String]::Format("{0:N0}", $_.Length) 95 | } 96 | $length 97 | 98 | 99 | 100 | ExtendedMode 101 | 102 | 103 | 104 | if($_.Attributes -band [IO.FileAttributes]::ReparsePoint) { 105 | if($_.Target -ne $null) { 106 | $junctionTarget = [String]::Format(" [{0}]", $_.Target[0]) 107 | } 108 | # PSCX is used, we have rich reparse point info 109 | elseif($_.ReparsePoint -ne $null) { 110 | $junctionTarget = [String]::Format(" [{0}]", $_.ReparsePoint.Target) 111 | } 112 | } 113 | [String]::Format("{0}{1}{2}", $_.Name, $junctionTarget, [AnsiColorOut]::ColorReset) 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | ansi 126 | 127 | FileSystemTypes 128 | 129 | 130 | PSParentPath 131 | FileSystemTypes-GroupingFormat 132 | 133 | 134 | 135 | 136 | 137 | [String]::Format("{0}{1}{2}", [AnsiColorOut]::GetFileInfoAnsiString($_), $_.Name, [AnsiColorOut]::ColorReset) 138 | 139 | 140 | 141 | 142 | System.IO.DirectoryInfo 143 | 144 | 145 | [String]::Format("{0}[{1}]{2}", [AnsiColorOut]::GetFileInfoAnsiString($_), $_.Name, [AnsiColorOut]::ColorReset) 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | ansi 156 | 157 | FileSystemTypes 158 | 159 | 160 | PSParentPath 161 | FileSystemTypes-GroupingFormat 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | if($_.Attributes -band [IO.FileAttributes]::ReparsePoint) { 170 | $length = "<JUNCTION> " 171 | if($_.Target -ne $null) { 172 | $junctionTarget = [String]::Format(" [{0}]", $_.Target[0]) 173 | } 174 | # PSCX is used, we have rich reparse point info 175 | elseif($_.ReparsePoint -ne $null) { 176 | $junctionTarget = [String]::Format(" [{0}]", $_.ReparsePoint.Target) 177 | } 178 | } 179 | elseif($_.PSIsContainer) { 180 | $length = "<DIR> " 181 | } 182 | else { 183 | $length = [String]::Format("{0:N0}", $_.Length) 184 | } 185 | [String]::Format("{0}{1, 10}{2, 7}{3, 16} {4} {5}{6}{7}", [AnsiColorOut]::GetFileInfoAnsiString($_), $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t"), $length, $_.ExtendedMode, $_.Name, $junctionTarget, [AnsiColorOut]::ColorReset) 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /AnsiColorOut/formats/Process.format.ps1xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ansi 12 | 13 | System.Diagnostics.Process 14 | 15 | 16 | 17 | 18 | 19 | 7 20 | right 21 | 22 | 23 | 24 | 7 25 | right 26 | 27 | 28 | 29 | 8 30 | right 31 | 32 | 33 | 34 | 10 35 | right 36 | 37 | 38 | 39 | 10 40 | right 41 | 42 | 43 | 44 | 8 45 | right 46 | 47 | 48 | 6 49 | right 50 | 51 | 52 | 3 53 | right 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | "$([AnsiColorOut]::GetProcessAnsiString($_))$($_.HandleCount)" 64 | 65 | 66 | [long]($_.NPM / 1024) 67 | 68 | 69 | [long]($_.PM / 1024) 70 | 71 | 72 | [long]($_.WS / 1024) 73 | 74 | 75 | [long]($_.VM / 1048576) 76 | 77 | 78 | 79 | if ($_.CPU -ne $()) { $_.CPU.ToString("N") } 80 | 81 | 82 | 83 | Id 84 | 85 | 86 | SI 87 | 88 | 89 | "$($_.ProcessName)$([AnsiColorOut]::ColorReset)" 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | ansi 101 | 102 | System.Diagnostics.Process#IncludeUserName 103 | 104 | 105 | 106 | 107 | 108 | 7 109 | right 110 | 111 | 112 | 113 | 10 114 | right 115 | 116 | 117 | 118 | 10 119 | right 120 | 121 | 122 | 123 | 8 124 | right 125 | 126 | 127 | 6 128 | right 129 | 130 | 131 | 17 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | "$([AnsiColorOut]::GetProcessAnsiString($_))$($_.HandleCount)" 142 | 143 | 144 | [long]($_.WS / 1024) 145 | 146 | 147 | [long]($_.VM / 1048576) 148 | 149 | 150 | 151 | if ($_.CPU -ne $()) { $_.CPU.ToString("N") } 152 | 153 | 154 | 155 | Id 156 | 157 | 158 | UserName 159 | 160 | 161 | "$($_.ProcessName)$([AnsiColorOut]::ColorReset)" 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /AnsiColorOut/help/en-US/Bozho.PowerShell.AnsiColorOut.dll-Help.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Get-FileInfoAttributePattern 7 | Get 8 | FileInfoAttributePattern 9 | 10 | Returns currently configured attribute string pattern for file and directory custom property, ExtendedMode. 11 | 12 | 13 | 14 | Returns currently configured attribute string pattern for file and directory custom property, ExtendedMode. 15 | Additionally, if the -ShowAll parameter is used, the cmdled will print out all supported attributes and their names. 16 | Currently supported attributes: 17 | A - Archive 18 | C - Compressed 19 | D - Directory 20 | E - Encrypted 21 | H - Hidden 22 | G - IntegrityStream 23 | N - Normal 24 | B - NoScrubData 25 | I - NotContentIndexed 26 | O - Offline 27 | R - ReadOnly 28 | J - ReparsePoint 29 | P - SparseFile 30 | S - System 31 | T - Temporary 32 | 33 | 34 | 35 | 36 | Get-FileInfoAttributePattern 37 | 38 | 39 | ShowAll 40 | 41 | If specified, the cmdled will print out all supported attributes and their names. 42 | 43 | SwitchParameter 44 | 45 | System.Management.Automation.SwitchParameter 46 | 47 | 48 | False 49 | 50 | 51 | 52 | 53 | 54 | 55 | ShowAll 56 | 57 | If specified, the cmdled will print out all supported attributes and their names. 58 | 59 | SwitchParameter 60 | 61 | System.Management.Automation.SwitchParameter 62 | 63 | 64 | False 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Set-FileInfoAttributePattern 74 | Set 75 | FileInfoAttributePattern 76 | 77 | Configures attribute string pattern for file and directory custom property, ExtendedMode. 78 | 79 | 80 | 81 | Configures attribute string pattern for file and directory custom property, ExtendedMode. It can also be used to reset current pattern to the default one. 82 | 83 | Currently supported attributes: 84 | A - Archive 85 | C - Compressed 86 | D - Directory 87 | E - Encrypted 88 | H - Hidden 89 | G - IntegrityStream 90 | N - Normal 91 | B - NoScrubData 92 | I - NotContentIndexed 93 | O - Offline 94 | R - ReadOnly 95 | J - ReparsePoint 96 | P - SparseFile 97 | S - System 98 | T - Temporary 99 | 100 | 101 | 102 | 103 | 104 | Set-FileInfoAttributePattern 105 | 106 | 107 | AttributePattern 108 | 109 | Used to specify custom attribute pattern for ExtendedMode property 110 | 111 | string 112 | 113 | System.String 114 | 115 | 116 | 117 | 118 | 119 | DefaultPattern 120 | 121 | Resets the ExtendedMode attribute pattern to the default one. 122 | 123 | SwitchParameter 124 | 125 | System.Management.Automation.SwitchParameter 126 | 127 | 128 | False 129 | 130 | 131 | 132 | 133 | 134 | 135 | AttributePattern 136 | 137 | Used to specify custom attribute pattern for ExtendedMode property 138 | 139 | string 140 | 141 | System.String 142 | 143 | 144 | 145 | 146 | 147 | DefaultPattern 148 | 149 | Resets the ExtendedMode attribute pattern to the default one. 150 | 151 | SwitchParameter 152 | 153 | System.Management.Automation.SwitchParameter 154 | 155 | 156 | False 157 | 158 | 159 | 160 | 161 | 162 | 163 | ---------- EXAMPLE 1 ---------- 164 | Set-FileInfoAttributePattern -AttributePattern DARHS 165 | 166 | Setting a custom parameter to indicated directories, archive, read=only, hidden and system attributes 167 | 168 | 169 | 170 | ---------- EXAMPLE 2 ---------- 171 | Set-FileInfoAttributePattern -DefaultPattern 172 | 173 | Setting the default pattern 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | Get-FileSystemColors 182 | Get 183 | FileSystemColors 184 | 185 | Gets a copy of currently configured color mappings for file and directory output. 186 | 187 | 188 | 189 | This cmdlet will return a copy of currently configured color mappings for file and directory output. 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | Set-FileSystemColors 200 | Set 201 | FileSystemColors 202 | 203 | Configures color mappings for file and directory output. 204 | 205 | 206 | 207 | Use this cmdlet to configure color mappings for file and directory output. 208 | The input parameter is an array of hashtables. Each hashtable has two members: Match and Color. 209 | Match can be one of the following: 210 | * An array of strings, which are matched against extensions 211 | * A System.IO.FileAttributes (or a combination), which are matched against file/dir attributes 212 | * A regular expression, which is matched against file/dir name(just the name, not the full path) 213 | * A script block with a single System.IO.FileSystemInfo parameter returning bool. 214 | When using Format-Custom to output files and directories (e.g. using Get-ChildItems | Format-Custom), matching items will have ANSI foreground color codes embedded in output strings. These codes can then be interpreted by ANSI-aware tools, like GNU less or AnsiCon. 215 | 216 | 217 | 218 | 219 | Set-FileSystemColors 220 | 221 | 222 | Colors 223 | 224 | An array of hashtables used for matching files and directories. Please see description for details and examples. 225 | 226 | object[] 227 | 228 | System.Object[] 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | Colors 238 | 239 | An array of hashtables used for matching files and directories. Please see description for details and examples. 240 | 241 | object[] 242 | 243 | System.Object[] 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | ---------- EXAMPLE 1 ---------- 253 | $fileSystemColors = @( 254 | # this entry will match directories 255 | @{ 256 | Match = [System.IO.FileAttributes]::Directory; 257 | Color = [System.ConsoleColor]::Gray 258 | }, 259 | # alternatively, we could've used a script block to match directories 260 | @{ 261 | Match = { param($f) $f.PSIsContainer }; 262 | Color = [System.ConsoleColor]::Gray 263 | }, 264 | # this entry will match files with extensions log, err or out 265 | # (it won't get a chance to match directories, since they'll 266 | # all be matched by the first entry) 267 | @{ 268 | Match = @("log", "err", "out"); 269 | Color = [System.ConsoleColor]::DarkGreen 270 | }, 271 | # this entry will match all files with a leading . in the name 272 | @{ 273 | Match = [regex] "^\..*"; 274 | Color = [System.ConsoleColor]::DarkGray 275 | } 276 | ) 277 | 278 | Set-FileSystemColors -Colors $fileSystemColors 279 | 280 | A simple example demonstrating supported matchers 281 | 282 | 283 | 284 | 285 | -------------------------------------------------------------------------------- /AnsiColorOut/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /AnsiColorOut/types/FileSystemInfo.type.ps1xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | System.IO.FileSystemInfo 5 | 6 | 7 | ExtendedMode 8 | 9 | Bozho.PowerShell.FileSystemInfoExtensions 10 | GetExtendedMode 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## Unreleased changes 4 | 5 | * File extension matching is now case-insensitive. 6 | * Added CHANGELOG.md 7 | 8 | ## 0.1.0.0 9 | 10 | * Initial release. 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AnsiColorOut 2 | 3 | ## Introduction 4 | 5 | AnsiColorOut is an attempt at a different approach to coloring PowerShell output. 6 | 7 | It uses custom formatting files used with `Format-XXX` cmdlets to write output with embedded ANSI 8 | color escape sequences and relies on PowerShell 5's built-in support for ANSI escape sequences, or 9 | external utilities, like GNU less or [AnsiCon](https://github.com/adoxa/ansicon) to interpret them. 10 | 11 | Currently, AnsiColorOut supports `FileInfo/DirectoryInfo` (e.g. `Get-ChildItem` output for drives) 12 | and `Process` (e.g. `Get-Process`) formatting. 13 | 14 | The module also expands `FileInfo` and `DirectoryInfo` types with the `ExtendedMode` property, 15 | which can show all suported file/directory attributes. `ExtendedMode` output format is 16 | configurable. 17 | 18 | 19 | ## Installation 20 | 21 | Install the module from the PowerShell [Gallery](https://www.powershellgallery.com/packages/AnsiColorOut): 22 | ``` 23 | Install-Module -Name AnsiColorOut 24 | ``` 25 | 26 | Download the file from the releases page and unzip the zip file to your modules directory. 27 | 28 | 29 | ## Changelog 30 | 31 | You can find full change log [here](./CHANGELOG.md). 32 | 33 | 34 | ## Configuration 35 | 36 | ### FileInfo/DirInfo 37 | 38 | File/dir color output is configured using the `Set-FileSystemColors` cmdlet: 39 | 40 | ~~~ 41 | Set-FileSystemColors -Colors $fileSystemColors 42 | ~~~ 43 | 44 | The input parameter is an array of Hashtables: 45 | ~~~ 46 | $fileSystemColors = @( 47 | @{ 48 | Match = ...; 49 | Color = [System.ConsoleColor]::Gray 50 | }, 51 | ... 52 | ) 53 | ~~~ 54 | 55 | `Match` is an object used to match a file/dir to a console color. The first matching entry is used 56 | to determine the text color. 57 | 58 | `Match` can be: 59 | 60 | * An array of file extension strings (**without** leading `.`) - only matched against files 61 | * A `System.IO.FileAttributes` (or a combination), which are matched against file/dir attributes 62 | * A regular expression, which is matched against file/dir name (just the name, not the full path) 63 | * A script block with a single `System.IO.FileSystemInfo` parameter returning `bool`. 64 | 65 | For example: 66 | 67 | ~~~ 68 | $fileSystemColors = @( 69 | # this entry will match directories 70 | @{ 71 | Match = [System.IO.FileAttributes]::Directory; 72 | Color = [System.ConsoleColor]::Gray 73 | }, 74 | # alternatively, we could've used a script block to match directories 75 | @{ 76 | Match = { param($f) $f.PSIsContainer }; 77 | Color = [System.ConsoleColor]::Gray 78 | }, 79 | # this entry will match files with extensions log, err or out 80 | @{ 81 | Match = @("log", "err", "out"); 82 | Color = [System.ConsoleColor]::DarkGreen 83 | }, 84 | # this entry will match all files with a leading . in the name 85 | @{ 86 | Match = [regex] "^\..*"; 87 | Color = [System.ConsoleColor]::DarkGray 88 | } 89 | ) 90 | ~~~ 91 | 92 | 93 | ### Process 94 | 95 | Process color output is configured using the `Set-ProcessColors` cmdlet: 96 | 97 | ~~~ 98 | Set-ProcessColors -Colors $processColors 99 | ~~~ 100 | 101 | The input parameter is an array of Hashtables: 102 | ~~~ 103 | $processColors = @( 104 | @{ 105 | Match = ...; 106 | Color = [System.ConsoleColor]::Gray 107 | }, 108 | ... 109 | ) 110 | ~~~ 111 | 112 | `Match` is an object used to match a process to a console color. The first matching entry is used 113 | to determine the text color. 114 | 115 | `Match` can be: 116 | 117 | * One of the `[ProcessPriorityClass]` enum values 118 | * A string corresponding to one of the `[ProcessPriorityClass]` enum value names 119 | 120 | For example: 121 | 122 | ~~~ 123 | $processColors = @( 124 | @{ 125 | Match = [System.Diagnostics.ProcessPriorityClass]::Idle 126 | Color = [System.ConsoleColor]::DarkMagenta 127 | @{ 128 | Match = "BelowNormal" 129 | Color = [System.ConsoleColor]::DarkCyan 130 | } 131 | @{ 132 | Match = "Normal" 133 | Color = [System.ConsoleColor]::White 134 | } 135 | @{ 136 | Match = "AboveNormal" 137 | Color = [System.ConsoleColor]::Green 138 | } 139 | @{ 140 | Match = "High" 141 | Color = [System.ConsoleColor]::Yellow 142 | } 143 | @{ 144 | Match = "RealTime" 145 | Color = [System.ConsoleColor]::Red 146 | } 147 | ) 148 | ~~~ 149 | 150 | For a sample configurations, please look at the `SampleProfile.ps1` file. 151 | 152 | 153 | ## Custom formatting files 154 | 155 | The module is distributed with two custom formatting files: `FileSystem.format.ps1xml` and 156 | `Process.format.ps1xml`. They define custom views for formatting output. 157 | 158 | The files are automatically loaded when importing the module. The views are used in appropriate 159 | Format-XXX cmdlets. 160 | 161 | ### Files/directories 162 | 163 | `FileSystem.format.ps1xml` contains table, wide and custom views, all named "ansi". 164 | 165 | `Get-ChildItem C:\Windows | Format-Table -View ansi` 166 | `Get-ChildItem C:\Windows | Format-Wide -View ansi` 167 | `Get-ChildItem C:\Windows | Format-Custom -View ansi` 168 | 169 | 170 | ### Process 171 | 172 | `Process.format.ps1xml` contains **ADD VIEWS HERE** 173 | 174 | 175 | ## Known issues and limitations 176 | 177 | The color code strings may get line-wrapped if the console window is not wide enough, which will 178 | result in corrupt output. 179 | 180 | If you are piping Format-XXX output into something like `less -rEX`, custom table output may get 181 | corrupt, because custom formats print out ANSI escape sequence strings, which are not interpreted 182 | by PowerShell, but passed on to `less`. 183 | 184 | It is recommended to use custom views in those cases. 185 | 186 | At the time of this writing, it looks like Cygwin programs (e.g. less.exe) clear 187 | ```ENABLE_VIRTUAL_TERMINAL_PROCESSING``` standard output flag when they run, which disables 188 | ANSI escape sequence processing in PowerShell. This module provides a helper method to re-enable 189 | the flag. 190 | 191 | If you're using Cygwin utilities from PowerShell, you might want to add the following call to 192 | your custom prompt function (which will ensure that the flag is set whenever the prompt is 193 | rendered): 194 | 195 | ```[Bozho.PowerShell.Console]::EnableVirtualTerminalProcessing()``` 196 | 197 | 198 | 199 | ## License 200 | 201 | The MIT License (MIT) 202 | 203 | Copyright (c) 2016-2017 Marko Bozikovic 204 | 205 | Permission is hereby granted, free of charge, to any person obtaining a copy of 206 | this software and associated documentation files (the "Software"), to deal in 207 | the Software without restriction, including without limitation the rights to 208 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 209 | the Software, and to permit persons to whom the Software is furnished to do so, 210 | subject to the following conditions: 211 | 212 | The above copyright notice and this permission notice shall be included in all 213 | copies or substantial portions of the Software. 214 | 215 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 216 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 217 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 218 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 219 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 220 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 221 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Marko Bozikovic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /scripts/ansicolorout.msbuild.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Release 8 | 9 | .. 10 | False 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | $(SolutionRoot)\build\output 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 38 | 39 | 40 | 41 | 42 | 47 | 48 | 49 | 50 | 51 | 52 | %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe 53 | 54 | 55 | 56 | 57 | %(Project.Filename) 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | AnsiColorOut-$(ModuleVersion) 76 | $(BuildName).zip 77 | 78 | $(SolutionRoot)\build\zipped\ 79 | 80 | $(ZipFilePath)$(ZipFileName) 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /tools/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozho/AnsiColorOut/88ff1bf9f5be84e5bd44a1ed8c7467885bdb052e/tools/nuget.exe --------------------------------------------------------------------------------