eliziumnet / krayola Goto Github PK
View Code? Open in Web Editor NEWColourful console writing with Powershell
License: MIT License
Colourful console writing with Powershell
License: MIT License
Add new function Get-KraylaTheme that gets the theme from the environment. This will allow different applicatins to get consistent display behaviour
branch: get-krayolatheme
When using the krayon from a command (as oppsed to a class method), the returned krayon instance (fluent style) can be a pain, because we always have to remember to assign the result to $null if we're not using it. The end function will do this for us, or at least relieve us from having to do that assignment.
The Theme parameter table does not match up with the parameter list in Write-RawPairsInColour. That's not the problem in itself, but the 2 lists are not the same, however, the documentation is misleading by simply deferring back to that table as if they were all the same. The following parameters need a comment (because they are not in the Theme table)
New command that will simply re-render a .scribble file via Krayon.scribble. This will just reproduce the output that was captured inside the file. It's almost as if you were running the command again that produced this output, without actually doing so; hence Replay.
This is for debugging and testing purposes.
Sometimes, we need to ensure that a structured string ceated does not change the actual text content of the pure string, particularly in test cases.
Make sure that all the themes that are stored inside the global KrayolThemes map are read only objects.
Make sure that we return a reference to the krayola theme, unless a new Switch (Clone) has been specified. A user might want to use a clone of the theme so they can make safe adjustments to a theme without affecting other clients.
If Scribble recieves a plain string (without any api call embedded), then the string is not rendered.
This is because of the problems with classes in PowerShell modules. The only reason why we don't have a problem in VSC with class references in files is because I already have Krayola installed on my machine and imported. In VSC powershell, the module has been imported so it can see the class definitions. However, these are the old class definitions which can't be modified after being defined in the same session. If somebody else checked out the repo without already having the module installed would see class reference erros in VSC.
So the best option would be to consolidate all the files into 1, bas work-around, but until class support in powershell has been improved, there is little else we can do.
Add the improvements applie to Loopz
How the fuck did this happen?
[+] C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Get-EnvironmentVariable.tests.ps1 557ms (73ms|381ms)
[-] Describe Get-KrayolaTheme failed
InvalidOperationException: Unable to remove the module 'Elizium.Krayola' because it is required by 'Elizium.Loopz'. Add the Force parameter to your command to remove the module.
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Get-KrayolaTheme.tests.ps1:5
Are you master of your domain? Yeah, Im still king of the county!
Are you master of your domain? Yeah, Im still lord of the manner!
This is affirmed text
This is key text
This is message text
This is meta text
This is value text
This is bold text
This is /italic/ text
This is s-t-r-i-k-e--t-h-r-u text
This is underlined text
"Album" => "Pungent Effulgent"
"Nine" => "Wreltch"
"Album" => "Pungent Effulgent"
"Artist" => "Ozric Tentacles"
"One" => "Disolution (The Clouds Disperse)"
"Two" => "0-1"
"Three" => "Phalarn Dawn"
"Four" => "04 - The Domes of G'Bal"
[-] Krayon.given: pair.and: pair created via New-Pair.should: write pair 21ms (20ms|1ms)
PSInvalidCastException: Cannot convert the "[Key: 'Five', Value: 'Shaping the Pelm', Affirm: 'True']" value of type "couplet" to type "couplet".
RuntimeException: Cannot convert the "[Key: 'Five', Value: 'Shaping the Pelm', Affirm: 'True']" value of type "couplet" to type "couplet".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:117
[-] Krayon.given: pair.and: pair created via kp alias.should: write pair 6ms (6ms|1ms)
PSInvalidCastException: Cannot convert the "[Key: 'Seven', Value: 'Kick Muck', Affirm: 'True']" value of type "couplet" to type "couplet".
RuntimeException: Cannot convert the "[Key: 'Seven', Value: 'Kick Muck', Affirm: 'True']" value of type "couplet" to type "couplet".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:129
["name" => "art vanderlay", "occupation" => "architect", "quip" => "i'm back baby, i'm back"]
Festivus for the rest of us // ["name" => "frank", "festivity" => "The airance of grievances"]
["one" => "(Dead But Dreaming)", "two" => "For her light", "three" => "At The Gates Of Silent Memory", "four" => "(Paradise Regained)", "five" => "Submission", "six" => "Sumerland (What Dreams May Come)"]
[-] Krayon.given: line.and: append to line.should: write line 10ms (9ms|1ms)
PSInvalidCastException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']; [Key: 'two', Value: 'Bango', Affirm: 'True']; [Key: 'three', Value: 'No Geography', Affirm: 'False']" value of type "line" to type "line".
RuntimeException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']; [Key: 'two', Value: 'Bango', Affirm: 'True']; [Key: 'three', Value: 'No Geography', Affirm: 'False']" value of type "line" to type "line".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:196
Fields Of The Nephilim, Love Under Will
I need to be alone today
Smother me or suffer me
Lay down I'll die today
*** Love under will //
!!! Love under will //
$$$ Love under will
Smother me or suffer me
Love Under Will //
When I'm gone wait here
Discover all of life's surprises
The Nephilim; Love Under Will // *The Winter Solstace
[🚀] ====== [ Children of the Damned ] ===
When I'm gone wait here
When I'm gone wait here
I'll send my child my last good smile
I'll love her 'til i
Then rest in peace can't you
If you pass through my soul today
[-] line.given: 2 equal lines.should: compare equal 11ms (11ms|1ms)
PSInvalidCastException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']; [Key: 'two', Value: 'Bango', Affirm: 'True']; [Key: 'three', Value: 'No Geography', Affirm: 'False']" value of type "line" to type "line".
RuntimeException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']; [Key: 'two', Value: 'Bango', Affirm: 'True']; [Key: 'three', Value: 'No Geography', Affirm: 'False']" value of type "line" to type "line".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:472
[-] line.given: 2 non equal lines.should: NOT compare equal 11ms (10ms|0ms)
PSInvalidCastException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']; [Key: 'two', Value: 'Bango', Affirm: 'True']; [Key: 'three', Value: 'No Geography', Affirm: 'False']" value of type "line" to type "line".
RuntimeException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']; [Key: 'two', Value: 'Bango', Affirm: 'True']; [Key: 'three', Value: 'No Geography', Affirm: 'False']" value of type "line" to type "line".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:493
[-] couplet.given: 2 equal couplets.should: compare equal 6ms (5ms|1ms)
PSInvalidCastException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']" value of type "couplet" to type "couplet".
RuntimeException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']" value of type "couplet" to type "couplet".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:521
[-] couplet.given: 2 non equal couplets.should: NOT compare equal 9ms (9ms|0ms)
PSInvalidCastException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']" value of type "couplet" to type "couplet".
RuntimeException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']" value of type "couplet" to type "couplet".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:533
[-] couplet.given: 2 non equal couplets.and: differs by case only.should: NOT compare equal 14ms (14ms|1ms)
PSInvalidCastException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']" value of type "couplet" to type "couplet".
RuntimeException: Cannot convert the "[Key: 'one', Value: 'Eve of Destruction', Affirm: 'False']" value of type "couplet" to type "couplet".
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Krayon.tests.ps1:543
[-] Split-KeyValuePairFormatter.Format is Key before Value.Given: minimal format.Should: return formatted string 21ms (20ms|0ms)
CommandNotFoundException: The term 'Split-KeyValuePairFormatter' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Split-KeyValuePairFormatter.tests.ps1:16
[-] Split-KeyValuePairFormatter.Format is Key before Value.Given: format with leading, mid and trailing tokens.Should: return formatted string 21ms (20ms|1ms)
CommandNotFoundException: The term 'Split-KeyValuePairFormatter' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Split-KeyValuePairFormatter.tests.ps1:34
[-] Split-KeyValuePairFormatter.Format is Value before Key.Given: minimal format.Should: return formatted string 26ms (25ms|1ms)
CommandNotFoundException: The term 'Split-KeyValuePairFormatter' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Split-KeyValuePairFormatter.tests.ps1:54
[-] Split-KeyValuePairFormatter.Format is Value before Key.Given: format with leading, mid and trailing tokens.Should: return formatted string 27ms (26ms|0ms)
CommandNotFoundException: The term 'Split-KeyValuePairFormatter' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at , C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Split-KeyValuePairFormatter.tests.ps1:72
[+] C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Write-ThemedPairsInColour.tests.ps1 803ms (286ms|447ms)
Tests completed in 4.96s
Tests Passed: 38, Failed: 21, Skipped: 1 NotRun: 0
BeforeAll \ AfterAll failed: 1
As an aid to the user, need to add a reminder about the dangers of sintgle item Powershell array, that needs the use of the prefixing comma operator to prevent unwanted deconstruction of the array.
Also, put in a tip about the use of the += operator instead of using the Add method on a fixed item array.
Tis is because the function sets thes the colour as 'red,'; ie it has a rogue comma inside the string.
When the module is imported, powershell is reporting the following errors:
At C:\Program Files\WindowsPowerShell\Modules\Elizium.Krayola\0.0.1\Public\themes.ps1:55 char:32
+ "OPEN" = "â—„â—„â—„ <";
+ ~~~~~~
Unexpected token 'â—„â—„' in expression or statement.
At C:\Program Files\WindowsPowerShell\Modules\Elizium.Krayola\0.0.1\Public\themes.ps1:55 char:32
+ "OPEN" = "â—„â—„â—„ <";
+ ~
The hash literal was incomplete.
At C:\Program Files\WindowsPowerShell\Modules\Elizium.Krayola\0.0.1\Public\themes.ps1:55 char:31
+ "OPEN" = "â—„â—„â—„ <";
+ ~
The hash literal was incomplete.
At C:\Program Files\WindowsPowerShell\Modules\Elizium.Krayola\0.0.1\Public\themes.ps1:55 char:39
+ "OPEN" = "â—„â—„â—„ <";
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\WindowsPowerShell\Modules\Elizium.Krayola\0.0.1\Public\themes.ps1:60 char:33
+ "MESSAGE-SUFFIX" = " // "
+ ~
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
However does not affect the functionality. Also, this only appears to happen when the module is is installed for all users in 'Program Files\WindowsPowerShell\Modules'. This was not observed, when the module is installed for the local user under their own personal ~\Documents location. Also, this has not been observed on mac.
The errors could be caused by the fact that the string are be defined by double quotes rather than single quotes, because it looks like PowerShell is trying to evaluate the contents of these strings when it shuld not.
To fix, replace the double quotes with the single quotes. The characters causing problems appear to be '>', '<' and '/'.
branch: fix-theme-double-quotes
[writer] as a class name is too generic and non specific. Krayon is very unique and therefore a better name in global scope
On final review of the module prior to it being published show there were a fe minor issues that need to be address:
This scenario results in an invalid operation being generated as a result of the internal parse:
[-] Show-AsTable.Krayon.Scribble.given: empty string.should: ignore without barfing 10ms (10ms|1ms)
MethodException: Cannot find an overload for "Text" and the argument count: "0".
at Scribble, C:\Program Files\PowerShell\Modules\Elizium.Krayola\1.0.2\Elizium.Krayola.psm1:1228
at <ScriptBlock>, C:\Users\Plastikfan\dev\github\PoSh\Loopz\Elizium.Loopz\Tests\Public\ui\Show-AsTable.tests.ps1:60
This is as a result of generating a 'Text' api operation without an arg which means its trying to inovke the Text method on krayon without a text arg, which is not supported.
Some source files are not named in the standard way, ie exactly reflecting the name of the function it contains.
branch: rename-files
Add as documented unit test examples
Set-Alias does not need to be called explicitly, we can just use the Alias decorator attribute on a function defintion
Write-ThemedPairsInColour contains non parameter variable names in capitalised from eg 'PairsToWriteInColour', should be 'pairsToWriteInColour'. Check this isnt happening elsewhere.
In the README, in the introduction, there is an incorrect reference to Write-Colour, which should be Write-InColour
Use Parameter validation where appropriate
branch: minor-non-fn
Copy the function from TerminalBuddy
this causes errors when trying to write in colour.
The following code in Krayon constructor cause error, because for some reason it is set to -1:
$this._defaultFgc = (Get-Host).ui.rawui.ForegroundColor;
$this._defaultBgc = (Get-Host).ui.rawui.BackgroundColor;
This appears to be a problem in PowerShell.
On mac:
λ $host.ui.RawUI.ForegroundColor
-1
λ (get-host).ui.rawui | Format-List -Property *
ForegroundColor : -1
BackgroundColor : -1
CursorPosition : 0,52
WindowPosition : 0,0
CursorSize : 100
BufferSize : 214,53
WindowSize : 214,53
MaxWindowSize : 214,53
MaxPhysicalWindowSize : 214,53
KeyAvailable : False
WindowTitle :
On windows:
λ (get-host).ui.rawui | Format-List -Property *
ForegroundColor : Gray
BackgroundColor : Black
CursorPosition : 0,59
WindowPosition : 0,0
CursorSize : 25
BufferSize : 213,60
WindowSize : 213,60
MaxWindowSize : 213,60
MaxPhysicalWindowSize : 1904,70
KeyAvailable : True
WindowTitle : Elizium.Krayola
https://devblogs.microsoft.com/scripting/psscriptanalyzer-deep-dive-part-1-of-4/
This one might be a good reference as a whole framework for building PowerShell modules: https://github.com/PoshCode/ModuleBuilder
conditional hi-light/lo-light
See: Virtual terminal Sequences
Currently, Krayon does not allow for styling text (bold/underline/italics), perhaps this can be achieved with VTS. This issue is simply a research item.
Sometimes, we just need a quick way to get a krayon without haing to assemble requirements ourselves. Get-Krayon will do this for us.
CopyFiles switch should be able to work independently from CreateDirs. currently, CopyFiles has not effect unless CreateDirs is also set. There is a useful usecase that requires this decoupling. If you want to mirror and directory tree, but in the destination tree, you only want to copy over some files that match a particluar filter (includes/excludes), then this won't work unless CreateDirs. If you also set CreateDirs, then this could result in empty directories in the destination, as a result of there being files that fail to pass the filter, but the directroy would be created anyway.
The much better way around this is to remove the need to also set the CreateDirs flag.
branch: feature/copyfiles-without-createdirs
Another way to write, would be to embed colour infomation inside text eg
"Something to say: {blue:-}, I've got chills, {red:-} and now I'm feeling hot".
Where the tokens inside {} are called Krayons and control the colour being rendered.
This functionality represents 'unstructured' writes.
If a critical function is using this module to produce output, it would be harmful for the process to be halted just becuase of a relatively un important display issue. The process should be allowed to run to completion, even if the display is not what is expected.
Perhap, we need to consult ErrorAction behaviour to make sure we take the correct action.
branch: fix-error-action
Related to EliziumNet/Loopz#105
Lots of lint warnings in README. Also add in badges
Add properties to writer to denote the format to use to create api calls inside a structured string, which correspond to the expression that the writer is created with.
Errors should not be absorbed and hidden as they are with the catch, even though the error is actually written out, but does not appear in the console.
Sometimes at the end of a batch run in Loopz.Rename-Many, un-solicited info is displayed on screen. It is thought that it could be because of un-consumed returned values from a writer method.
See https://powershellstation.com/2015/12/09/code-smell-invoke-expression/
branch: kill-invoke-expr
Add a tip somewhere, tht custom themes maybe added to themes and it would be a god idea to add this to the powershell profile to make it persitent.
Why this error didnt make itself apparent before is a mystery. There is no way it should have got into ths state whilst tests have been running previously.
[+] C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Get-EnvironmentVariable.tests.ps1 535ms (75ms|339ms)
[-] Describe Get-KrayolaTheme failed
FileNotFoundException: The specified module '.\Elizium.Krayola\Elizium.Krayola.psm1' was not loaded because no valid module file was found in any module directory.
at <ScriptBlock>, C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Get-KrayolaTheme.tests.ps1:6
[-] Describe Split-KeyValuePairFormatter failed
FileNotFoundException: The specified module '.\Elizium.Krayola\Elizium.Krayola.psm1' was not loaded because no valid module file was found in any module directory.
at <ScriptBlock>, C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Split-KeyValuePairFormatter.tests.ps1:5
[-] Describe Write-ThemedPairsInColour failed
FileNotFoundException: The specified module '.\Elizium.Krayola\Elizium.Krayola.psm1' was not loaded because no valid module file was found in any module directory.
at <ScriptBlock>, C:\Users\Plastikfan\dev\github\PoSh\Krayola\Elizium.Krayola\Tests\Write-ThemedPairsInColour.tests.ps1:5
Tests completed in 1.3s
Tests Passed: 1, Failed: 20, Skipped: 0 NotRun: 0
BeforeAll \ AfterAll failed: 3
- Get-KrayolaTheme
- Split-KeyValuePairFormatter
- Write-ThemedPairsInColour
Done /./Tests/Pester 00:00:01.8213733
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.