Closed futuremotiondev closed 10 months ago
this is pretty fun, but i think it should be activated by a -Markup switch perhaps?
my PR #15 adds support for ANSI escape code parsing ($PSStyle etc..), which is the way to color objects in formatfiles etc.
I have made alot of changes to the Format-SpectreTable, so if that PR is accepted we would need to re-do this a bit.
i can add it if you want.
@trackd I still have yet to go over your changes in detail to Format-SpectreTable, but yes - it would be great if you could include this change in your PR. I don't know if a -markup
switch would make much sense though, as markup is used everywhere else in the module without having to activate a switch. I think adding markup should always result in that markup being respected and rendered.
When you strip out the ANSI codes and convert to Spectre colors, would it instead be possible to strip the ANSI color codes and convert to a markup string? I.E:
"`e[38;5;12mTesting Blue`e[0m Testing Reset `e[38;5;9mTesting Red"
Becomes:
"[blue]Testing Blue[/] Testing Reset [red]Testing Red[/]"
Shouldn't this work both with your aim of converting the FormatData
and also support multiple colors in the same cell? It would eliminate the need to add a -markup
switch and still accomplish what you want while also preserving the ability to use markup everywhere else.
https://spectreconsole.net/api/spectre.console/markup/
Any thoughts?
@trackd I still have yet to go over your changes in detail to Format-SpectreTable, but yes - it would be great if you could include this change in your PR. I don't know if a
-markup
switch would make much sense though, as markup is used everywhere else in the module without having to activate a switch. I think adding markup should always result in that markup being respected and rendered.I don't think that's used almost anywhere in the module?
Get-ChildItem -Recurse -Filter *.ps1 | Select-String -Pattern 'markdown|markup]|\[\w+\son.*]' | Select FileName, Line | Format-SpectreTable -Border Markdown
| Filename | Line | | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | Get-SpectreDemoColors.ps1 | Write-SpectreHost " PS> [Yellow]Write-SpectreHost[/] [DeepSkyBlue1]`"$('I am [Red]colored text[/] using [Yellow1 on | | | Turquoise4]Spectre markdown[/]!' | Get-SpectreEscapedText)`"[/]" | | Get-SpectreDemoColors.ps1 | Write-SpectreHost " [white on grey19]I am [Red]colored text[/] using [Yellow1 on Turquoise4]Spectre markdown[/]! | | | [/]" | | Get-SpectreDemoColors.ps1 | Write-SpectreHost "`nFor more markdown hints see [link]https://spectreconsole.net/markup[/]`n" | | Get-SpectreDemoEmoji.ps1 | Write-SpectreHost -NoNewline "[DeepSkyBlue1]grinning_face: Spectre markdown emoji string :[/]" | | Get-SpectreDemoEmoji.ps1 | Write-SpectreHost " [white on grey19]I am a :grinning_face: Spectre markdown emoji string :victory_hand: ! | | | [/]" | | Get-SpectreDemoEmoji.ps1 | Write-SpectreHost "`nEmoji support is dependent on OS, terminal & font support. For more markdown hints see | | | [link]https://spectreconsole.net/markup[/] and for more emoji help see [link]https://spectreconsole.net/appendix/emojis[/]`n" | | Get-SpectreEscapedText.ps1 | See [https://spectreconsole.net/markup](https://spectreconsole.net/markup) for more information about the markup language used in | | | Spectre Console. | | Get-SpectreEscapedText.ps1 | return [Spectre.Console.Markup]::Escape($Text) | | Write-SpectreHost.ps1 | The markup language is defined at [https://spectreconsole.net/markup](https://spectreconsole.net/markup) |
Mostly demo that uses it
When you strip out the ANSI codes and convert to Spectre colors, would it instead be possible to strip the ANSI color codes and convert to a markup string? I.E:
"`e[38;5;12mTesting Blue`e[0m Testing Reset `e[38;5;9mTesting Red"
Becomes:
"[blue]Testing Blue[/] Testing Reset [red]Testing Red[/]"
Yea, this should be possible. I didn't know that the markdown option supported RGB etc, but i honestly didn't look too closely at it.
Shouldn't this work both with your aim of converting the
FormatData
and also support multiple colors in the same cell? It would eliminate the need to add a-markup
switch and still accomplish what you want while also preserving the ability to use markup everywhere else.https://spectreconsole.net/api/spectre.console/markup/
Any thoughts?
The -Markup
(or -Markdown
) switch was more to tell Format-SpectreTable
that strings contain markdown and should be handled (input), but i guess we could just detect that with a regex.
markdown for output could also be used..
One thing that didnt really find a good solution for yet is detecting where in the string to place different colors..
e[38;5;12m
etc should be counted as '1' in terms of string length in order to place the color in the correct spot.
It's going to be a bit of work but i could look into it.
But I would like some feedback from @ShaunLawrie before doing any more work as I'm not even sure if he wants to add either of these PR's.
Awesome! I cherry-picked this into @trackd's branch and merged that to prerelease because it had the most change. Format-SpectreTable has to assume no markup by default otherwise a lot of random stuff piped into it as a psobject can cause rendering issues. Opting-in with -AllowMarkup
seems like a reasonable approach 🤷
You should be able to try it with:
Install-Module PwshSpectreConsole -Scope CurrentUser -AllowPrerelease
If ya'll are happy I'll merge it to main. If you need to tweak anything @trackd open a new PR against prerelease. I just updated the default branch of the repo to that so it should do it automatically from now.
The prerelease docs are at https://2232f36c.pwshspectreconsole.pages.dev/reference/formatting/format-spectretable/
Currently color markup isn't parsed.
The above doesn't work currently. The table text isn't treated as markup, so any custom color tags won't work. This is how the above renders now:
This commit fixes that problem. This is how the same code renders with my change:
I've also added
using namespace Spectre.Console
at the top of the file to simplify object definitions in the body of the code.Let me know if this change works for you.