Skip to content

Commit

Permalink
Try make not break docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie authored Mar 15, 2024
1 parent 7e4f4ae commit 6bd8db2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion PwshSpectreConsole.Docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "astro build",
"preview": "astro preview",
"astro": "astro",
"update-docs": "pwsh -File ./src/powershell/UpdateDocs.ps1"
"update-docs": "pwsh -NoProfile -File ./src/powershell/UpdateDocs.ps1"
},
"dependencies": {
"@astrojs/starlight": "^0.11.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ title: Get Started
---

import { TerminalPlayer } from 'astro-terminal-player';
import readspectreselectionExample1 from '../../../assets/examples/readspectreselectionExample1.cast?url';
import readspectremultiselectionExample1 from '../../../assets/examples/readspectremultiselectionExample1.cast?url';

### Demo

Expand Down Expand Up @@ -36,7 +34,7 @@ Write-SpectreHost "Your chosen color is '$color'"
> Example of a user being prompted with a select list:
<TerminalPlayer
src={readspectreselectionExample1}
src="/examples/readspectreselectionExample1.cast"
settings={{
loop: false,
terminalLineHeight: 1.1,
Expand All @@ -61,7 +59,7 @@ Write-SpectreHost "Your favourite fruits are $($chosenItems -join ', ')"
> Example of a user being prompted with a multi-select list:
<TerminalPlayer
src={readspectremultiselectionExample1}
src="/examples/readspectremultiselectionExample1.cast"
settings={{
loop: false,
terminalLineHeight: 1.1,
Expand Down
5 changes: 3 additions & 2 deletions PwshSpectreConsole.Docs/src/powershell/UpdateDocs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ foreach ($doc in $docs) {
$specialChars = @("", "", "", "¦", "<space>")
$inputDelay = Get-Random -Minimum 500 -Maximum 1000
$typingDelay = Get-Random -Minimum 50 -Maximum 200
$recordingConsole = Start-SpectreRecording -RecordingType "asciinema" -Width 100 -Height 48 -Quiet
$recordingConsole = Start-SpectreRecording -RecordingType "asciinema" -Width 110 -Height 48

Write-Host "Generating sample for:"
Write-Host -ForegroundColor DarkGray $code
Expand Down Expand Up @@ -151,12 +151,13 @@ foreach ($doc in $docs) {

$castName = ($doc.Name -replace '.md$', '' -replace '-', '').ToLower() + "Example$example"
Set-Content -Path "$asciiCastOutputPath\$castName.cast" -Value $recording
$castUrl += "/examples/$castName.cast';`n"
$castUrl = "/examples/$castName.cast"

# Replace the code block with the ascii cast
$castTemplate = Get-AsciiCastTemplate -Name $castUrl
$content = $content -replace "(?ms)> EXAMPLE $example.+?(``````.+?``````)", "> EXAMPLE $example`n`n`$1`n$castTemplate"
}
$content = $content -replace "### Description", "$imports`n### Description"
} finally {
Pop-Location
[Spectre.Console.AnsiConsole]::Console = $originalConsole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ public class RecordingConsole : IAnsiConsole
{
private IAnsiConsole _ansiConsole;
private AsciiCastWriter _writer;
private bool _quiet;
public AsciiCastInput Input { get; }

public RecordingConsole(int width, int height, bool quiet)
public RecordingConsole(int width, int height)
{
var profileEnrichment = new ProfileEnrichment();
profileEnrichment.UseDefaultEnrichers = false;
Expand All @@ -168,7 +167,6 @@ public RecordingConsole(int width, int height, bool quiet)
console.Profile.Capabilities.Unicode = true;
console.Profile.Out = output;

_quiet = quiet;
_ansiConsole = console;
_writer = asciiCast;
Input = new AsciiCastInput();
Expand Down Expand Up @@ -205,10 +203,7 @@ public void Clear(bool homeValue)

public void Write(IRenderable renderable)
{
if(_quiet)
{
_ansiConsole.Write(renderable);
}
_ansiConsole.Write(renderable);
}
}
}
27 changes: 12 additions & 15 deletions PwshSpectreConsole/public/demo/Start-SpectreRecording.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Import-NamespaceFromCsFile -Namespace "PwshSpectreConsole.Recording"

$global:SpectreRecordingRecorder = $null
$global:SpectreRecordingOriginalConsole = $null
$global:SpectreRecordingType = $null
$script:SpectreRecordingRecorder = $null
$script:SpectreRecordingOriginalConsole = $null
$script:SpectreRecordingType = $null

function Start-SpectreRecording {
<#
Expand All @@ -22,8 +22,6 @@ function Start-SpectreRecording {
The type of recording to create.
.PARAMETER CountdownAndClear
If this switch is present, the console will be cleared and a countdown will be displayed before the recording starts.
.PARAMETER Quiet
If this switch is present all terminal output from spectre console will be suppressed, it will not be visible on the terminal.
.EXAMPLE
$recording = Start-SpectreRecording -RecordingType "Html" -CountdownAndClear
# Use spectre console functions, these will be recorded
Expand All @@ -40,12 +38,11 @@ function Start-SpectreRecording {
[int] $Height = (Get-HostHeight),
[ValidateSet("asciinema", "text", "html")]
[string] $RecordingType = "asciinema",
[switch] $CountdownAndClear,
[switch] $Quiet
[switch] $CountdownAndClear
)

if($global:SpectreRecordingType) {
throw "A $global:SpectreRecordingType recording has already started"
if($script:SpectreRecordingType) {
throw "A $script:SpectreRecordingType recording has already started"
}

if($CountdownAndClear) {
Expand All @@ -61,19 +58,19 @@ function Start-SpectreRecording {
}
}

$global:SpectreRecordingOriginalConsole = [Spectre.Console.AnsiConsole]::Console
$script:SpectreRecordingOriginalConsole = [Spectre.Console.AnsiConsole]::Console

if($RecordingType -eq "asciinema") {
# Create a recording console for asciinema, it's a bit fiddlier and requires an iansiconsole that can record durations between frames
$global:SpectreRecordingRecorder = [PwshSpectreConsole.Recording.RecordingConsole]::new($width, $height, $quiet)
$script:SpectreRecordingRecorder = [PwshSpectreConsole.Recording.RecordingConsole]::new($width, $height)
} else {
# Use the built in recorder
$global:SpectreRecordingRecorder = [Spectre.Console.Recorder]::new($global:SpectreRecordingOriginalConsole)
$script:SpectreRecordingRecorder = [Spectre.Console.Recorder]::new($script:SpectreRecordingOriginalConsole)
}

# Override current spectre console instance
$global:SpectreRecordingType = $RecordingType
[Spectre.Console.AnsiConsole]::Console = $global:SpectreRecordingRecorder
$script:SpectreRecordingType = $RecordingType
[Spectre.Console.AnsiConsole]::Console = $script:SpectreRecordingRecorder

return $global:SpectreRecordingRecorder
return $script:SpectreRecordingRecorder
}
18 changes: 9 additions & 9 deletions PwshSpectreConsole/public/demo/Stop-SpectreRecording.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Stop-SpectreRecording {
[string] $OutputPath
)

if(!$global:SpectreRecordingType) {
if(!$script:SpectreRecordingType) {
Write-Warning "No recording in progress"
return
}
Expand All @@ -39,23 +39,23 @@ function Stop-SpectreRecording {
}

# Get the recording
switch ($global:SpectreRecordingType) {
switch ($script:SpectreRecordingType) {
"asciinema" {
$recording = $global:SpectreRecordingRecorder.GetAsciiCastRecording($Title)
$recording = $script:SpectreRecordingRecorder.GetAsciiCastRecording($Title)
}
"text" {
$recording = [Spectre.Console.RecorderExtensions]::ExportText($global:SpectreRecordingRecorder)
$recording = [Spectre.Console.RecorderExtensions]::ExportText($script:SpectreRecordingRecorder)
}
"html" {
$recording = [Spectre.Console.RecorderExtensions]::ExportHtml($global:SpectreRecordingRecorder)
$recording = [Spectre.Console.RecorderExtensions]::ExportHtml($script:SpectreRecordingRecorder)
}
}

# Reset the console
[Spectre.Console.AnsiConsole]::Console = $global:SpectreRecordingOriginalConsole
$global:SpectreRecordingRecorder = $null
$global:SpectreRecordingOriginalConsole = $null
$global:SpectreRecordingType = $null
[Spectre.Console.AnsiConsole]::Console = $script:SpectreRecordingOriginalConsole
$script:SpectreRecordingRecorder = $null
$script:SpectreRecordingOriginalConsole = $null
$script:SpectreRecordingType = $null

# Return the output
if ($OutputPath) {
Expand Down

0 comments on commit 6bd8db2

Please sign in to comment.